Skip to content

🐛 (CLI): Fix panic from unchecked type assertion in printDeprecationWarnings#5689

Open
SebTardif wants to merge 1 commit into
kubernetes-sigs:masterfrom
SebTardif:fix/unchecked-type-assertion-panic
Open

🐛 (CLI): Fix panic from unchecked type assertion in printDeprecationWarnings#5689
SebTardif wants to merge 1 commit into
kubernetes-sigs:masterfrom
SebTardif:fix/unchecked-type-assertion-panic

Conversation

@SebTardif
Copy link
Copy Markdown

Problem

In pkg/cli/cli.go line 586, printDeprecationWarnings uses bare type assertions:

if p != nil && p.(plugin.Deprecated) != nil && len(p.(plugin.Deprecated).DeprecationWarning()) > 0 {
    _, _ = fmt.Fprintf(os.Stderr, noticeColor, fmt.Sprintf(deprecationFmt, p.(plugin.Deprecated).DeprecationWarning()))
}

p.(plugin.Deprecated) without the comma-ok pattern panics at runtime if any resolved plugin does not implement the plugin.Deprecated interface. This can be triggered by external plugins (user-installed binaries) that do not implement Deprecated.

The safe comma-ok pattern is already used elsewhere in the same codebase:

  • pkg/cli/root.go:180: if deprecated, ok := p.(plugin.Deprecated); ok {
  • pkg/cli/init.go:102: if _, isDeprecated := p.(plugin.Deprecated); !isDeprecated {

The unsafe assertion on line 586 was introduced on 2023-03-20.

Fix

Use the comma-ok pattern (deprecated, ok := p.(plugin.Deprecated)), matching the style in root.go:180. This also eliminates three redundant type assertions per iteration by reusing the deprecated variable.

Verification

  • make lint-fix: 0 issues
  • go test ./pkg/cli/...: all pass

…cationWarnings

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 9, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: SebTardif
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.

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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @SebTardif. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 9, 2026
@camilamacedo86 camilamacedo86 changed the title 🐛 Fix panic from unchecked type assertion in printDeprecationWarnings 🐛 (CLI) Fix panic from unchecked type assertion in printDeprecationWarnings May 11, 2026
@camilamacedo86
Copy link
Copy Markdown
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 11, 2026
@SebTardif
Copy link
Copy Markdown
Author

/retest

1 similar comment
@SebTardif
Copy link
Copy Markdown
Author

/retest

@SebTardif SebTardif changed the title 🐛 (CLI) Fix panic from unchecked type assertion in printDeprecationWarnings 🐛 (CLI): Fix panic from unchecked type assertion in printDeprecationWarnings May 12, 2026
@SebTardif
Copy link
Copy Markdown
Author

/retest

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@SebTardif: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-36-0 91c184b link true /test pull-kubebuilder-e2e-k8s-1-36-0

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants