Skip to content
Merged
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
25 changes: 20 additions & 5 deletions api/v1beta1/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,41 +94,56 @@ func (c *AzureCluster) setVnetDefaults() {
c.Spec.NetworkSpec.Vnet.VnetClassSpec.setDefaults()
}

// setSubnetDefaults ensures a fully populated, default subnet configuration
// and in certain scenarios creates new, default subnet configurations.
func (c *AzureCluster) setSubnetDefaults() {
clusterSubnet, err := c.Spec.NetworkSpec.GetSubnet(SubnetCluster)
clusterSubnetExists := err == nil
// If we already have a cluster subnet defined, ensure it has sensible defaults
// for all properties.
if clusterSubnetExists {
clusterSubnet.setClusterSubnetDefaults(c.ObjectMeta.Name)
c.Spec.NetworkSpec.UpdateSubnet(clusterSubnet, SubnetCluster)
}

if c.Spec.ControlPlaneEnabled {
/* if there is a cp subnet set defaults
if no cp subnet and cluster subnet create a default cp subnet */
cpSubnet, errcp := c.Spec.NetworkSpec.GetSubnet(SubnetControlPlane)
// If we already have a control plane subnet defined, ensure it has sensible defaults
// for all properties.
if errcp == nil {
cpSubnet.setControlPlaneSubnetDefaults(c.ObjectMeta.Name)
c.Spec.NetworkSpec.UpdateSubnet(cpSubnet, SubnetControlPlane)
// If we don't have either a control plane subnet or a cluster subnet,
// create a new control plane subnet from scratch and populate with sensible defaults.
} else if !clusterSubnetExists {
cpSubnet = SubnetSpec{SubnetClassSpec: SubnetClassSpec{Role: SubnetControlPlane}}
cpSubnet.setControlPlaneSubnetDefaults(c.ObjectMeta.Name)
c.Spec.NetworkSpec.Subnets = append(c.Spec.NetworkSpec.Subnets, cpSubnet)
}
}

var nodeSubnetFound bool
// anyNodeSubnetFound tracks whether or not we have one or more node subnets defined.
var anyNodeSubnetFound bool
// nodeSubnetCounter tracks all node subnets to aid automatic CIDR configuration.
var nodeSubnetCounter int
for i, subnet := range c.Spec.NetworkSpec.Subnets {
// Skip all non-node subnets
if subnet.Role != SubnetNode {
continue
}
nodeSubnetCounter++
nodeSubnetFound = true
anyNodeSubnetFound = true
// Set has sensible defaults for this existing node subnet.
subnet.setNodeSubnetDefaults(c.ObjectMeta.Name, nodeSubnetCounter)
// Because there can be multiple node subnets, we have to update any changes
// after applying defaults to the explicit item at the current index.
c.Spec.NetworkSpec.Subnets[i] = subnet
}

if !nodeSubnetFound && !clusterSubnetExists {
// We need at least one subnet for nodes.
// If no node subnets are defined, and there is no cluster subnet defined,
// create a default 10.1.0.0/16 node subnet.
if !anyNodeSubnetFound && !clusterSubnetExists {
nodeSubnet := SubnetSpec{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetNode,
Expand Down
Loading