Skip to content

Commit 75ef09b

Browse files
Merge pull request #16438 from juanvallejo/jvallejo/prevent-oc-rollout-panic
Automatic merge from submit-queue (batch tested with PRs 16861, 16438). Prevent `oc rollout` panic when resource given is not a dc Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1493071 Prevents nil pointer dereference by skipping command logic when given resource is not of type *deployapi.DeploymentConfig. **Before** ``` $ oc rollout cancel rc/my-rc-1 panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x189 pc=0x3821780] ... ``` **After** ``` $ oc rollout cancel rc/my-rc-1 error: expected deployment configuration, got *api.ReplicationController ``` cc @openshift/cli-review
2 parents 20db538 + d863f04 commit 75ef09b

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed

examples/examples_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func TestExampleObjectSchemas(t *testing.T) {
121121
"../test/integration/testdata": {
122122
// TODO fix this test to handle json and yaml
123123
"project-request-template-with-quota": nil, // skip a yaml file
124+
"test-replication-controller": nil, // skip &api.ReplicationController
124125
"test-deployment-config": &deployapi.DeploymentConfig{},
125126
"test-image": &imageapi.Image{},
126127
"test-image-stream": &imageapi.ImageStream{},

pkg/oc/cli/cmd/rollout/cancel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ func (o CancelOptions) Run() error {
111111
for _, info := range o.Infos {
112112
config, ok := info.Object.(*deployapi.DeploymentConfig)
113113
if !ok {
114-
allErrs = append(allErrs, kcmdutil.AddSourceToErr("cancelling", info.Source, fmt.Errorf("expected deployment configuration, got %T", info.Object)))
114+
allErrs = append(allErrs, kcmdutil.AddSourceToErr("cancelling", info.Source, fmt.Errorf("expected deployment configuration, got %s", info.Mapping.Resource)))
115+
continue
115116
}
116117
if config.Spec.Paused {
117118
allErrs = append(allErrs, kcmdutil.AddSourceToErr("cancelling", info.Source, fmt.Errorf("unable to cancel paused deployment %s/%s", config.Namespace, config.Name)))

test/cmd/deployments.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ os::cmd::try_until_success 'oc rollout pause dc/database'
9696
os::cmd::try_until_text "oc get dc/database --template='{{.spec.paused}}'" "true"
9797
os::cmd::try_until_success 'oc rollout resume dc/database'
9898
os::cmd::try_until_text "oc get dc/database --template='{{.spec.paused}}'" "<no value>"
99+
# create a replication controller and attempt to perform `oc rollout cancel` on it.
100+
# expect an error about the resource type, rather than a panic or a success.
101+
os::cmd::expect_success 'oc create -f test/integration/testdata/test-replication-controller.yaml'
102+
os::cmd::expect_failure_and_text 'oc rollout cancel rc/test-replication-controller' 'expected deployment configuration, got replicationcontrollers'
103+
99104
echo "rollout: ok"
100105
os::test::junit::declare_suite_end
101106

test/extended/testdata/bindata.go

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: v1
2+
kind: ReplicationController
3+
metadata:
4+
annotations:
5+
openshift.io/deployment-config.latest-version: "1"
6+
openshift.io/deployment-config.name: test-deployment
7+
openshift.io/deployment.phase: Complete
8+
optnshift.io/deployment.replicas: "1"
9+
name: test-replication-controller
10+
spec:
11+
replicas: 1
12+
selector:
13+
deployment: test-deployment
14+
deploymentconfig: test-deployment
15+
template:
16+
metadata:
17+
labels:
18+
deployment: test-deployment
19+
deploymentconfig: test-deployment
20+
spec:
21+
containers:
22+
- image: openshift/origin-pod
23+
imagePullPolicy: IfNotPresent
24+
name: ruby-helloworld
25+
ports:
26+
- containerPort: 8080
27+
protocol: TCP
28+
resources: {}
29+
dnsPolicy: ClusterFirst
30+
restartPolicy: Always
31+
status: {}

0 commit comments

Comments
 (0)