Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add usage of subnet and routetable shared resources in azure #10900

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ func (c *Cluster) AzureResourceGroupName() string {
return c.Name
}

// IsSharedAzureRouteTable returns true if the route table is shared.
func (c *Cluster) IsSharedAzureRouteTable() bool {
return c.Spec.CloudConfig.Azure.RouteTableName != ""
}

// EnvVar represents an environment variable present in a Container.
type EnvVar struct {
// Name of the environment variable. Must be a C_IDENTIFIER.
Expand Down
3 changes: 3 additions & 0 deletions pkg/model/azuremodel/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (b *NetworkModelBuilder) Build(c *fi.ModelBuilderContext) error {
ResourceGroup: b.LinkToResourceGroup(),
CIDR: fi.String(b.Cluster.Spec.NetworkCIDR),
Tags: map[string]*string{},
Shared: fi.Bool(b.Cluster.SharedVPC()),
}
c.AddTask(networkTask)

Expand All @@ -47,6 +48,7 @@ func (b *NetworkModelBuilder) Build(c *fi.ModelBuilderContext) error {
ResourceGroup: b.LinkToResourceGroup(),
VirtualNetwork: b.LinkToVirtualNetwork(),
CIDR: fi.String(subnetSpec.CIDR),
Shared: fi.Bool(b.Cluster.SharedVPC()),
}
c.AddTask(subnetTask)
}
Expand All @@ -56,6 +58,7 @@ func (b *NetworkModelBuilder) Build(c *fi.ModelBuilderContext) error {
Lifecycle: b.Lifecycle,
ResourceGroup: b.LinkToResourceGroup(),
Tags: map[string]*string{},
Shared: fi.Bool(b.Cluster.IsSharedAzureRouteTable()),
}
c.AddTask(rtTask)

Expand Down
3 changes: 3 additions & 0 deletions pkg/resources/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (g *resourceGetter) toVirtualNetworkResource(vnet *network.VirtualNetwork)
Name: *vnet.Name,
Deleter: g.deleteVirtualNetwork,
Blocks: []string{toKey(typeResourceGroup, g.resourceGroupName())},
Shared: g.cluster.SharedVPC(),
}
}

Expand Down Expand Up @@ -199,6 +200,7 @@ func (g *resourceGetter) toSubnetResource(subnet *network.Subnet, vnetName strin
toKey(typeVirtualNetwork, vnetName),
toKey(typeResourceGroup, g.resourceGroupName()),
},
Shared: g.cluster.SharedVPC(),
}
}

Expand Down Expand Up @@ -231,6 +233,7 @@ func (g *resourceGetter) toRouteTableResource(rt *network.RouteTable) *resources
Name: *rt.Name,
Deleter: g.deleteRouteTable,
Blocks: []string{toKey(typeResourceGroup, g.resourceGroupName())},
Shared: g.cluster.IsSharedAzureRouteTable(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions upup/pkg/fi/cloudup/azure/azure_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ func (c *azureCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([
})
}
}
if ingresses == nil {
return nil, fmt.Errorf("error getting API Ingress Status so make sure to update your kubecfg accordingly")
}
}

return ingresses, nil
Expand Down
1 change: 1 addition & 0 deletions upup/pkg/fi/cloudup/azuretasks/routetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type RouteTable struct {
Lifecycle *fi.Lifecycle
ResourceGroup *ResourceGroup
Tags map[string]*string
Shared *bool
}

var _ fi.Task = &RouteTable{}
Expand Down
1 change: 1 addition & 0 deletions upup/pkg/fi/cloudup/azuretasks/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Subnet struct {
ResourceGroup *ResourceGroup
VirtualNetwork *VirtualNetwork
CIDR *string
Shared *bool
}

var _ fi.Task = &Subnet{}
Expand Down
13 changes: 7 additions & 6 deletions upup/pkg/fi/cloudup/azuretasks/virtualnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type VirtualNetwork struct {
ResourceGroup *ResourceGroup
CIDR *string
Tags map[string]*string
Subnets *[]network.Subnet
Shared *bool
}

var _ fi.Task = &VirtualNetwork{}
Expand Down Expand Up @@ -75,8 +77,9 @@ func (n *VirtualNetwork) Find(c *fi.Context) (*VirtualNetwork, error) {
ResourceGroup: &ResourceGroup{
Name: n.ResourceGroup.Name,
},
CIDR: to.StringPtr(addrPrefixes[0]),
Tags: found.Tags,
CIDR: to.StringPtr(addrPrefixes[0]),
Tags: found.Tags,
Subnets: found.Subnets,
}, nil
}

Expand Down Expand Up @@ -115,10 +118,7 @@ func (*VirtualNetwork) RenderAzure(t *azure.AzureAPITarget, a, e, changes *Virtu
if changes.Tags == nil {
return nil
}
// TODO(kenji): Fix this. Update is not supported yet as updating the tag will recreate a virtual network,
// which causes an InUseSubnetCannotBeDeleted error.
klog.Infof("Skip updating a Virtual Network with name: %s", fi.StringValue(e.Name))
return nil
klog.Infof("Updating a Virtual Network with name: %s", fi.StringValue(e.Name))
}

vnet := network.VirtualNetwork{
Expand All @@ -127,6 +127,7 @@ func (*VirtualNetwork) RenderAzure(t *azure.AzureAPITarget, a, e, changes *Virtu
AddressSpace: &network.AddressSpace{
AddressPrefixes: &[]string{*e.CIDR},
},
Subnets: e.Subnets,
},
Tags: e.Tags,
}
Expand Down