From b80203a8e893947f8485623a578247e12cd7ae75 Mon Sep 17 00:00:00 2001 From: Hardik Dodiya Date: Wed, 26 Aug 2020 12:25:20 +0530 Subject: [PATCH] Move the ca-annotation to the utils file --- pkg/apis/machine/v1alpha1/shared_types.go | 12 ------ pkg/controller/deployment_rolling.go | 47 +---------------------- pkg/controller/deployment_util.go | 8 ++++ 3 files changed, 10 insertions(+), 57 deletions(-) diff --git a/pkg/apis/machine/v1alpha1/shared_types.go b/pkg/apis/machine/v1alpha1/shared_types.go index 5b24873e9..d1d56f6ab 100644 --- a/pkg/apis/machine/v1alpha1/shared_types.go +++ b/pkg/apis/machine/v1alpha1/shared_types.go @@ -72,15 +72,3 @@ type MachineSummary struct { // OwnerRef OwnerRef string `json:"ownerRef,omitempty"` } - -const ( - // ClusterAutoscalerScaleDownDisabledAnnotationKey annotation to disable the scale-down of the nodes. - ClusterAutoscalerScaleDownDisabledAnnotationKey = "cluster-autoscaler.kubernetes.io/scale-down-disabled" - // ClusterAutoscalerScaleDownDisabledAnnotationValue annotation to disable the scale-down of the nodes. - ClusterAutoscalerScaleDownDisabledAnnotationValue = "True" - - // ClusterAutoscalerScaleDownDisabledAnnotationByMCMKey annotation to disable the scale-down of the nodes. - ClusterAutoscalerScaleDownDisabledAnnotationByMCMKey = "cluster-autoscaler.kubernetes.io/scale-down-disabled-by-mcm" - // ClusterAutoscalerScaleDownDisabledAnnotationByMCMValue annotation to disable the scale-down of the nodes. - ClusterAutoscalerScaleDownDisabledAnnotationByMCMValue = "True" -) diff --git a/pkg/controller/deployment_rolling.go b/pkg/controller/deployment_rolling.go index 5af377474..679de3307 100644 --- a/pkg/controller/deployment_rolling.go +++ b/pkg/controller/deployment_rolling.go @@ -46,10 +46,10 @@ var ( func (dc *controller) rolloutRolling(d *v1alpha1.MachineDeployment, isList []*v1alpha1.MachineSet, machineMap map[types.UID]*v1alpha1.MachineList) error { clusterAutoscalerScaleDownAnnotations := make(map[string]string) - clusterAutoscalerScaleDownAnnotations[v1alpha1.ClusterAutoscalerScaleDownDisabledAnnotationKey] = v1alpha1.ClusterAutoscalerScaleDownDisabledAnnotationValue + clusterAutoscalerScaleDownAnnotations[ClusterAutoscalerScaleDownDisabledAnnotationKey] = ClusterAutoscalerScaleDownDisabledAnnotationValue // We do this avoid accidentally deleting the user provided annotations. - clusterAutoscalerScaleDownAnnotations[v1alpha1.ClusterAutoscalerScaleDownDisabledAnnotationByMCMKey] = v1alpha1.ClusterAutoscalerScaleDownDisabledAnnotationByMCMValue + clusterAutoscalerScaleDownAnnotations[ClusterAutoscalerScaleDownDisabledAnnotationByMCMKey] = ClusterAutoscalerScaleDownDisabledAnnotationByMCMValue newIS, oldISs, err := dc.getAllMachineSetsAndSyncRevision(d, isList, machineMap, true) if err != nil { @@ -431,49 +431,6 @@ func (dc *controller) machineSetsScaledToZero(MachineSets []*v1alpha1.MachineSet return true } -// removeAnnotationFromNodesBackingMachineSets annotates all nodes backing the machineSets -func (dc *controller) removeAnnotationFromNodesBackingMachineSets(MachineSets []*v1alpha1.MachineSet, annotations map[string]string) error { - - for _, machineSet := range MachineSets { - - klog.V(3).Infof("Trying to de-annotate nodes under the MachineSet object %q with %s", machineSet.Name, annotations) - selector, err := metav1.LabelSelectorAsSelector(machineSet.Spec.Selector) - if err != nil { - return err - } - - // list all machines to include the machines that don't match the ms`s selector - // anymore but has the stale controller ref. - // TODO: Do the List and Filter in a single pass, or use an index. - filteredMachines, err := dc.machineLister.List(labels.Everything()) - if err != nil { - return err - } - // NOTE: filteredMachines are pointing to objects from cache - if you need to - // modify them, you need to copy it first. - filteredMachines, err = dc.claimMachines(machineSet, selector, filteredMachines) - if err != nil { - return err - } - - for _, machine := range filteredMachines { - if machine.Status.Node != "" { - err = RemoveAnnotationsOffNode( - dc.targetCoreClient, - machine.Status.Node, - annotations, - ) - if err != nil { - klog.Warningf("Removing annotation failed for node: %s, %s", machine.Status.Node, err) - } - } - } - klog.V(2).Infof("De-annotated the nodes backed by MachineSet %q with %s", machineSet.Name, annotations) - } - - return nil -} - // removeAutoscalerAnnotationsIfRequired removes the annotations if needed from nodes backing machinesets. func (dc *controller) removeAutoscalerAnnotationsIfRequired(MachineSets []*v1alpha1.MachineSet, annotations map[string]string) error { diff --git a/pkg/controller/deployment_util.go b/pkg/controller/deployment_util.go index bdc9f61ca..79e48f3a8 100644 --- a/pkg/controller/deployment_util.go +++ b/pkg/controller/deployment_util.go @@ -109,6 +109,14 @@ const ( // PreferNoScheduleKey is used to identify machineSet nodes on which PreferNoSchedule taint is added on // older machineSets during a rolling update PreferNoScheduleKey = "deployment.machine.sapcloud.io/prefer-no-schedule" + // ClusterAutoscalerScaleDownDisabledAnnotationKey annotation to disable the scale-down of the nodes. + ClusterAutoscalerScaleDownDisabledAnnotationKey = "cluster-autoscaler.kubernetes.io/scale-down-disabled" + // ClusterAutoscalerScaleDownDisabledAnnotationValue annotation to disable the scale-down of the nodes. + ClusterAutoscalerScaleDownDisabledAnnotationValue = "True" + // ClusterAutoscalerScaleDownDisabledAnnotationByMCMKey annotation to disable the scale-down of the nodes. + ClusterAutoscalerScaleDownDisabledAnnotationByMCMKey = "cluster-autoscaler.kubernetes.io/scale-down-disabled-by-mcm" + // ClusterAutoscalerScaleDownDisabledAnnotationByMCMValue annotation to disable the scale-down of the nodes. + ClusterAutoscalerScaleDownDisabledAnnotationByMCMValue = "True" // RollbackRevisionNotFound is not found rollback event reason RollbackRevisionNotFound = "DeploymentRollbackRevisionNotFound"