Skip to content

Commit

Permalink
Do not recreate CA deployment when CA CR is being deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelSpeed committed Jul 26, 2021
1 parent e5c1bd1 commit 27bf4c4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/controller/clusterautoscaler/clusterautoscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r *Reconciler) Reconcile(_ context.Context, request reconcile.Request) (re
return reconcile.Result{}, err
}

_, err = r.GetAutoscaler(ca)
existingDeployment, err := r.GetAutoscaler(ca)
if err != nil && !errors.IsNotFound(err) {
errMsg := fmt.Sprintf("Error getting cluster-autoscaler deployment: %v", err)
r.recorder.Event(caRef, corev1.EventTypeWarning, "FailedGetDeployment", errMsg)
Expand All @@ -189,6 +189,18 @@ func (r *Reconciler) Reconcile(_ context.Context, request reconcile.Request) (re
return reconcile.Result{}, err
}

// Make sure not to create a new deployment when the CA is being removed.
if ca.GetDeletionTimestamp() != nil {
if !errors.IsNotFound(err) {
// We've already checked for other errors, so this means there was no error, ie the deployment exists.
// Remove the deployment if it still exists (GC may have beaten us to this).
if err := r.client.Delete(context.TODO(), existingDeployment); err != nil && !errors.IsNotFound(err) {
return reconcile.Result{}, err
}
}
return reconcile.Result{}, nil
}

if err := r.ensureAutoscalerMonitoring(ca); err != nil {
errMsg := fmt.Sprintf("Error ensuring ClusterAutoscaler monitoring: %v", err)
r.recorder.Event(caRef, corev1.EventTypeWarning, "FailedCreate", errMsg)
Expand Down

0 comments on commit 27bf4c4

Please sign in to comment.