Skip to content

Commit

Permalink
Remove rollbackTo in deployment controller
Browse files Browse the repository at this point in the history
  • Loading branch information
pigletfly committed Aug 8, 2020
1 parent ce662e1 commit 80ccf45
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 198 deletions.
3 changes: 0 additions & 3 deletions pkg/controller/deployment/BUILD
Expand Up @@ -12,7 +12,6 @@ go_library(
"deployment_controller.go",
"progress.go",
"recreate.go",
"rollback.go",
"rolling.go",
"sync.go",
],
Expand All @@ -23,7 +22,6 @@ go_library(
"//pkg/util/labels:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/extensions/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
Expand Down Expand Up @@ -73,7 +71,6 @@ go_test(
"//pkg/controller/testutil:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/extensions/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
Expand Down
9 changes: 1 addition & 8 deletions pkg/controller/deployment/deployment_controller.go
Expand Up @@ -29,7 +29,7 @@ import (
"k8s.io/klog/v2"

apps "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -630,13 +630,6 @@ func (dc *DeploymentController) syncDeployment(key string) error {
return dc.sync(d, rsList)
}

// rollback is not re-entrant in case the underlying replica sets are updated with a new
// revision so we should ensure that we won't proceed to update replica sets until we
// make sure that the deployment has cleaned up its rollback spec in subsequent enqueues.
if getRollbackTo(d) != nil {
return dc.rollback(d, rsList)
}

scalingEvent, err := dc.isScalingEvent(d, rsList)
if err != nil {
return err
Expand Down
36 changes: 1 addition & 35 deletions pkg/controller/deployment/deployment_controller_test.go
Expand Up @@ -22,8 +22,7 @@ import (
"testing"

apps "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -45,7 +44,6 @@ import (
_ "k8s.io/kubernetes/pkg/apis/settings/install"
_ "k8s.io/kubernetes/pkg/apis/storage/install"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller/deployment/util"
"k8s.io/kubernetes/pkg/controller/testutil"
)

Expand Down Expand Up @@ -164,11 +162,6 @@ func (f *fixture) expectUpdateDeploymentStatusAction(d *apps.Deployment) {
f.actions = append(f.actions, action)
}

func (f *fixture) expectUpdateDeploymentAction(d *apps.Deployment) {
action := core.NewUpdateAction(schema.GroupVersionResource{Resource: "deployments"}, d.Namespace, d)
f.actions = append(f.actions, action)
}

func (f *fixture) expectCreateRSAction(rs *apps.ReplicaSet) {
f.actions = append(f.actions, core.NewCreateAction(schema.GroupVersionResource{Resource: "replicasets"}, rs.Namespace, rs))
}
Expand Down Expand Up @@ -334,33 +327,6 @@ func TestDontSyncDeploymentsWithEmptyPodSelector(t *testing.T) {
f.run(testutil.GetKey(d, t))
}

func TestReentrantRollback(t *testing.T) {
f := newFixture(t)

d := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
d.Annotations = map[string]string{util.RevisionAnnotation: "2"}
setRollbackTo(d, &extensions.RollbackConfig{Revision: 0})
f.dLister = append(f.dLister, d)

rs1 := newReplicaSet(d, "deploymentrs-old", 0)
rs1.Annotations = map[string]string{util.RevisionAnnotation: "1"}
one := int64(1)
rs1.Spec.Template.Spec.TerminationGracePeriodSeconds = &one
rs1.Spec.Selector.MatchLabels[apps.DefaultDeploymentUniqueLabelKey] = "hash"

rs2 := newReplicaSet(d, "deploymentrs-new", 1)
rs2.Annotations = map[string]string{util.RevisionAnnotation: "2"}
rs2.Spec.Selector.MatchLabels[apps.DefaultDeploymentUniqueLabelKey] = "hash"

f.rsLister = append(f.rsLister, rs1, rs2)
f.objects = append(f.objects, d, rs1, rs2)

// Rollback is done here
f.expectUpdateDeploymentAction(d)
// Expect no update on replica sets though
f.run(testutil.GetKey(d, t))
}

// TestPodDeletionEnqueuesRecreateDeployment ensures that the deletion of a pod
// will requeue a Recreate deployment iff there is no other pod returned from the
// client.
Expand Down
149 changes: 0 additions & 149 deletions pkg/controller/deployment/rollback.go

This file was deleted.

6 changes: 3 additions & 3 deletions pkg/controller/deployment/sync.go
Expand Up @@ -24,7 +24,7 @@ import (
"strconv"

apps "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -57,8 +57,8 @@ func (dc *DeploymentController) sync(d *apps.Deployment, rsList []*apps.ReplicaS
return err
}

// Clean up the deployment when it's paused and no rollback is in flight.
if d.Spec.Paused && getRollbackTo(d) == nil {
// Clean up the deployment when it's paused.
if d.Spec.Paused {
if err := dc.cleanupDeployment(oldRSs, d); err != nil {
return err
}
Expand Down

0 comments on commit 80ccf45

Please sign in to comment.