Skip to content

Commit 65f84b1

Browse files
CORS-3566: Azure CAPI: disable natgw by setting node subnet id (openshift#8727)
* Azure CAPI: disable natgw by setting node subnet id Setting the ID on the Subnet disables natgw creation. See: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/21479a9a4c640b43e0bef028487c522c55605d06/api/v1beta1/azurecluster_default.go#L160 Because the node subnet does not already exist, we are using an arbitrary value. We could populate this with the proper subnet ID in the case of BYO VNET, but the value currently has no practical effect. * Set subnet ID to UNKNOWN. Sets the subnet ID to a clearly unknown value to avoid confusion.
1 parent 3ca43c1 commit 65f84b1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/asset/manifests/azure/cluster.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
7777
},
7878
},
7979
}
80+
81+
// Setting ID on the Subnet disables natgw creation. See:
82+
// https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/21479a9a4c640b43e0bef028487c522c55605d06/api/v1beta1/azurecluster_default.go#L160
83+
// CAPZ enables NAT Gateways by default, so we are using this hack to disable
84+
// nat gateways when we prefer to use load balancers for node egress.
85+
nodeSubnetID := ""
86+
if installConfig.Config.Platform.Azure.OutboundType != azure.NatGatewayOutboundType {
87+
// Because the node subnet does not already exist, we are using an arbitrary value.
88+
// We could populate this with the proper subnet ID in the case of BYO VNET, but
89+
// the value currently has no practical effect.
90+
nodeSubnetID = "UNKNOWN"
91+
}
92+
8093
azureCluster := &capz.AzureCluster{
8194
ObjectMeta: metav1.ObjectMeta{
8295
Name: clusterID.InfraID,
@@ -136,6 +149,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
136149
SecurityGroup: securityGroup,
137150
},
138151
{
152+
ID: nodeSubnetID,
139153
SubnetClassSpec: capz.SubnetClassSpec{
140154
Name: computeSubnet,
141155
Role: capz.SubnetNode,

0 commit comments

Comments
 (0)