Skip to content

Commit

Permalink
don't sync deployment when pod selector is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedanese committed Mar 28, 2016
1 parent fa48e24 commit c430576
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/controller/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func (dsc *DaemonSetsController) syncDaemonSet(key string) error {

everything := unversioned.LabelSelector{}
if reflect.DeepEqual(ds.Spec.Selector, &everything) {
dsc.eventRecorder.Eventf(ds, api.EventTypeWarning, "SelectingAll", "This controller is selecting all pods. Skipping sync.")
dsc.eventRecorder.Eventf(ds, api.EventTypeWarning, "SelectingAll", "This daemon set is selecting all pods. A non-empty selector is required.")
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/deployment/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ func (dc *DeploymentController) syncDeployment(key string) error {
}

d := obj.(*extensions.Deployment)
everything := unversioned.LabelSelector{}
if reflect.DeepEqual(d.Spec.Selector, &everything) {
dc.eventRecorder.Eventf(d, api.EventTypeWarning, "SelectingAll", "This deployment is selecting all pods. A non-empty selector is required.")
return nil
}

if d.Spec.Paused {
// TODO: Implement scaling for paused deployments.
Expand Down
25 changes: 25 additions & 0 deletions pkg/controller/deployment/deployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,28 @@ func TestSyncDeploymentCreatesReplicaSet(t *testing.T) {

f.run(getKey(d, t))
}

// issue: https://github.com/kubernetes/kubernetes/issues/23218
func TestDeploymentController_dontSyncDeploymentsWithEmptyPodSelector(t *testing.T) {
fake := &fake.Clientset{}
controller := NewDeploymentController(fake, controller.NoResyncPeriodFunc)

controller.eventRecorder = &record.FakeRecorder{}
controller.rsStoreSynced = alwaysReady
controller.podStoreSynced = alwaysReady

d := newDeployment(1, nil)
empty := unversioned.LabelSelector{}
d.Spec.Selector = &empty
controller.dStore.Store.Add(d)
// We expect the deployment controller to not take action here since it's configuration
// is invalid, even though no replicasets exist that match it's selector.
controller.syncDeployment(fmt.Sprintf("%s/%s", d.ObjectMeta.Namespace, d.ObjectMeta.Name))
if len(fake.Actions()) == 0 {
return
}
for _, action := range fake.Actions() {
t.Logf("unexpected action: %#v", action)
}
t.Errorf("expected deployment controller to not take action")
}

1 comment on commit c430576

@k8s-teamcity-mesosphere

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity OSS :: Kubernetes Mesos :: 4 - Smoke Tests Build 20060 outcome was SUCCESS
Summary: Tests passed: 1, ignored: 267 Build time: 00:10:26

Please sign in to comment.