Skip to content

oc: rolling back to the same dc version should be a no-op #13104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/deploy/registry/rollback/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, err
return nil, newInvalidError(rollback, "cannot rollback an undeployed config")
case 1:
return nil, newInvalidError(rollback, fmt.Sprintf("no previous deployment exists for %q", deployutil.LabelForDeploymentConfig(from)))
case rollback.Spec.Revision:
return nil, newInvalidError(rollback, fmt.Sprintf("version %d is already the latest", rollback.Spec.Revision))
}

revision := from.Status.LatestVersion - 1
Expand Down
21 changes: 21 additions & 0 deletions pkg/deploy/registry/rollback/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ func TestCreateOk(t *testing.T) {
}
}

func TestCreateRollbackToLatest(t *testing.T) {
oc := &testclient.Fake{}
oc.AddReactor("get", "deploymentconfigs", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, deploytest.OkDeploymentConfig(2), nil
})

_, err := NewREST(oc, &fake.Clientset{}, codec).Create(kapi.NewDefaultContext(), &deployapi.DeploymentConfigRollback{
Name: "config",
Spec: deployapi.DeploymentConfigRollbackSpec{
Revision: 2,
},
})

if err == nil {
t.Errorf("expected an error when rolling back to the existing deployed revision")
}
if err != nil && !strings.Contains(err.Error(), "version 2 is already the latest") {
t.Errorf("unexpected error received: %v", err)
}
}

func TestCreateGeneratorError(t *testing.T) {
oc := &testclient.Fake{}
oc.AddReactor("get", "deploymentconfigs", func(action core.Action) (handled bool, ret runtime.Object, err error) {
Expand Down
2 changes: 2 additions & 0 deletions test/cmd/deployments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ os::cmd::expect_failure 'oc rollback database -o yaml'
os::cmd::expect_success 'oc set image dc/database ruby-helloworld-database=foo --source=docker'
# wait for the new deployment
os::cmd::try_until_success 'oc rollout history dc/database --revision=2'
# rolling back to the same revision should fail
os::cmd::expect_failure 'oc rollback dc/database --to-version=2'
# undo --dry-run should report the original image
os::cmd::expect_success_and_text 'oc rollout undo dc/database --dry-run' 'mysql-57-centos7'
echo "rollback: ok"
Expand Down