-
Notifications
You must be signed in to change notification settings - Fork 216
feat: add kube-api-linter checker #421
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
Merged
k8s-ci-robot
merged 11 commits into
kubernetes-sigs:main
from
dongjiang1989:add-kube-api-linter
Mar 19, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2c21f69
add kube-api-linter checker
dongjiang1989 d6e67d4
fix by codereview
dongjiang1989 31ad777
rm no use file
dongjiang1989 e07d414
revert dev/ci/presubmits/lint-go
dongjiang1989 63fe46d
update chmod 755
dongjiang1989 b0c37dd
Update dev/tools/lint-api
dongjiang1989 7a88fae
Update extensions/api/v1alpha1/sandboxclaim_types.go
dongjiang1989 66b3b7d
fix lint-api
dongjiang1989 9616cf1
update by codereview
dongjiang1989 ec6cfc3
update make gen
dongjiang1989 be20b18
revert nit
dongjiang1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright 2025 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. | ||
|
|
||
| import sys | ||
|
|
||
| from shared import utils | ||
|
|
||
|
|
||
| def main(): | ||
| """ invokes go kube api linter """ | ||
| return utils.run_dev_tool("lint-api") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| version: v2.10.1 | ||
| name: golangci-kube-api-linter | ||
| destination: ./tmp/bin/ | ||
| plugins: | ||
| - module: 'sigs.k8s.io/kube-api-linter' | ||
| version: v0.0.0-20260206102632-39e3d06a2850 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # This file holds the Kube-API-Linter (KAL) configuration. | ||
| # KAL ensures that our Custom Resource Definitions meet the Kubernetes API | ||
| # conventions (as much as possible). | ||
| # | ||
| # The linters documentation is at | ||
| # https://github.com/kubernetes-sigs/kube-api-linter/blob/main/docs/linters.md | ||
| version: "2" | ||
| run: | ||
| go: "1.26" | ||
| allow-parallel-runners: true | ||
| linters: | ||
| default: none | ||
| enable: | ||
| - kubeapilinter | ||
| settings: | ||
| custom: | ||
| kubeapilinter: | ||
| type: module | ||
| description: KAL is the Kube-API-Linter and lints Custom Resource Definitions (CRDs) based on API conventions and best practices. | ||
| settings: | ||
| linters: | ||
| # We configure the list of enabled linters explicitly. | ||
| # Whenever a new linter is added, it should not break the backward | ||
| # compatibility of existing APIs (at least for v1 APIs). | ||
| enable: | ||
| - "nobools" | ||
| - "commentstart" | ||
| - "conflictingmarkers" | ||
| - "duplicatemarkers" | ||
| - "nofloats" | ||
| - "optionalorrequired" | ||
| - "statussubresource" | ||
| - "uniquemarkers" | ||
| - "jsontags" | ||
| - "statusoptional" | ||
| - "nophase" | ||
| - "nonullable" | ||
| - "forbiddenmarkers" | ||
| - "nomaps" | ||
| disable: | ||
| - "*" | ||
|
dongjiang1989 marked this conversation as resolved.
|
||
| lintersConfig: | ||
| conflictingmarkers: | ||
| conflicts: | ||
| - name: "default_vs_required" | ||
| sets: | ||
| - ["default", "kubebuilder:default"] | ||
| - ["required", "kubebuilder:validation:Required", "k8s:required"] | ||
| description: "A field with a default value cannot be required" | ||
| forbiddenmarkers: | ||
| markers: | ||
| - identifier: "+kubebuilder:pruning:PreserveUnknownFields" | ||
| - identifier: "+kubebuilder:validation:XPreserveUnknownFields" | ||
| - identifier: "+kubebuilder:validation:items:XPreserveUnknownFields" | ||
| - identifier: "+kubebuilder:validation:EmbeddedResource" | ||
| - identifier: "+kubebuilder:validation:XEmbeddedResource" | ||
| - identifier: "+kubebuilder:validation:items:XEmbeddedResource" | ||
| exclusions: | ||
| generated: strict | ||
| paths: | ||
| # Exclude test files and generated code. | ||
| - _test\.go | ||
| - zz_generated.*\.go$ | ||
| rules: | ||
| # KAL only validates the API folders for CRD client generation. | ||
| - path-except: "api/.*" | ||
| linters: | ||
| - kubeapilinter | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/usr/bin/env bash | ||
|
dongjiang1989 marked this conversation as resolved.
|
||
| # Copyright 2025 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 nounset | ||
| set -o pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| OUTPUT_DIR="${SCRIPT_DIR}/tmp/bin" | ||
| OUTPUT_BINARY="${OUTPUT_DIR}/golangci-kube-api-linter" | ||
|
|
||
| mkdir -p "${OUTPUT_DIR}" | ||
|
|
||
| echo "Building golangci-kube-api-linter..." | ||
|
dongjiang1989 marked this conversation as resolved.
|
||
| (cd "${SCRIPT_DIR}" && go tool -modfile "${SCRIPT_DIR}/go.mod" golangci-lint custom) | ||
|
dongjiang1989 marked this conversation as resolved.
|
||
|
|
||
| if [ -f "${OUTPUT_BINARY}" ]; then | ||
| echo "Build complete. Binary: ${OUTPUT_BINARY}" | ||
| else | ||
| echo "Build failed: binary not found at ${OUTPUT_BINARY}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Build complete. Run with:" | ||
| echo " ${OUTPUT_BINARY} run --config=${SCRIPT_DIR}/.golangci-kal.yml" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.