From 725ec0cc5ec5f783eec349ad3d70bcc0b678f6c0 Mon Sep 17 00:00:00 2001 From: Anthony Yeh Date: Thu, 16 Mar 2017 10:08:22 -0700 Subject: [PATCH] kubectl: Check for Deployment overlap annotation in reaper. This effectively reverts the client-side changes in cec3899b96044af5804ad83694a1565df82a798f. We have to maintain the old behavior on the client side to support version skew when talking to old servers that set the annotation. However, the new server-side behavior is still to NOT set the annotation. --- pkg/controller/deployment/util/deployment_util.go | 5 +++++ pkg/kubectl/stop.go | 7 +++++++ pkg/printers/internalversion/describe.go | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/pkg/controller/deployment/util/deployment_util.go b/pkg/controller/deployment/util/deployment_util.go index 01b5f33ebf8..ff10001c683 100644 --- a/pkg/controller/deployment/util/deployment_util.go +++ b/pkg/controller/deployment/util/deployment_util.go @@ -67,6 +67,10 @@ const ( RollbackTemplateUnchanged = "DeploymentRollbackTemplateUnchanged" // RollbackDone is the done rollback event reason RollbackDone = "DeploymentRollback" + // OverlapAnnotation marks deployments with overlapping selector with other deployments + // TODO: Delete this annotation when we no longer need to support a client + // talking to a server older than v1.6. + OverlapAnnotation = "deployment.kubernetes.io/error-selector-overlapping-with" // Reasons for deployment conditions // @@ -287,6 +291,7 @@ var annotationsToSkip = map[string]bool{ RevisionHistoryAnnotation: true, DesiredReplicasAnnotation: true, MaxReplicasAnnotation: true, + OverlapAnnotation: true, } // skipCopyAnnotation returns true if we should skip copying the annotation with the given annotation key diff --git a/pkg/kubectl/stop.go b/pkg/kubectl/stop.go index 70cea6deba0..9ccd9e40792 100644 --- a/pkg/kubectl/stop.go +++ b/pkg/kubectl/stop.go @@ -440,6 +440,13 @@ func (reaper *DeploymentReaper) Stop(namespace, name string, timeout time.Durati return err } + // Do not cascade deletion for overlapping deployments. + // A Deployment with this annotation will not create or manage anything, + // so we can assume any matching ReplicaSets belong to another Deployment. + if len(deployment.Annotations[deploymentutil.OverlapAnnotation]) > 0 { + return deployments.Delete(name, nil) + } + // Stop all replica sets belonging to this Deployment. rss, err := deploymentutil.ListReplicaSetsInternal(deployment, func(namespace string, options metav1.ListOptions) ([]*extensions.ReplicaSet, error) { diff --git a/pkg/printers/internalversion/describe.go b/pkg/printers/internalversion/describe.go index 19f50a65c3d..f8cfabf4376 100644 --- a/pkg/printers/internalversion/describe.go +++ b/pkg/printers/internalversion/describe.go @@ -2441,6 +2441,10 @@ func (dd *DeploymentDescriber) Describe(namespace, name string, describerSetting } w.Write(LEVEL_0, "NewReplicaSet:\t%s\n", printReplicaSetsByLabels(newRSs)) } + overlapWith := d.Annotations[deploymentutil.OverlapAnnotation] + if len(overlapWith) > 0 { + w.Write(LEVEL_0, "!!!WARNING!!! This deployment has overlapping label selector with deployment %q and won't behave as expected. Please fix it before continuing.\n", overlapWith) + } if describerSettings.ShowEvents { events, err := dd.Core().Events(namespace).Search(api.Scheme, d) if err == nil && events != nil {