Skip to content

Commit c1fdeb0

Browse files
Merge pull request #2114 from JoelSpeed/introduce-kal
Introduce KAL (Kube-API-Linter) to API repo
2 parents 58d4ac4 + 7c017f5 commit c1fdeb0

File tree

2,757 files changed

+408820
-14985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,757 files changed

+408820
-14985
lines changed

.golangci.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
linters-settings:
2+
custom:
3+
kal:
4+
type: "module"
5+
description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices.
6+
settings:
7+
linters: {}
8+
linters:
9+
disable-all: true
10+
enable:
11+
- kal
12+
issues:
13+
# We have a lot of existing issues.
14+
# Want to make sure that those adding new fields have an
15+
# opportunity to fix them when running the linter locally.
16+
max-issues-per-linter: 1000

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"go.lintTool": "golangci-lint",
3+
"go.alternateTools": {
4+
"golangci-lint": "${workspaceFolder}/hack/golangci-lint.sh",
5+
}
6+
}

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ update-codegen-crds: update-scripts
3939
#
4040
#####################
4141

42+
# When not otherwise set, diff/lint against the local master branch
43+
PULL_BASE_SHA ?= master
44+
45+
.PHONY: lint
46+
lint:
47+
hack/golangci-lint.sh run --new-from-rev=${PULL_BASE_SHA}
48+
49+
# While https://github.com/golangci/golangci-lint/issues/1779 is not fixed,
50+
# we need to run the fix separately from the lint command.
51+
# GolangCI-Lint will not actually run the fixer for us.
52+
# In the future we can remove this and have the linter auto-fix.
53+
.PHONY: lint-fix
54+
lint-fix:
55+
hack/lint-fix.sh
56+
4257
.PHONY: verify-scripts
4358
verify-scripts:
4459
bash -x hack/verify-deepcopy.sh
@@ -56,7 +71,7 @@ verify-scripts:
5671
hack/verify-promoted-features-pass-tests.sh
5772

5873
.PHONY: verify
59-
verify: verify-scripts verify-crd-schema verify-codegen-crds
74+
verify: verify-scripts lint verify-crd-schema verify-codegen-crds
6075

6176
.PHONY: verify-codegen-crds
6277
verify-codegen-crds:

hack/golangci-lint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
4+
5+
# Build codegen-crds when it's not present and not overriden for a specific file.
6+
if [ -z "${GOLANGCI_LINT:-}" ];then
7+
${TOOLS_MAKE} golangci-kal
8+
GOLANGCI_LINT="${TOOLS_OUTPUT}/golangci-kal"
9+
fi
10+
11+
# In CI, HOME is set to / and is not writable.
12+
# Make sure golangci-lint can create its cache.
13+
HOME=${HOME:-"/tmp"}
14+
if [[ ${HOME} == "/" ]]; then
15+
HOME="/tmp"
16+
fi
17+
18+
"${GOLANGCI_LINT}" $@

hack/lint-fix.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
4+
5+
# Build codegen-crds when it's not present and not overriden for a specific file.
6+
if [ -z "${KAL:-}" ];then
7+
${TOOLS_MAKE} kal
8+
KAL="${TOOLS_OUTPUT}/kal"
9+
fi
10+
11+
"${KAL}" -fix ./...

tools/.custom-gcl.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v1.62.0
2+
name: golangci-kal
3+
destination: ./bin
4+
plugins:
5+
- module: 'github.com/JoelSpeed/kal'
6+
version: v0.0.0-20241203114946-bdb342a271f6

tools/Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ publish-kubebuilder-tools:
4646
.PHONY:codegen
4747
codegen: $(OUTPUT_DIR)/codegen
4848

49-
.PHONY:prerelease-lifecycle-gen
50-
prerelease-lifecycle-gen: $(OUTPUT_DIR)/prerelease-lifecycle-gen
51-
5249
.PHONY:controller-gen
5350
controller-gen: $(OUTPUT_DIR)/controller-gen
5451

@@ -58,9 +55,18 @@ deepcopy-gen: $(OUTPUT_DIR)/deepcopy-gen
5855
.PHONY:go-to-protobuf
5956
go-to-protobuf: $(OUTPUT_DIR)/go-to-protobuf
6057

58+
.PHONY:golangci-kal
59+
golangci-kal: $(OUTPUT_DIR)/golangci-kal
60+
61+
.PHONY:kal
62+
kal: $(OUTPUT_DIR)/kal
63+
6164
.PHONY:openapi-gen
6265
openapi-gen: $(OUTPUT_DIR)/openapi-gen
6366

67+
.PHONY:prerelease-lifecycle-gen
68+
prerelease-lifecycle-gen: $(OUTPUT_DIR)/prerelease-lifecycle-gen
69+
6470
.PHONY:protoc-gen-gogo
6571
protoc-gen-gogo: $(OUTPUT_DIR)/protoc-gen-gogo
6672

@@ -99,6 +105,18 @@ $(OUTPUT_DIR)/deepcopy-gen: $(OUTPUT_DIR)/vendor-version
99105
$(OUTPUT_DIR)/go-to-protobuf: $(OUTPUT_DIR)/vendor-version
100106
go build -mod=vendor -o $(OUTPUT_DIR)/go-to-protobuf ./vendor/k8s.io/code-generator/cmd/go-to-protobuf
101107

108+
$(OUTPUT_DIR)/golangci-lint: $(OUTPUT_DIR)/vendor-version
109+
go build -mod=vendor -o $(OUTPUT_DIR)/golangci-lint ./vendor/github.com/golangci/golangci-lint/cmd/golangci-lint
110+
111+
# The golangci-lint custom command relies on finding a module, this uses a workaround to init the go.mod in the kal directory.
112+
$(OUTPUT_DIR)/golangci-kal: $(OUTPUT_DIR)/vendor-version $(OUTPUT_DIR)/golangci-lint
113+
GOFLAGS=-mod=readonly $(OUTPUT_DIR)/golangci-lint custom
114+
@ mv bin/golangci-kal $(OUTPUT_DIR)/golangci-kal
115+
@ rmdir bin
116+
117+
$(OUTPUT_DIR)/kal: $(OUTPUT_DIR)/vendor-version
118+
go build -mod=vendor -o $(OUTPUT_DIR)/kal ./vendor/github.com/JoelSpeed/kal/cmd/kal
119+
102120
$(OUTPUT_DIR)/openapi-gen: $(OUTPUT_DIR)/vendor-version
103121
go build -mod=vendor -o $(OUTPUT_DIR)/openapi-gen ./vendor/k8s.io/code-generator/cmd/openapi-gen
104122

0 commit comments

Comments
 (0)