From c344d8c5f51d15e6e794f418de3aca7a4e8babc8 Mon Sep 17 00:00:00 2001 From: himanshu-kun Date: Mon, 21 Jun 2021 23:00:34 +0530 Subject: [PATCH 1/7] added csi driver label if not present and tests Co-authored-by: Prashanth Co-authored-by: Prashanth Co-authored-by: Prashanth --- pkg/controller/worker/helper.go | 22 ++++++++++++++++++++++ pkg/controller/worker/machines.go | 18 ++++++++++-------- pkg/controller/worker/machines_test.go | 25 ++++++++++++++++++++----- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/pkg/controller/worker/helper.go b/pkg/controller/worker/helper.go index f603f63fe..4d1ffa29c 100644 --- a/pkg/controller/worker/helper.go +++ b/pkg/controller/worker/helper.go @@ -28,6 +28,10 @@ import ( "k8s.io/client-go/util/retry" ) +const ( + AwsCsiDriverTopologyKey = "topology.ebs.csi.aws.com/zone" +) + func (w *workerDelegate) decodeWorkerProviderStatus() (*api.WorkerStatus, error) { workerStatus := &api.WorkerStatus{} @@ -59,3 +63,21 @@ func (w *workerDelegate) updateWorkerProviderStatus(ctx context.Context, workerS return nil }) } + +func makeCopyOfMap(mp map[string]string) map[string]string { + var mpDeepCopy = make(map[string]string) + for k, v := range mp { + mpDeepCopy[k] = v + } + return mpDeepCopy +} + +func addAwsCsiDriverTopologyLabel(poolLabels map[string]string, zone string) map[string]string { + if _, exists := poolLabels[AwsCsiDriverTopologyKey]; !exists { + var poolLabelsDeepCopy = makeCopyOfMap(poolLabels) + poolLabelsDeepCopy[AwsCsiDriverTopologyKey] = zone + return poolLabelsDeepCopy + } + + return poolLabels +} diff --git a/pkg/controller/worker/machines.go b/pkg/controller/worker/machines.go index 091381610..b18360fa9 100644 --- a/pkg/controller/worker/machines.go +++ b/pkg/controller/worker/machines.go @@ -173,14 +173,16 @@ func (w *workerDelegate) generateMachineConfig() error { ) machineDeployments = append(machineDeployments, worker.MachineDeployment{ - Name: deploymentName, - ClassName: className, - SecretName: className, - Minimum: worker.DistributeOverZones(zoneIdx, pool.Minimum, zoneLen), - Maximum: worker.DistributeOverZones(zoneIdx, pool.Maximum, zoneLen), - MaxSurge: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxSurge, zoneLen, pool.Maximum), - MaxUnavailable: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxUnavailable, zoneLen, pool.Minimum), - Labels: pool.Labels, + Name: deploymentName, + ClassName: className, + SecretName: className, + Minimum: worker.DistributeOverZones(zoneIdx, pool.Minimum, zoneLen), + Maximum: worker.DistributeOverZones(zoneIdx, pool.Maximum, zoneLen), + MaxSurge: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxSurge, zoneLen, pool.Maximum), + MaxUnavailable: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxUnavailable, zoneLen, pool.Minimum), + // TODO: remove when AWS CSI driver stops using the aws csi topology key - https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/899 + // add aws csi driver topology label if its not specified + Labels: addAwsCsiDriverTopologyLabel(pool.Labels, zone), Annotations: pool.Annotations, Taints: pool.Taints, MachineConfiguration: genericworkeractuator.ReadMachineConfiguration(pool), diff --git a/pkg/controller/worker/machines_test.go b/pkg/controller/worker/machines_test.go index 89a64a456..e76a03905 100644 --- a/pkg/controller/worker/machines_test.go +++ b/pkg/controller/worker/machines_test.go @@ -141,7 +141,9 @@ var _ = Describe("Machines", func() { zone1 string zone2 string - labels map[string]string + labels map[string]string + labelsWithAwsCsiDriverTopologyLabel1 map[string]string + labelsWithAwsCsiDriverTopologyLabel2 map[string]string machineConfiguration *machinev1alpha1.MachineConfiguration @@ -209,6 +211,8 @@ var _ = Describe("Machines", func() { zone2 = region + "b" labels = map[string]string{"component": "TiDB"} + labelsWithAwsCsiDriverTopologyLabel1 = makeCopyOfMap(labels) + labelsWithAwsCsiDriverTopologyLabel2 = makeCopyOfMap(labels) machineConfiguration = &machinev1alpha1.MachineConfiguration{} @@ -533,6 +537,9 @@ var _ = Describe("Machines", func() { machineClassPool2Zone2, }} + labelsWithAwsCsiDriverTopologyLabel1[AwsCsiDriverTopologyKey] = zone1 + labelsWithAwsCsiDriverTopologyLabel2[AwsCsiDriverTopologyKey] = zone2 + machineDeployments = worker.MachineDeployments{ { Name: machineClassNamePool1Zone1, @@ -542,7 +549,7 @@ var _ = Describe("Machines", func() { Maximum: worker.DistributeOverZones(0, maxPool1, 2), MaxSurge: worker.DistributePositiveIntOrPercent(0, maxSurgePool1, 2, maxPool1), MaxUnavailable: worker.DistributePositiveIntOrPercent(0, maxUnavailablePool1, 2, minPool1), - Labels: labels, + Labels: labelsWithAwsCsiDriverTopologyLabel1, MachineConfiguration: machineConfiguration, }, { @@ -553,7 +560,7 @@ var _ = Describe("Machines", func() { Maximum: worker.DistributeOverZones(1, maxPool1, 2), MaxSurge: worker.DistributePositiveIntOrPercent(1, maxSurgePool1, 2, maxPool1), MaxUnavailable: worker.DistributePositiveIntOrPercent(1, maxUnavailablePool1, 2, minPool1), - Labels: labels, + Labels: labelsWithAwsCsiDriverTopologyLabel2, MachineConfiguration: machineConfiguration, }, { @@ -564,7 +571,7 @@ var _ = Describe("Machines", func() { Maximum: worker.DistributeOverZones(0, maxPool2, 2), MaxSurge: worker.DistributePositiveIntOrPercent(0, maxSurgePool2, 2, maxPool2), MaxUnavailable: worker.DistributePositiveIntOrPercent(0, maxUnavailablePool2, 2, minPool2), - Labels: labels, + Labels: labelsWithAwsCsiDriverTopologyLabel1, MachineConfiguration: machineConfiguration, }, { @@ -575,7 +582,7 @@ var _ = Describe("Machines", func() { Maximum: worker.DistributeOverZones(1, maxPool2, 2), MaxSurge: worker.DistributePositiveIntOrPercent(1, maxSurgePool2, 2, maxPool2), MaxUnavailable: worker.DistributePositiveIntOrPercent(1, maxUnavailablePool2, 2, minPool2), - Labels: labels, + Labels: labelsWithAwsCsiDriverTopologyLabel2, MachineConfiguration: machineConfiguration, }, } @@ -911,3 +918,11 @@ func addNameAndSecretToMachineClass(class map[string]interface{}, name string, c } class["secret"].(map[string]interface{})["labels"] = map[string]string{v1beta1constants.GardenerPurpose: genericworkeractuator.GardenPurposeMachineClass} } + +func makeCopyOfMap(mp map[string]string) map[string]string { + var mpDeepCopy = make(map[string]string) + for k, v := range mp { + mpDeepCopy[k] = v + } + return mpDeepCopy +} From 44de08948f17fa5804a04b8b5ea64fc2f7bcd98c Mon Sep 17 00:00:00 2001 From: Himanshu Sharma <79965161+himanshu-kun@users.noreply.github.com> Date: Wed, 23 Jun 2021 19:51:03 +0530 Subject: [PATCH 2/7] Update pkg/controller/worker/helper.go not exporting csi driver key constant Co-authored-by: Vladimir Nachev --- pkg/controller/worker/helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/worker/helper.go b/pkg/controller/worker/helper.go index 4d1ffa29c..f11910a0e 100644 --- a/pkg/controller/worker/helper.go +++ b/pkg/controller/worker/helper.go @@ -29,7 +29,7 @@ import ( ) const ( - AwsCsiDriverTopologyKey = "topology.ebs.csi.aws.com/zone" + awsCSIDriverTopologyKey = "topology.ebs.csi.aws.com/zone" ) func (w *workerDelegate) decodeWorkerProviderStatus() (*api.WorkerStatus, error) { From ab15506d4073285e5f70e18962723668617b429f Mon Sep 17 00:00:00 2001 From: himanshu-kun Date: Thu, 24 Jun 2021 00:29:25 +0530 Subject: [PATCH 3/7] checking if CSI enabled before adding csi label removed unit tests, updated constant name to `awsCSIDriverTopologyKey` --- pkg/controller/worker/helper.go | 22 ---------------- pkg/controller/worker/machines.go | 36 ++++++++++++++++---------- pkg/controller/worker/machines_test.go | 25 ++++-------------- 3 files changed, 27 insertions(+), 56 deletions(-) diff --git a/pkg/controller/worker/helper.go b/pkg/controller/worker/helper.go index f11910a0e..f603f63fe 100644 --- a/pkg/controller/worker/helper.go +++ b/pkg/controller/worker/helper.go @@ -28,10 +28,6 @@ import ( "k8s.io/client-go/util/retry" ) -const ( - awsCSIDriverTopologyKey = "topology.ebs.csi.aws.com/zone" -) - func (w *workerDelegate) decodeWorkerProviderStatus() (*api.WorkerStatus, error) { workerStatus := &api.WorkerStatus{} @@ -63,21 +59,3 @@ func (w *workerDelegate) updateWorkerProviderStatus(ctx context.Context, workerS return nil }) } - -func makeCopyOfMap(mp map[string]string) map[string]string { - var mpDeepCopy = make(map[string]string) - for k, v := range mp { - mpDeepCopy[k] = v - } - return mpDeepCopy -} - -func addAwsCsiDriverTopologyLabel(poolLabels map[string]string, zone string) map[string]string { - if _, exists := poolLabels[AwsCsiDriverTopologyKey]; !exists { - var poolLabelsDeepCopy = makeCopyOfMap(poolLabels) - poolLabelsDeepCopy[AwsCsiDriverTopologyKey] = zone - return poolLabelsDeepCopy - } - - return poolLabels -} diff --git a/pkg/controller/worker/machines.go b/pkg/controller/worker/machines.go index b18360fa9..c51871271 100644 --- a/pkg/controller/worker/machines.go +++ b/pkg/controller/worker/machines.go @@ -24,7 +24,7 @@ import ( awsapi "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws" awsapihelper "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws/helper" "github.com/gardener/gardener-extension-provider-aws/pkg/aws" - + "github.com/gardener/gardener/extensions/pkg/controller/csimigration" "github.com/gardener/gardener/extensions/pkg/controller/worker" genericworkeractuator "github.com/gardener/gardener/extensions/pkg/controller/worker/genericactuator" v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants" @@ -95,6 +95,11 @@ func (w *workerDelegate) generateMachineConfig() error { return err } + csiEnabled, _, err := csimigration.CheckCSIConditions(w.cluster, aws.GetCSIMigrationKubernetesVersion(w.cluster)) + if err != nil { + return err + } + for _, pool := range w.worker.Spec.Pools { zoneLen := int32(len(pool.Zones)) @@ -168,26 +173,29 @@ func (w *workerDelegate) generateMachineConfig() error { } var ( - deploymentName = fmt.Sprintf("%s-%s-z%d", w.worker.Namespace, pool.Name, zoneIndex+1) - className = fmt.Sprintf("%s-%s", deploymentName, workerPoolHash) + deploymentName = fmt.Sprintf("%s-%s-z%d", w.worker.Namespace, pool.Name, zoneIndex+1) + className = fmt.Sprintf("%s-%s", deploymentName, workerPoolHash) + awsCSIDriverTopologyKey = "topology.ebs.csi.aws.com/zone" ) machineDeployments = append(machineDeployments, worker.MachineDeployment{ - Name: deploymentName, - ClassName: className, - SecretName: className, - Minimum: worker.DistributeOverZones(zoneIdx, pool.Minimum, zoneLen), - Maximum: worker.DistributeOverZones(zoneIdx, pool.Maximum, zoneLen), - MaxSurge: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxSurge, zoneLen, pool.Maximum), - MaxUnavailable: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxUnavailable, zoneLen, pool.Minimum), - // TODO: remove when AWS CSI driver stops using the aws csi topology key - https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/899 - // add aws csi driver topology label if its not specified - Labels: addAwsCsiDriverTopologyLabel(pool.Labels, zone), + Name: deploymentName, + ClassName: className, + SecretName: className, + Minimum: worker.DistributeOverZones(zoneIdx, pool.Minimum, zoneLen), + Maximum: worker.DistributeOverZones(zoneIdx, pool.Maximum, zoneLen), + MaxSurge: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxSurge, zoneLen, pool.Maximum), + MaxUnavailable: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxUnavailable, zoneLen, pool.Minimum), + Labels: pool.Labels, Annotations: pool.Annotations, Taints: pool.Taints, MachineConfiguration: genericworkeractuator.ReadMachineConfiguration(pool), }) - + // TODO: remove when AWS CSI driver stops using the aws csi topology key - https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/899 + // add aws csi driver topology label if its not specified + if csiEnabled { + machineDeployments[len(machineDeployments)-1].Labels = utils.MergeStringMaps(pool.Labels, map[string]string{awsCSIDriverTopologyKey: zone}) + } machineClassSpec["name"] = className machineClassSpec["labels"] = map[string]string{corev1.LabelZoneFailureDomain: zone} machineClassSpec["secret"].(map[string]interface{})["labels"] = map[string]string{v1beta1constants.GardenerPurpose: genericworkeractuator.GardenPurposeMachineClass} diff --git a/pkg/controller/worker/machines_test.go b/pkg/controller/worker/machines_test.go index e76a03905..89a64a456 100644 --- a/pkg/controller/worker/machines_test.go +++ b/pkg/controller/worker/machines_test.go @@ -141,9 +141,7 @@ var _ = Describe("Machines", func() { zone1 string zone2 string - labels map[string]string - labelsWithAwsCsiDriverTopologyLabel1 map[string]string - labelsWithAwsCsiDriverTopologyLabel2 map[string]string + labels map[string]string machineConfiguration *machinev1alpha1.MachineConfiguration @@ -211,8 +209,6 @@ var _ = Describe("Machines", func() { zone2 = region + "b" labels = map[string]string{"component": "TiDB"} - labelsWithAwsCsiDriverTopologyLabel1 = makeCopyOfMap(labels) - labelsWithAwsCsiDriverTopologyLabel2 = makeCopyOfMap(labels) machineConfiguration = &machinev1alpha1.MachineConfiguration{} @@ -537,9 +533,6 @@ var _ = Describe("Machines", func() { machineClassPool2Zone2, }} - labelsWithAwsCsiDriverTopologyLabel1[AwsCsiDriverTopologyKey] = zone1 - labelsWithAwsCsiDriverTopologyLabel2[AwsCsiDriverTopologyKey] = zone2 - machineDeployments = worker.MachineDeployments{ { Name: machineClassNamePool1Zone1, @@ -549,7 +542,7 @@ var _ = Describe("Machines", func() { Maximum: worker.DistributeOverZones(0, maxPool1, 2), MaxSurge: worker.DistributePositiveIntOrPercent(0, maxSurgePool1, 2, maxPool1), MaxUnavailable: worker.DistributePositiveIntOrPercent(0, maxUnavailablePool1, 2, minPool1), - Labels: labelsWithAwsCsiDriverTopologyLabel1, + Labels: labels, MachineConfiguration: machineConfiguration, }, { @@ -560,7 +553,7 @@ var _ = Describe("Machines", func() { Maximum: worker.DistributeOverZones(1, maxPool1, 2), MaxSurge: worker.DistributePositiveIntOrPercent(1, maxSurgePool1, 2, maxPool1), MaxUnavailable: worker.DistributePositiveIntOrPercent(1, maxUnavailablePool1, 2, minPool1), - Labels: labelsWithAwsCsiDriverTopologyLabel2, + Labels: labels, MachineConfiguration: machineConfiguration, }, { @@ -571,7 +564,7 @@ var _ = Describe("Machines", func() { Maximum: worker.DistributeOverZones(0, maxPool2, 2), MaxSurge: worker.DistributePositiveIntOrPercent(0, maxSurgePool2, 2, maxPool2), MaxUnavailable: worker.DistributePositiveIntOrPercent(0, maxUnavailablePool2, 2, minPool2), - Labels: labelsWithAwsCsiDriverTopologyLabel1, + Labels: labels, MachineConfiguration: machineConfiguration, }, { @@ -582,7 +575,7 @@ var _ = Describe("Machines", func() { Maximum: worker.DistributeOverZones(1, maxPool2, 2), MaxSurge: worker.DistributePositiveIntOrPercent(1, maxSurgePool2, 2, maxPool2), MaxUnavailable: worker.DistributePositiveIntOrPercent(1, maxUnavailablePool2, 2, minPool2), - Labels: labelsWithAwsCsiDriverTopologyLabel2, + Labels: labels, MachineConfiguration: machineConfiguration, }, } @@ -918,11 +911,3 @@ func addNameAndSecretToMachineClass(class map[string]interface{}, name string, c } class["secret"].(map[string]interface{})["labels"] = map[string]string{v1beta1constants.GardenerPurpose: genericworkeractuator.GardenPurposeMachineClass} } - -func makeCopyOfMap(mp map[string]string) map[string]string { - var mpDeepCopy = make(map[string]string) - for k, v := range mp { - mpDeepCopy[k] = v - } - return mpDeepCopy -} From df1b320d148e1aee3443dc39841bcae64e87d7a6 Mon Sep 17 00:00:00 2001 From: himanshu-kun Date: Thu, 24 Jun 2021 16:19:38 +0530 Subject: [PATCH 4/7] used lambda fn to add aws csi label --- pkg/controller/worker/machines.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/controller/worker/machines.go b/pkg/controller/worker/machines.go index c51871271..2681b668b 100644 --- a/pkg/controller/worker/machines.go +++ b/pkg/controller/worker/machines.go @@ -179,23 +179,26 @@ func (w *workerDelegate) generateMachineConfig() error { ) machineDeployments = append(machineDeployments, worker.MachineDeployment{ - Name: deploymentName, - ClassName: className, - SecretName: className, - Minimum: worker.DistributeOverZones(zoneIdx, pool.Minimum, zoneLen), - Maximum: worker.DistributeOverZones(zoneIdx, pool.Maximum, zoneLen), - MaxSurge: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxSurge, zoneLen, pool.Maximum), - MaxUnavailable: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxUnavailable, zoneLen, pool.Minimum), - Labels: pool.Labels, + Name: deploymentName, + ClassName: className, + SecretName: className, + Minimum: worker.DistributeOverZones(zoneIdx, pool.Minimum, zoneLen), + Maximum: worker.DistributeOverZones(zoneIdx, pool.Maximum, zoneLen), + MaxSurge: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxSurge, zoneLen, pool.Maximum), + MaxUnavailable: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxUnavailable, zoneLen, pool.Minimum), + // TODO: remove when AWS CSI driver stops using the aws csi topology key - https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/899 + // add aws csi driver topology label if its not specified + Labels: func() map[string]string { + if !csiEnabled { + return pool.Labels + } + return utils.MergeStringMaps(pool.Labels, map[string]string{awsCSIDriverTopologyKey: zone}) + }(), Annotations: pool.Annotations, Taints: pool.Taints, MachineConfiguration: genericworkeractuator.ReadMachineConfiguration(pool), }) - // TODO: remove when AWS CSI driver stops using the aws csi topology key - https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/899 - // add aws csi driver topology label if its not specified - if csiEnabled { - machineDeployments[len(machineDeployments)-1].Labels = utils.MergeStringMaps(pool.Labels, map[string]string{awsCSIDriverTopologyKey: zone}) - } + machineClassSpec["name"] = className machineClassSpec["labels"] = map[string]string{corev1.LabelZoneFailureDomain: zone} machineClassSpec["secret"].(map[string]interface{})["labels"] = map[string]string{v1beta1constants.GardenerPurpose: genericworkeractuator.GardenPurposeMachineClass} From 5231046c3538211b47b330c40d909455a7e0afc8 Mon Sep 17 00:00:00 2001 From: Himanshu Sharma <79965161+himanshu-kun@users.noreply.github.com> Date: Thu, 24 Jun 2021 19:17:42 +0530 Subject: [PATCH 5/7] Update pkg/controller/worker/machines.go moved comments Co-authored-by: Vladimir Nachev --- pkg/controller/worker/machines.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/controller/worker/machines.go b/pkg/controller/worker/machines.go index 2681b668b..26e64d2c9 100644 --- a/pkg/controller/worker/machines.go +++ b/pkg/controller/worker/machines.go @@ -186,12 +186,12 @@ func (w *workerDelegate) generateMachineConfig() error { Maximum: worker.DistributeOverZones(zoneIdx, pool.Maximum, zoneLen), MaxSurge: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxSurge, zoneLen, pool.Maximum), MaxUnavailable: worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxUnavailable, zoneLen, pool.Minimum), - // TODO: remove when AWS CSI driver stops using the aws csi topology key - https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/899 - // add aws csi driver topology label if its not specified Labels: func() map[string]string { if !csiEnabled { return pool.Labels } + // TODO: remove the csi topology label when AWS CSI driver stops using the aws csi topology key - https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/899 + // add aws csi driver topology label if its not specified return utils.MergeStringMaps(pool.Labels, map[string]string{awsCSIDriverTopologyKey: zone}) }(), Annotations: pool.Annotations, From 8d32318b57180101ee419e76c63379b461b9036b Mon Sep 17 00:00:00 2001 From: Himanshu Sharma <79965161+himanshu-kun@users.noreply.github.com> Date: Thu, 24 Jun 2021 19:19:32 +0530 Subject: [PATCH 6/7] Update pkg/controller/worker/machines.go Co-authored-by: Vladimir Nachev --- pkg/controller/worker/machines.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controller/worker/machines.go b/pkg/controller/worker/machines.go index 26e64d2c9..b3d240264 100644 --- a/pkg/controller/worker/machines.go +++ b/pkg/controller/worker/machines.go @@ -24,6 +24,7 @@ import ( awsapi "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws" awsapihelper "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws/helper" "github.com/gardener/gardener-extension-provider-aws/pkg/aws" + "github.com/gardener/gardener/extensions/pkg/controller/csimigration" "github.com/gardener/gardener/extensions/pkg/controller/worker" genericworkeractuator "github.com/gardener/gardener/extensions/pkg/controller/worker/genericactuator" From 9ae49f7f64763a1ad2bf1edfa02aaae622eab208 Mon Sep 17 00:00:00 2001 From: himanshu-kun Date: Mon, 28 Jun 2021 09:24:09 +0530 Subject: [PATCH 7/7] added test case --- pkg/controller/worker/machines_test.go | 94 ++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/pkg/controller/worker/machines_test.go b/pkg/controller/worker/machines_test.go index 89a64a456..4bc9aadf4 100644 --- a/pkg/controller/worker/machines_test.go +++ b/pkg/controller/worker/machines_test.go @@ -145,14 +145,17 @@ var _ = Describe("Machines", func() { machineConfiguration *machinev1alpha1.MachineConfiguration - workerPoolHash1 string - workerPoolHash2 string + workerPoolHash1 string + workerPoolHash2 string + workerPoolWithCSIlabelHash1 string + workerPoolWithCSIlabelHash2 string shootVersionMajorMinor string shootVersion string scheme *runtime.Scheme decoder runtime.Decoder clusterWithoutImages *extensionscontroller.Cluster + clusterk8s118 *extensionscontroller.Cluster cluster *extensionscontroller.Cluster w *extensionsv1alpha1.Worker ) @@ -262,6 +265,26 @@ var _ = Describe("Machines", func() { Shoot: clusterWithoutImages.Shoot, } + clusterk8s118 = &extensionscontroller.Cluster{ + CloudProfile: &gardencorev1beta1.CloudProfile{ + ObjectMeta: metav1.ObjectMeta{ + Name: cloudProfileName, + }, + Spec: gardencorev1beta1.CloudProfileSpec{ + ProviderConfig: &runtime.RawExtension{ + Raw: cloudProfileConfigJSON, + }, + }, + }, + Shoot: &gardencorev1beta1.Shoot{ + Spec: gardencorev1beta1.ShootSpec{ + Kubernetes: gardencorev1beta1.Kubernetes{ + Version: "1.18.0", + }, + }, + }, + } + w = &extensionsv1alpha1.Worker{ ObjectMeta: metav1.ObjectMeta{ Namespace: namespace, @@ -398,15 +421,18 @@ var _ = Describe("Machines", func() { workerPoolHash1, _ = worker.WorkerPoolHash(w.Spec.Pools[0], cluster, strconv.FormatBool(volumeEncrypted), fmt.Sprintf("%dGi", dataVolume1Size), dataVolume1Type, strconv.FormatBool(dataVolume1Encrypted), fmt.Sprintf("%dGi", dataVolume2Size), dataVolume2Type, strconv.FormatBool(dataVolume2Encrypted)) workerPoolHash2, _ = worker.WorkerPoolHash(w.Spec.Pools[1], cluster) + workerPoolWithCSIlabelHash1, _ = worker.WorkerPoolHash(w.Spec.Pools[0], clusterk8s118, strconv.FormatBool(volumeEncrypted), fmt.Sprintf("%dGi", dataVolume1Size), dataVolume1Type, strconv.FormatBool(dataVolume1Encrypted), fmt.Sprintf("%dGi", dataVolume2Size), dataVolume2Type, strconv.FormatBool(dataVolume2Encrypted)) + workerPoolWithCSIlabelHash2, _ = worker.WorkerPoolHash(w.Spec.Pools[1], clusterk8s118) workerDelegate, _ = NewWorkerDelegate(common.NewClientContext(c, scheme, decoder), chartApplier, "", w, clusterWithoutImages) }) Describe("machine images", func() { var ( - defaultMachineClass map[string]interface{} - machineDeployments worker.MachineDeployments - machineClasses map[string]interface{} + defaultMachineClass map[string]interface{} + machineDeployments worker.MachineDeployments + machineDeploymentsWithCSILabels worker.MachineDeployments + machineClasses map[string]interface{} ) BeforeEach(func() { @@ -519,6 +545,11 @@ var _ = Describe("Machines", func() { machineClassWithHashPool1Zone2 = fmt.Sprintf("%s-%s", machineClassNamePool1Zone2, workerPoolHash1) machineClassWithHashPool2Zone1 = fmt.Sprintf("%s-%s", machineClassNamePool2Zone1, workerPoolHash2) machineClassWithHashPool2Zone2 = fmt.Sprintf("%s-%s", machineClassNamePool2Zone2, workerPoolHash2) + + machineClassWithHashPool1Zone1CSI = fmt.Sprintf("%s-%s", machineClassNamePool1Zone1, workerPoolWithCSIlabelHash1) + machineClassWithHashPool1Zone2CSI = fmt.Sprintf("%s-%s", machineClassNamePool1Zone2, workerPoolWithCSIlabelHash1) + machineClassWithHashPool2Zone1CSI = fmt.Sprintf("%s-%s", machineClassNamePool2Zone1, workerPoolWithCSIlabelHash2) + machineClassWithHashPool2Zone2CSI = fmt.Sprintf("%s-%s", machineClassNamePool2Zone2, workerPoolWithCSIlabelHash2) ) addNameAndSecretToMachineClass(machineClassPool1Zone1, machineClassWithHashPool1Zone1, w.Spec.SecretRef) @@ -580,8 +611,61 @@ var _ = Describe("Machines", func() { }, } + machineDeploymentsWithCSILabels = worker.MachineDeployments{ + { + Name: machineClassNamePool1Zone1, + ClassName: machineClassWithHashPool1Zone1CSI, + SecretName: machineClassWithHashPool1Zone1CSI, + Minimum: worker.DistributeOverZones(0, minPool1, 2), + Maximum: worker.DistributeOverZones(0, maxPool1, 2), + MaxSurge: worker.DistributePositiveIntOrPercent(0, maxSurgePool1, 2, maxPool1), + MaxUnavailable: worker.DistributePositiveIntOrPercent(0, maxUnavailablePool1, 2, minPool1), + Labels: utils.MergeStringMaps(labels, map[string]string{"topology.ebs.csi.aws.com/zone": zone1}), + MachineConfiguration: machineConfiguration, + }, + { + Name: machineClassNamePool1Zone2, + ClassName: machineClassWithHashPool1Zone2CSI, + SecretName: machineClassWithHashPool1Zone2CSI, + Minimum: worker.DistributeOverZones(1, minPool1, 2), + Maximum: worker.DistributeOverZones(1, maxPool1, 2), + MaxSurge: worker.DistributePositiveIntOrPercent(1, maxSurgePool1, 2, maxPool1), + MaxUnavailable: worker.DistributePositiveIntOrPercent(1, maxUnavailablePool1, 2, minPool1), + Labels: utils.MergeStringMaps(labels, map[string]string{"topology.ebs.csi.aws.com/zone": zone2}), + MachineConfiguration: machineConfiguration, + }, + { + Name: machineClassNamePool2Zone1, + ClassName: machineClassWithHashPool2Zone1CSI, + SecretName: machineClassWithHashPool2Zone1CSI, + Minimum: worker.DistributeOverZones(0, minPool2, 2), + Maximum: worker.DistributeOverZones(0, maxPool2, 2), + MaxSurge: worker.DistributePositiveIntOrPercent(0, maxSurgePool2, 2, maxPool2), + MaxUnavailable: worker.DistributePositiveIntOrPercent(0, maxUnavailablePool2, 2, minPool2), + Labels: utils.MergeStringMaps(labels, map[string]string{"topology.ebs.csi.aws.com/zone": zone1}), + MachineConfiguration: machineConfiguration, + }, + { + Name: machineClassNamePool2Zone2, + ClassName: machineClassWithHashPool2Zone2CSI, + SecretName: machineClassWithHashPool2Zone2CSI, + Minimum: worker.DistributeOverZones(1, minPool2, 2), + Maximum: worker.DistributeOverZones(1, maxPool2, 2), + MaxSurge: worker.DistributePositiveIntOrPercent(1, maxSurgePool2, 2, maxPool2), + MaxUnavailable: worker.DistributePositiveIntOrPercent(1, maxUnavailablePool2, 2, minPool2), + Labels: utils.MergeStringMaps(labels, map[string]string{"topology.ebs.csi.aws.com/zone": zone2}), + MachineConfiguration: machineConfiguration, + }, + } }) + It("should return machine deployments with AWS CSI Label (k8s>=1.18)", func() { + workerDelegate, _ = NewWorkerDelegate(common.NewClientContext(c, scheme, decoder), chartApplier, "", w, clusterk8s118) + result, err := workerDelegate.GenerateMachineDeployments(ctx) + + Expect(err).NotTo(HaveOccurred()) + Expect(result).To(Equal(machineDeploymentsWithCSILabels)) + }) It("should return the expected machine deployments for profile image types", func() { workerDelegate, _ = NewWorkerDelegate(common.NewClientContext(c, scheme, decoder), chartApplier, "", w, cluster)