Skip to content

Commit d7c5992

Browse files
authored
Enable Kubernetes API Linter (#3917)
* Add kubeapi linter * Enable duplicatemarkers linter * Enable jsontags linter * Enable nofloats linter * Enable nomaps linter * Enable nophase linter * Enable requiredfields linter * Enable statussubresource linter * Enable uniquemarkers linter * Enable Kube API Linter Github Workflow * Pin lint version correctly and fix config file spacing * Fix kal github actions spacing and remove requiredfields linter
1 parent b285585 commit d7c5992

File tree

6 files changed

+67
-17
lines changed

6 files changed

+67
-17
lines changed

.custom-gcl.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v2.2.1
2+
name: golangci-kube-api-linter
3+
destination: ./bin
4+
plugins:
5+
- module: 'sigs.k8s.io/kube-api-linter'
6+
version: 'v0.0.0-20250715075424-4fab82d26a8e' # Pin to a commit while there's no tag

.github/workflows/kal.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: PR golangci-lint
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
7+
# Remove all permissions from GITHUB_TOKEN except metadata.
8+
permissions: {}
9+
10+
jobs:
11+
golangci:
12+
name: kube-api-lint
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
steps:
17+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2
18+
- name: Set up Go
19+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # tag=v5.5.0
20+
- name: Install Golang CI Lint
21+
run: go install github.com/golangci/golangci-lint/v2/cmd/[email protected]
22+
- name: Build KAL
23+
run: golangci-lint custom
24+
- name: run api linter
25+
run: ./bin/golangci-kube-api-linter run -c ./.golangci-kal.yml ./...

.golangci-kal.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: "2"
2+
linters:
3+
default: none
4+
enable:
5+
- kubeapilinter
6+
settings:
7+
custom:
8+
kubeapilinter:
9+
type: module
10+
description: Kube API LInter lints Kube like APIs based on API conventions and best practices.
11+
settings:
12+
linters:
13+
enable:
14+
- "duplicatemarkers" # Ensure there are no exact duplicate markers. for types and fields.
15+
- "jsontags" # Ensure every field has a json tag.
16+
- "nofloats" # Ensure floats are not used.
17+
- "nomaps" # Ensure maps are not used.
18+
- "nophase" # Phase fields are discouraged by the Kube API conventions, use conditions instead.
19+
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
20+
- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once.
21+
disable:
22+
- "*"
23+
lintersConfig: {}
24+
exclusions:
25+
generated: strict
26+
paths:
27+
- conformance/
28+
paths-except:
29+
- apis/
30+
- apisx/
31+
issues:
32+
max-issues-per-linter: 0
33+
max-same-issues: 0
34+
run:
35+
timeout: 5m
36+
tests: false

apis/v1/httproute_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,6 @@ type HTTPBackendRef struct {
15901590
// +optional
15911591
// +kubebuilder:validation:MaxItems=16
15921592
// +kubebuilder:validation:XValidation:message="May specify either httpRouteFilterRequestRedirect or httpRouteFilterRequestRewrite, but not both",rule="!(self.exists(f, f.type == 'RequestRedirect') && self.exists(f, f.type == 'URLRewrite'))"
1593-
// +kubebuilder:validation:XValidation:message="May specify either httpRouteFilterRequestRedirect or httpRouteFilterRequestRewrite, but not both",rule="!(self.exists(f, f.type == 'RequestRedirect') && self.exists(f, f.type == 'URLRewrite'))"
15941593
// +kubebuilder:validation:XValidation:message="RequestHeaderModifier filter cannot be repeated",rule="self.filter(f, f.type == 'RequestHeaderModifier').size() <= 1"
15951594
// +kubebuilder:validation:XValidation:message="ResponseHeaderModifier filter cannot be repeated",rule="self.filter(f, f.type == 'ResponseHeaderModifier').size() <= 1"
15961595
// +kubebuilder:validation:XValidation:message="RequestRedirect filter cannot be repeated",rule="self.filter(f, f.type == 'RequestRedirect').size() <= 1"

config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/standard/gateway.networking.k8s.io_httproutes.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)