From 5a467e2f9b03f40369868140b96278e2daf0f7d8 Mon Sep 17 00:00:00 2001 From: Aleksei Sizov <45825279+a13x5@users.noreply.github.com> Date: Mon, 23 Dec 2024 10:47:29 -0500 Subject: [PATCH] Fix azure.json generation: include node-subnet data (#804) --- 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 38157d37..53abb495 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) { + for _, sn := range azureCluster.Spec.NetworkSpec.Subnets { + if sn.Role == "node" { + subnetName = sn.Name + secGroup = sn.SecurityGroup.Name + routeTable = sn.RouteTable.Name + break + } + } + return subnetName, secGroup, routeTable +}