From daf80ef1469876ab093c897200f52b30b6f0e26f Mon Sep 17 00:00:00 2001 From: Rafael Franzke Date: Tue, 28 Apr 2020 12:25:07 +0200 Subject: [PATCH] Fix wrongly set vnet resource group in machine class --- pkg/controller/worker/machines.go | 19 +++++++------ pkg/controller/worker/machines_test.go | 39 +++++++++++++++----------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/pkg/controller/worker/machines.go b/pkg/controller/worker/machines.go index c7c202ad4..2befd262b 100644 --- a/pkg/controller/worker/machines.go +++ b/pkg/controller/worker/machines.go @@ -175,10 +175,7 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error { Annotations: pool.Annotations, Taints: pool.Taints, } - networkConfig = map[string]interface{}{ - "vnet": infrastructureStatus.Networks.VNet.Name, - "subnet": nodesSubnet.Name, - } + machineClassSpec = map[string]interface{}{ "region": w.worker.Spec.Region, "resourceGroup": infrastructureStatus.ResourceGroup.Name, @@ -196,10 +193,14 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error { "sshPublicKey": string(w.worker.Spec.SSHPublicKey), } ) + + networkConfig := map[string]interface{}{ + "vnet": infrastructureStatus.Networks.VNet.Name, + "subnet": nodesSubnet.Name, + } if infrastructureStatus.Networks.VNet.ResourceGroup != nil { - machineClassSpec["vnetResourceGroup"] = *infrastructureStatus.Networks.VNet.ResourceGroup + networkConfig["vnetResourceGroup"] = *infrastructureStatus.Networks.VNet.ResourceGroup } - if imageSupportAcceleratedNetworking != nil && *imageSupportAcceleratedNetworking && w.isMachineTypeSupportingAcceleratedNetworking(pool.MachineType) { networkConfig["acceleratedNetworking"] = true } @@ -212,6 +213,7 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error { machineDeployment.MaxUnavailable = worker.DistributePositiveIntOrPercent(zone.index, pool.MaxUnavailable, zone.count, pool.Minimum) machineClassSpec["zone"] = zone.name } + if availabilitySetID != nil { machineClassSpec["availabilitySetID"] = *availabilitySetID } @@ -224,6 +226,7 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error { deploymentName = fmt.Sprintf("%s-%s", w.worker.Namespace, pool.Name) className = fmt.Sprintf("%s-%s", deploymentName, workerPoolHash) ) + if zone != nil { deploymentName = fmt.Sprintf("%s-z%s", deploymentName, zone.name) className = fmt.Sprintf("%s-z%s", className, zone.name) @@ -234,9 +237,7 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error { machineDeployment.SecretName = className machineClassSpec["name"] = className - machineClassSpec["labels"] = map[string]string{ - v1beta1constants.GardenerPurpose: genericworkeractuator.GardenPurposeMachineClass, - } + machineClassSpec["labels"] = map[string]string{v1beta1constants.GardenerPurpose: genericworkeractuator.GardenPurposeMachineClass} machineClassSpec["secret"].(map[string]interface{})[azure.ClientIDKey] = string(machineClassSecretData[machinev1alpha1.AzureClientID]) machineClassSpec["secret"].(map[string]interface{})[azure.ClientSecretKey] = string(machineClassSecretData[machinev1alpha1.AzureClientSecret]) machineClassSpec["secret"].(map[string]interface{})[azure.SubscriptionIDKey] = string(machineClassSecretData[machinev1alpha1.AzureSubscriptionID]) diff --git a/pkg/controller/worker/machines_test.go b/pkg/controller/worker/machines_test.go index 388c0b676..ea6700147 100644 --- a/pkg/controller/worker/machines_test.go +++ b/pkg/controller/worker/machines_test.go @@ -97,15 +97,16 @@ var _ = Describe("Machines", func() { machineImageURN string machineImageID string - resourceGroupName string - vnetName string - subnetName string - availabilitySetID string - identityID string - machineType string - userData []byte - volumeSize int - sshKey string + resourceGroupName string + vnetResourceGroupName string + vnetName string + subnetName string + availabilitySetID string + identityID string + machineType string + userData []byte + volumeSize int + sshKey string namePool1 string minPool1 int32 @@ -150,6 +151,7 @@ var _ = Describe("Machines", func() { machineImageID = "/shared/image/gallery/image/id" resourceGroupName = "my-rg" + vnetResourceGroupName = "my-vnet-rg" vnetName = "my-vnet" subnetName = "subnet-1234" availabilitySetID = "av-1234" @@ -189,15 +191,15 @@ var _ = Describe("Machines", func() { Kind: "CloudProfileConfig", }, MachineImages: []apiv1alpha1.MachineImages{ - apiv1alpha1.MachineImages{ + { Name: machineImageName, Versions: []apiv1alpha1.MachineImageVersion{ - apiv1alpha1.MachineImageVersion{ + { Version: machineImageVersion, URN: &machineImageURN, AcceleratedNetworking: &boolTrue, }, - apiv1alpha1.MachineImageVersion{ + { Version: machineImageVersionID, ID: &machineImageID, }, @@ -205,7 +207,7 @@ var _ = Describe("Machines", func() { }, }, MachineTypes: []apiv1alpha1.MachineType{ - apiv1alpha1.MachineType{ + { Name: machineType, AcceleratedNetworking: &boolTrue, }, @@ -246,7 +248,8 @@ var _ = Describe("Machines", func() { }, Networks: apisazure.NetworkStatus{ VNet: apisazure.VNetStatus{ - Name: vnetName, + Name: vnetName, + ResourceGroup: &vnetResourceGroupName, }, Subnets: []apisazure.Subnet{ { @@ -329,6 +332,7 @@ var _ = Describe("Machines", func() { "network": map[string]interface{}{ "vnet": vnetName, "subnet": subnetName, + "vnetResourceGroup": vnetResourceGroupName, "acceleratedNetworking": true, }, "availabilitySetID": availabilitySetID, @@ -354,8 +358,9 @@ var _ = Describe("Machines", func() { } defaultMachineClass["network"] = map[string]interface{}{ - "vnet": vnetName, - "subnet": subnetName, + "vnet": vnetName, + "subnet": subnetName, + "vnetResourceGroup": vnetResourceGroupName, } imageIdMachineClass = copyMachineClass(defaultMachineClass) imageIdMachineClass["image"] = map[string]interface{}{ @@ -410,7 +415,7 @@ var _ = Describe("Machines", func() { expectGetSecretCallToWork(c, azureClientID, azureClientSecret, azureSubscriptionID, azureTenantID) // Test workerDelegate.DeployMachineClasses() - chartApplier.EXPECT().Apply(context.TODO(), filepath.Join(azure.InternalChartsPath, "machineclass"), namespace, "machineclass", kubernetes.Values(machineClasses)).Return(nil) + chartApplier.EXPECT().Apply(context.TODO(), filepath.Join(azure.InternalChartsPath, "machineclass"), namespace, "machineclass", kubernetes.Values(machineClasses)) err := workerDelegate.DeployMachineClasses(context.TODO()) Expect(err).NotTo(HaveOccurred())