Skip to content

Commit

Permalink
added csi driver label if not present and tests
Browse files Browse the repository at this point in the history
Co-authored-by: Prashanth <[email protected]>

Co-authored-by: Prashanth <[email protected]>

Co-authored-by: Prashanth <[email protected]>
  • Loading branch information
himanshu-kun and prashanth26 committed Jun 23, 2021
1 parent c314018 commit 8eb133c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
22 changes: 22 additions & 0 deletions pkg/controller/worker/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -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
}
18 changes: 10 additions & 8 deletions pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
25 changes: 20 additions & 5 deletions pkg/controller/worker/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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{}

Expand Down Expand Up @@ -533,6 +537,9 @@ var _ = Describe("Machines", func() {
machineClassPool2Zone2,
}}

labelsWithAwsCsiDriverTopologyLabel1[AwsCsiDriverTopologyKey] = zone1
labelsWithAwsCsiDriverTopologyLabel2[AwsCsiDriverTopologyKey] = zone2

machineDeployments = worker.MachineDeployments{
{
Name: machineClassNamePool1Zone1,
Expand All @@ -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,
},
{
Expand All @@ -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,
},
{
Expand All @@ -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,
},
{
Expand All @@ -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,
},
}
Expand Down Expand Up @@ -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
}

0 comments on commit 8eb133c

Please sign in to comment.