-
Notifications
You must be signed in to change notification settings - Fork 4.3k
#8325 Adds kubeapi linter to the project #8737
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
50dc876
0037665
3c0e537
a52f7f0
77b273a
d5b5e1b
9729f40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| version: v2.5.0 | ||
| name: golangci-kube-api-linter | ||
| destination: ./bin | ||
| plugins: | ||
| - module: 'sigs.k8s.io/kube-api-linter' | ||
| version: v0.0.0-20250908163129-65a570bd22aa |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| version: "2" | ||
| run: | ||
| go: "1.25" | ||
| allow-parallel-runners: true | ||
| linters: | ||
| default: none | ||
| enable: | ||
| - kubeapilinter # linter for Kube API conventions | ||
| settings: | ||
| custom: | ||
| kubeapilinter: | ||
| type: module | ||
| description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices. | ||
| settings: | ||
| linters: | ||
| enable: | ||
| #- "commentstart" # Ensure comments start with the serialized version of the field name. | ||
| #- "conditions" # Ensure conditions have the correct json tags and markers. | ||
| #- "conflictingmarkers" | ||
| #- "duplicatemarkers" # Ensure there are no exact duplicate markers. for types and fields. | ||
| #- "integers" # Ensure only int32 and int64 are used for integers. | ||
| #- "jsontags" # Ensure every field has a json tag. | ||
| #- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items. | ||
| #- "nobools" # Bools do not evolve over time, should use enums instead. | ||
| #- "nodurations" # Prevents usage of `Duration` types. | ||
| #- "nofloats" # Ensure floats are not used. | ||
| #- "nomaps" # Ensure maps are not used. | ||
| #- "nonullable" # Ensure that types and fields do not have the nullable marker. | ||
| #- "optionalorrequired" # Every field should be marked as `+optional` or `+required`. | ||
| #- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`. | ||
| #- "ssatags" # Ensure array fields have the appropriate listType markers | ||
| #- "statusoptional" # Ensure all first children within status should be optional. | ||
| #- "statussubresource" # All root objects that have a `status` field should have a status subresource. | ||
| #- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once. | ||
| disable: | ||
| - "*" # Disable all by default. | ||
| lintersConfig: | ||
|
|
||
|
|
||
| exclusions: | ||
| build-tags: | ||
| - ignore_autogenerated | ||
| paths: | ||
| - ".*_test.go" # Exclude test files. | ||
| rules: | ||
| ## KAL should only run on APIS folders. | ||
| - path-except: "apis//*" | ||
| linters: | ||
| - kubeapilinter | ||
|
|
||
| issues: | ||
| max-same-issues: 0 | ||
| max-issues-per-linter: 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright 2014 The Kubernetes Authors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| echo "verify-kubelint" | ||
|
|
||
| cd $(dirname "${BASH_SOURCE}")/.. | ||
| SCRIPT_ROOT="$PWD" | ||
|
|
||
| TOOLS_DIR="${PWD}/hack/tools/kube-api-linter" | ||
| TOOLS_BIN_DIR="${TOOLS_DIR}/bin" | ||
|
|
||
| GOLANGCI_LINT_BIN=${GOLANGCI_LINT_BIN:-"golangci-lint"} | ||
| GOLANGCI_LINT_KAL_BIN=${GOLANGCI_LINT_KAL_BIN:-"${TOOLS_BIN_DIR}/golangci-kube-api-linter"} | ||
| GOLANGCI_LINT_CONFIG_PATH=${GOLANGCI_LINT_CONFIG_PATH:-"${TOOLS_DIR}/.golangci-kal.yml"} | ||
|
|
||
| echo "creating custom golangci linter" | ||
| cd "${TOOLS_DIR}"; "${GOLANGCI_LINT_BIN}" custom | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work for me: I can't figure out why though, that clone works manually
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you run I made a clean copy of the repo and I cannot reproduce it
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, thanks My preference is a standalone script that doesn't require a user to know that another script has to be run before. Other than that, it worked as expected! Thanks!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can, just keep in mind
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, that makes sense. Thanks! |
||
| cd "${SCRIPT_ROOT}" | ||
|
|
||
| "${GOLANGCI_LINT_KAL_BIN}" run -v --config "${GOLANGCI_LINT_CONFIG_PATH}" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this is ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with 1.24 the pipeline fails: https://github.com/kubernetes/autoscaler/actions/runs/19970789057/job/57274722659
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it is possible to use go version lower than
1.25.golangci-lintstarted using1.25from version2.4.0.The
kube-api-linterjumped straight fromgolangci-lintversion1.64to2.50.There was a version in between that suppose to use
golangci2.0.2, but I do not know how find the artifact generated by that build.