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

Conversation

juanvallejo
Copy link
Contributor

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

@openshift-ci-robot openshift-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 19, 2017
@juanvallejo juanvallejo force-pushed the jvallejo/prevent-oc-rollout-panic branch from 5faee15 to 279ef22 Compare September 19, 2017 19:31
@@ -112,6 +112,7 @@ func (o CancelOptions) Run() error {
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)))
Copy link
Contributor

Choose a reason for hiding this comment

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

can you use kapi.Scheme.ObjectKind(info.Object).Kind ? seems nicer than raw go type

@juanvallejo juanvallejo force-pushed the jvallejo/prevent-oc-rollout-panic branch from 11e5260 to 0f75016 Compare September 20, 2017 14:40
@juanvallejo
Copy link
Contributor Author

@mfojtik thanks, comment addressed. Left raw go type as fallback

@juanvallejo juanvallejo force-pushed the jvallejo/prevent-oc-rollout-panic branch from 0f75016 to 3260b5a Compare September 20, 2017 14:44
@juanvallejo
Copy link
Contributor Author

/retest

@fabianofranz
Copy link
Member

/unassign
/assign @mfojtik

@juanvallejo
Copy link
Contributor Author

@mfojtik friendly ping

@@ -111,7 +111,12 @@ 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)))
kind, _, err := kapi.Scheme.ObjectKind(info.Object)
Copy link
Contributor

Choose a reason for hiding this comment

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

the info.Resource (i think) carries the resource name name, I would use that instead of getting the kind... it will also show nicer in CLI (not capitalized). WDYT?

# 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 ReplicationController'
Copy link
Contributor

Choose a reason for hiding this comment

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

This will change to "expected deployment configuration, got replicationcontroller" :)

@juanvallejo juanvallejo force-pushed the jvallejo/prevent-oc-rollout-panic branch from 3260b5a to 0c17437 Compare October 12, 2017 20:02
@juanvallejo
Copy link
Contributor Author

@mfojtik thanks for the feedback, review comments addressed

@mfojtik
Copy link
Contributor

mfojtik commented Oct 16, 2017

allright, squash the commits, this looks good to me.

@juanvallejo juanvallejo force-pushed the jvallejo/prevent-oc-rollout-panic branch from 0c17437 to d863f04 Compare October 16, 2017 16:53
@juanvallejo
Copy link
Contributor Author

@mfojtik sorry about the delay. Commits squashed

@mfojtik
Copy link
Contributor

mfojtik commented Oct 17, 2017

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 17, 2017
@openshift-merge-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: juanvallejo, mfojtik

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 17, 2017
@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 16861, 16438).

@openshift-merge-robot openshift-merge-robot merged commit 75ef09b into openshift:master Oct 17, 2017
@juanvallejo juanvallejo deleted the jvallejo/prevent-oc-rollout-panic branch October 17, 2017 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants