From e6b1c7981cf0f647bb5d9d1ea4f4b583f2940006 Mon Sep 17 00:00:00 2001 From: Aleksei Sizov Date: Tue, 17 Dec 2024 21:48:49 -0500 Subject: [PATCH] Fix azure.json generation: include node-subnet data --- internal/credspropagation/azure.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/credspropagation/azure.go b/internal/credspropagation/azure.go index 05eb6973..a5944246 100644 --- a/internal/credspropagation/azure.go +++ b/internal/credspropagation/azure.go @@ -63,6 +63,7 @@ func PropagateAzureSecrets(ctx context.Context, cfg *PropagationCfg) error { } func generateAzureCCMSecret(azureCluster *capz.AzureCluster, azureClIdty *capz.AzureClusterIdentity, azureSecret *corev1.Secret) (*corev1.Secret, error) { + subnetName, secGroup, routeTable := getAzureSubnetData(azureCluster) azureJSONMap := map[string]any{ "cloud": azureCluster.Spec.AzureEnvironment, "tenantId": azureClIdty.Spec.TenantID, @@ -70,13 +71,14 @@ func generateAzureCCMSecret(azureCluster *capz.AzureCluster, azureClIdty *capz.A "aadClientId": azureClIdty.Spec.ClientID, "aadClientSecret": string(azureSecret.Data["clientSecret"]), "resourceGroup": azureCluster.Spec.ResourceGroup, - "securityGroupName": azureCluster.Spec.NetworkSpec.Subnets[0].SecurityGroup.Name, + "securityGroupName": secGroup, "securityGroupResourceGroup": azureCluster.Spec.NetworkSpec.Vnet.ResourceGroup, "location": azureCluster.Spec.Location, "vmType": "vmss", "vnetName": azureCluster.Spec.NetworkSpec.Vnet.Name, "vnetResourceGroup": azureCluster.Spec.NetworkSpec.Vnet.ResourceGroup, - "subnetName": azureCluster.Spec.NetworkSpec.Subnets[0].Name, + "subnetName": subnetName, + "routeTableName": routeTable, "loadBalancerSku": "Standard", "loadBalancerName": "", "maximumLoadBalancerRuleCount": 250, @@ -94,3 +96,15 @@ func generateAzureCCMSecret(azureCluster *capz.AzureCluster, azureClIdty *capz.A return makeSecret("azure-cloud-provider", metav1.NamespaceSystem, secretData), nil } + +func getAzureSubnetData(azureCluster *capz.AzureCluster) (subnetName, secGroup, routeTable string) { + subnetName = azureCluster.Name + "-node-subnet" + for _, sn := range azureCluster.Spec.NetworkSpec.Subnets { + if sn.Name == subnetName { + secGroup = sn.SecurityGroup.Name + routeTable = sn.RouteTable.Name + break + } + } + return subnetName, secGroup, routeTable +}