Skip to content
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

Prevent oc rollout panic when resource given is not a dc #16438

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
1 change: 1 addition & 0 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"../test/integration/testdata": {
// TODO fix this test to handle json and yaml
"project-request-template-with-quota": nil, // skip a yaml file
"test-replication-controller": nil, // skip &api.ReplicationController
"test-deployment-config": &deployapi.DeploymentConfig{},
"test-image": &imageapi.Image{},
"test-image-stream": &imageapi.ImageStream{},
Expand Down
3 changes: 2 additions & 1 deletion pkg/oc/cli/cmd/rollout/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func (o CancelOptions) Run() error {
for _, info := range o.Infos {
config, ok := info.Object.(*deployapi.DeploymentConfig)
if !ok {
allErrs = append(allErrs, kcmdutil.AddSourceToErr("cancelling", info.Source, fmt.Errorf("expected deployment configuration, got %T", info.Object)))
allErrs = append(allErrs, kcmdutil.AddSourceToErr("cancelling", info.Source, fmt.Errorf("expected deployment configuration, got %s", info.Mapping.Resource)))
continue
}
if config.Spec.Paused {
allErrs = append(allErrs, kcmdutil.AddSourceToErr("cancelling", info.Source, fmt.Errorf("unable to cancel paused deployment %s/%s", config.Namespace, config.Name)))
Expand Down
5 changes: 5 additions & 0 deletions test/cmd/deployments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ os::cmd::try_until_success 'oc rollout pause dc/database'
os::cmd::try_until_text "oc get dc/database --template='{{.spec.paused}}'" "true"
os::cmd::try_until_success 'oc rollout resume dc/database'
os::cmd::try_until_text "oc get dc/database --template='{{.spec.paused}}'" "<no value>"
# create a replication controller and attempt to perform `oc rollout cancel` on it.
# expect an error about the resource type, rather than a panic or a success.
os::cmd::expect_success 'oc create -f test/integration/testdata/test-replication-controller.yaml'
os::cmd::expect_failure_and_text 'oc rollout cancel rc/test-replication-controller' 'expected deployment configuration, got replicationcontrollers'

echo "rollout: ok"
os::test::junit::declare_suite_end

Expand Down
51 changes: 51 additions & 0 deletions test/extended/testdata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions test/integration/testdata/test-replication-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: ReplicationController
metadata:
annotations:
openshift.io/deployment-config.latest-version: "1"
openshift.io/deployment-config.name: test-deployment
openshift.io/deployment.phase: Complete
optnshift.io/deployment.replicas: "1"
name: test-replication-controller
spec:
replicas: 1
selector:
deployment: test-deployment
deploymentconfig: test-deployment
template:
metadata:
labels:
deployment: test-deployment
deploymentconfig: test-deployment
spec:
containers:
- image: openshift/origin-pod
imagePullPolicy: IfNotPresent
name: ruby-helloworld
ports:
- containerPort: 8080
protocol: TCP
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}