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 {