Skip to content

Commit

Permalink
Move the ca-annotation to the utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikdr committed Aug 26, 2020
1 parent b99e8a8 commit b80203a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 57 deletions.
12 changes: 0 additions & 12 deletions pkg/apis/machine/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
47 changes: 2 additions & 45 deletions pkg/controller/deployment_rolling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {

Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/deployment_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b80203a

Please sign in to comment.