Skip to content

Commit

Permalink
Merge pull request #2114 from JoelSpeed/introduce-kal
Browse files Browse the repository at this point in the history
Introduce KAL (Kube-API-Linter) to API repo
  • Loading branch information
openshift-merge-bot[bot] authored Dec 4, 2024
2 parents 58d4ac4 + 7c017f5 commit c1fdeb0
Show file tree
Hide file tree
Showing 2,757 changed files with 408,820 additions and 14,985 deletions.
16 changes: 16 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
linters-settings:
custom:
kal:
type: "module"
description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices.
settings:
linters: {}
linters:
disable-all: true
enable:
- kal
issues:
# We have a lot of existing issues.
# Want to make sure that those adding new fields have an
# opportunity to fix them when running the linter locally.
max-issues-per-linter: 1000
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"go.lintTool": "golangci-lint",
"go.alternateTools": {
"golangci-lint": "${workspaceFolder}/hack/golangci-lint.sh",
}
}
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ update-codegen-crds: update-scripts
#
#####################

# When not otherwise set, diff/lint against the local master branch
PULL_BASE_SHA ?= master

.PHONY: lint
lint:
hack/golangci-lint.sh run --new-from-rev=${PULL_BASE_SHA}

# While https://github.com/golangci/golangci-lint/issues/1779 is not fixed,
# we need to run the fix separately from the lint command.
# GolangCI-Lint will not actually run the fixer for us.
# In the future we can remove this and have the linter auto-fix.
.PHONY: lint-fix
lint-fix:
hack/lint-fix.sh

.PHONY: verify-scripts
verify-scripts:
bash -x hack/verify-deepcopy.sh
Expand All @@ -56,7 +71,7 @@ verify-scripts:
hack/verify-promoted-features-pass-tests.sh

.PHONY: verify
verify: verify-scripts verify-crd-schema verify-codegen-crds
verify: verify-scripts lint verify-crd-schema verify-codegen-crds

.PHONY: verify-codegen-crds
verify-codegen-crds:
Expand Down
18 changes: 18 additions & 0 deletions hack/golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

# Build codegen-crds when it's not present and not overriden for a specific file.
if [ -z "${GOLANGCI_LINT:-}" ];then
${TOOLS_MAKE} golangci-kal
GOLANGCI_LINT="${TOOLS_OUTPUT}/golangci-kal"
fi

# In CI, HOME is set to / and is not writable.
# Make sure golangci-lint can create its cache.
HOME=${HOME:-"/tmp"}
if [[ ${HOME} == "/" ]]; then
HOME="/tmp"
fi

"${GOLANGCI_LINT}" $@
11 changes: 11 additions & 0 deletions hack/lint-fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

# Build codegen-crds when it's not present and not overriden for a specific file.
if [ -z "${KAL:-}" ];then
${TOOLS_MAKE} kal
KAL="${TOOLS_OUTPUT}/kal"
fi

"${KAL}" -fix ./...
6 changes: 6 additions & 0 deletions tools/.custom-gcl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v1.62.0
name: golangci-kal
destination: ./bin
plugins:
- module: 'github.com/JoelSpeed/kal'
version: v0.0.0-20241203114946-bdb342a271f6
24 changes: 21 additions & 3 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ publish-kubebuilder-tools:
.PHONY:codegen
codegen: $(OUTPUT_DIR)/codegen

.PHONY:prerelease-lifecycle-gen
prerelease-lifecycle-gen: $(OUTPUT_DIR)/prerelease-lifecycle-gen

.PHONY:controller-gen
controller-gen: $(OUTPUT_DIR)/controller-gen

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

.PHONY:golangci-kal
golangci-kal: $(OUTPUT_DIR)/golangci-kal

.PHONY:kal
kal: $(OUTPUT_DIR)/kal

.PHONY:openapi-gen
openapi-gen: $(OUTPUT_DIR)/openapi-gen

.PHONY:prerelease-lifecycle-gen
prerelease-lifecycle-gen: $(OUTPUT_DIR)/prerelease-lifecycle-gen

.PHONY:protoc-gen-gogo
protoc-gen-gogo: $(OUTPUT_DIR)/protoc-gen-gogo

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

$(OUTPUT_DIR)/golangci-lint: $(OUTPUT_DIR)/vendor-version
go build -mod=vendor -o $(OUTPUT_DIR)/golangci-lint ./vendor/github.com/golangci/golangci-lint/cmd/golangci-lint

# The golangci-lint custom command relies on finding a module, this uses a workaround to init the go.mod in the kal directory.
$(OUTPUT_DIR)/golangci-kal: $(OUTPUT_DIR)/vendor-version $(OUTPUT_DIR)/golangci-lint
GOFLAGS=-mod=readonly $(OUTPUT_DIR)/golangci-lint custom
@ mv bin/golangci-kal $(OUTPUT_DIR)/golangci-kal
@ rmdir bin

$(OUTPUT_DIR)/kal: $(OUTPUT_DIR)/vendor-version
go build -mod=vendor -o $(OUTPUT_DIR)/kal ./vendor/github.com/JoelSpeed/kal/cmd/kal

$(OUTPUT_DIR)/openapi-gen: $(OUTPUT_DIR)/vendor-version
go build -mod=vendor -o $(OUTPUT_DIR)/openapi-gen ./vendor/k8s.io/code-generator/cmd/openapi-gen

Expand Down
Loading

0 comments on commit c1fdeb0

Please sign in to comment.