Skip to content

ci: fix lint issues for golangci-lint v2.12.1#199

Open
rawadhossain wants to merge 1 commit intokubernetes-sigs:mainfrom
rawadhossain:golangci-lint
Open

ci: fix lint issues for golangci-lint v2.12.1#199
rawadhossain wants to merge 1 commit intokubernetes-sigs:mainfrom
rawadhossain:golangci-lint

Conversation

@rawadhossain
Copy link
Copy Markdown

@rawadhossain rawadhossain commented May 3, 2026

This pr resolves the issues reported by golangci-lint v2.12.1 that block upgrading the linter version in CI.

Fixes #195

Changes

  • G704 (SSRF) — readiness-condition-reporter/main.go
    Excluded via .golangci.yml. The endpoint comes from the CHECK_ENDPOINT env var (deployment config), not user input.

  • G703 (path traversal) — suite_test.go
    Excluded via .golangci.yml. This is test only code using KUBEBUILDER_ASSETS from the envtest setup.

  • prealloc — nodereadinessgaterule_webhook.go
    Preallocated allErrs (make(..., 0, 4)) to address the prealloc linter.

Why config exclusions instead of //nolint

Inline //nolint:gosec triggers nolintlint errors on v2.9.0 (since the checks don’t exist there). Using .golangci.yml keeps things compatible across both versions. So clean results on v2.12.1.

With these fixes, golangci-lint can be upgraded in CI without breaking.

Testing

Before:
image

After:
image
make lint (v2.9.0) and golangci-lint run ./... (v2.12.1) are both clean.

Checklist

  • make test passes
  • make lint passes

@netlify
Copy link
Copy Markdown

netlify Bot commented May 3, 2026

Deploy Preview for node-readiness-controller canceled.

Name Link
🔨 Latest commit 4cd54c9
🔍 Latest deploy log https://app.netlify.com/projects/node-readiness-controller/deploys/69f7271859c0f2000824c0b4

@k8s-ci-robot k8s-ci-robot requested a review from ajaysundark May 3, 2026 10:44
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rawadhossain
Once this PR has been reviewed and has the lgtm label, please assign sergeykanzhelev 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

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 3, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: rawadhossain / name: Rawad Hossain (4cd54c9)

@k8s-ci-robot k8s-ci-robot requested a review from haircommander May 3, 2026 10:44
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 3, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @rawadhossain!

It looks like this is your first PR to kubernetes-sigs/node-readiness-controller 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/node-readiness-controller has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @rawadhossain. 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/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 3, 2026
@ajaysundark ajaysundark requested review from Karthik-K-N and removed request for haircommander May 4, 2026 20:08
Comment thread .golangci.yml
- gosec
path: "test/utils/"
text: "G204"
- linters:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ins't there any better way apart from excluding it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hey @Karthik-K-N, thanks for reviewing the PR.

I looked into fixing this properly instead of excluding it.

  • For G703 suite_test.go), using filepath.Clean works fine - no suppression needed.
  • For G704 (main.go), I added URL validation (scheme + host), so we’re not accepting arbitrary inputs anymore. But gosec still flags the HTTP calls. looks like its taint analysis doesn’t treat this validation as a sanitizer.

Because of that, some form of suppression is still needed for those two lines.
The tricky part is that the repo is currently using golangci-lint v2.9.0, which doesn’t include G704. So if I add inline //nolint:gosec, nolintlint flags it as unused and CI fails.

That’s why I initially went with the .golangci.yml exclusion, else the warnings can’t be resolved cleanly with the current lint setup (shared the lint output if helpful).

From here, I see two options:

  1. Keep the validation in code and use a scoped .golangci.yml exclusion just for G704
  2. Upgrade golangci-lint to a version that includes G704, then use inline //nolint:gosec with the validation in place

Happy to go with whichever direction you prefer.

image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think in near future we need to update the golang lint, so I think that would be better, wdyt?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah I think that sounds better for the long term.
I can update the lint version in CI and switch to inline suppression using //nolint:gosec. That should keep things cleaner going forward.

Let me know if you want me to go ahead with that.

@ajaysundark
Copy link
Copy Markdown
Contributor

/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 5, 2026
@ajaysundark ajaysundark requested a review from Karthik-K-N May 5, 2026 18:53
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: golangci-lint v2.12.1 detected issues

4 participants