Skip to content

Commit 854be25

Browse files
author
Kamil
committed
#8325 Adds kubeapi linter to the project
1 parent 8ff8d91 commit 854be25

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

hack/install-verify-tools.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ go install github.com/tools/godep@latest
2626

2727
go install github.com/client9/misspell/cmd/misspell@latest
2828

29+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
30+
2931
# ex: ts=2 sw=2 et filetype=sh

hack/tools/.custom-gcl.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v2.5.0
2+
name: golangci-kube-api-linter
3+
destination: ./bin
4+
plugins:
5+
- module: 'sigs.k8s.io/kube-api-linter'
6+
version: v0.0.0-20250908163129-65a570bd22aa

hack/tools/.golangci-kal.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
version: "2"
2+
run:
3+
go: "1.24"
4+
allow-parallel-runners: true
5+
linters:
6+
default: none
7+
enable:
8+
- kubeapilinter # linter for Kube API conventions
9+
settings:
10+
custom:
11+
kubeapilinter:
12+
type: module
13+
description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices.
14+
settings:
15+
linters:
16+
enable:
17+
#- "commentstart" # Ensure comments start with the serialized version of the field name.
18+
#- "conditions" # Ensure conditions have the correct json tags and markers.
19+
#- "conflictingmarkers"
20+
#- "duplicatemarkers" # Ensure there are no exact duplicate markers. for types and fields.
21+
#- "integers" # Ensure only int32 and int64 are used for integers.
22+
#- "jsontags" # Ensure every field has a json tag.
23+
#- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items.
24+
#- "nobools" # Bools do not evolve over time, should use enums instead.
25+
#- "nodurations" # Prevents usage of `Duration` types.
26+
#- "nofloats" # Ensure floats are not used.
27+
#- "nomaps" # Ensure maps are not used.
28+
#- "nonullable" # Ensure that types and fields do not have the nullable marker.
29+
#- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
30+
#- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`.
31+
#- "ssatags" # Ensure array fields have the appropriate listType markers
32+
#- "statusoptional" # Ensure all first children within status should be optional.
33+
#- "statussubresource" # All root objects that have a `status` field should have a status subresource.
34+
#- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once.
35+
disable:
36+
- "*" # Disable all by default.
37+
lintersConfig:
38+
39+
40+
exclusions:
41+
build-tags:
42+
- ignore_autogenerated
43+
paths:
44+
- ".*_test.go" # Exclude test files.
45+
rules:
46+
## KAL should only run on APIS folders.
47+
- path-except: "apis//*"
48+
linters:
49+
- kubeapilinter
50+
51+
issues:
52+
max-same-issues: 0
53+
max-issues-per-linter: 0

hack/verify-kubelint.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Copyright 2014 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
echo "verify-kubelint"
22+
23+
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
24+
cd "${KUBE_ROOT}"
25+
ROOT_DIR="$PWD"
26+
27+
TOOLS_DIR="${ROOT_DIR}/hack/tools"
28+
TOOLS_BIN_DIR="${TOOLS_DIR}/bin"
29+
30+
GOLANGCI_LINT_BIN=${GOLANGCI_LINT_BIN:-"golangci-lint"}
31+
GOLANGCI_LINT_KAL_BIN=${GOLANGCI_LINT_KAL_BIN:-"${TOOLS_BIN_DIR}/golangci-kube-api-linter"}
32+
GOLANGCI_LINT_CONFIG_PATH=${GOLANGCI_LINT_CONFIG_PATH:-"${TOOLS_DIR}/.golangci-kal.yml"}
33+
34+
echo "creating custom golangci linter"
35+
cd "${TOOLS_DIR}"; "${GOLANGCI_LINT_BIN}" custom
36+
37+
cd "${ROOT_DIR}"
38+
39+
PACKAGES=(
40+
"${ROOT_DIR}/cluster-autoscaler"
41+
"${ROOT_DIR}/vertical-pod-autoscaler"
42+
)
43+
44+
for package in "${PACKAGES[@]}"; do
45+
cd "${package}"
46+
"${GOLANGCI_LINT_KAL_BIN}" run -v --config "${GOLANGCI_LINT_CONFIG_PATH}"
47+
done

0 commit comments

Comments
 (0)