Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting CSI AWS topology label on machine deployment creation to allow scale-up #365

Merged
merged 7 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
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"
himanshu-kun marked this conversation as resolved.
Show resolved Hide resolved
"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"
Expand Down Expand Up @@ -95,6 +96,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))

Expand Down Expand Up @@ -168,19 +174,27 @@ 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),
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),
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,
Taints: pool.Taints,
MachineConfiguration: genericworkeractuator.ReadMachineConfiguration(pool),
Expand Down
94 changes: 89 additions & 5 deletions pkg/controller/worker/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down