-
Notifications
You must be signed in to change notification settings - Fork 1.6k
:WIP sparkles: Add KAL and fix missing parts from tutorials #4888
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ jobs: | |
uses: golangci/golangci-lint-action@v8 | ||
with: | ||
version: v2.2.2 | ||
install-mode: goinstall |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ jobs: | |
uses: golangci/golangci-lint-action@v8 | ||
with: | ||
version: v2.2.2 | ||
install-mode: goinstall | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It allow we run the linter as a go Module |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,20 @@ linters: | |
- unconvert | ||
- unparam | ||
- unused | ||
- kubeapilinter | ||
settings: | ||
revive: | ||
rules: | ||
- name: comment-spacings | ||
- name: import-shadowing | ||
custom: | ||
kubeapilinter: | ||
path: "./bin/kube-api-linter.so" | ||
description: "Kube API Linter plugin" | ||
original-url: "sigs.k8s.io/kube-api-linter" | ||
settings: | ||
linters: { } | ||
lintersConfig: { } | ||
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should discuss sensible defaults to these options for CRDs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you suggesting that we should not enable all by default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some linters that are disabled by default because they only make sense for CRDs. There are some linters where the default config makes sense only for built-ins, and they need specific configuration for CRDs. This is an ideal place to document what the correct configuration should be for CRDs in general There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are calling only in the api dir, but that is a good call. |
||
exclusions: | ||
generated: lax | ||
rules: | ||
|
@@ -36,6 +45,9 @@ linters: | |
- dupl | ||
- lll | ||
path: internal/* | ||
- path-except: "^api/" | ||
linters: | ||
- kubeapilinter | ||
paths: | ||
- third_party$ | ||
- builtin$ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ jobs: | |
uses: golangci/golangci-lint-action@v8 | ||
with: | ||
version: v2.2.2 | ||
install-mode: goinstall |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests | |
@$(KIND) delete cluster --name $(KIND_CLUSTER) | ||
|
||
.PHONY: lint | ||
lint: golangci-lint ## Run golangci-lint linter | ||
lint: golangci-lint kube-api-linter ## Run golangci-lint linter | ||
$(GOLANGCI_LINT) run | ||
|
||
.PHONY: lint-fix | ||
|
@@ -225,6 +225,23 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. | |
$(GOLANGCI_LINT): $(LOCALBIN) | ||
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) | ||
|
||
# To lint Kubernetes API definitions. | ||
# More info: https://github.com/kubernetes-sigs/kube-api-linter | ||
KUBE_API_LINTER_PLUGIN := $(LOCALBIN)/kube-api-linter.so | ||
KUBE_API_LINTER_BUILD_DIR := ./hack/kube-api-linter | ||
|
||
.PHONY: kube-api-linter | ||
kube-api-linter: $(KUBE_API_LINTER_PLUGIN) ## Build the kube-api-linter plugin | ||
$(KUBE_API_LINTER_PLUGIN): $(KUBE_API_LINTER_BUILD_DIR)/go.mod | ||
cd $(KUBE_API_LINTER_BUILD_DIR) && \ | ||
go build -buildmode=plugin -o "$(abspath $(KUBE_API_LINTER_PLUGIN))" sigs.k8s.io/kube-api-linter/pkg/plugin | ||
$(KUBE_API_LINTER_BUILD_DIR)/go.mod: | ||
@echo "Setting up local module for kube-api-linter plugin..." | ||
mkdir -p $(KUBE_API_LINTER_BUILD_DIR) | ||
cd $(KUBE_API_LINTER_BUILD_DIR) && \ | ||
go mod init local-kube-api-linter && \ | ||
go get sigs.k8s.io/kube-api-linter@latest | ||
Comment on lines
+239
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this achieve? Why was it needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it to allow us to build the linter locally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The approach taken for K/K and other repos has generally to have a separate go.mod for tools (new Go tools directives), and then this doesn't add deps to the main go.mod, but does allow all of the tools to built using the same environment.
But you're building it with the first command, so I'm not sure why there's then a second get of the linter after you've already built the plugin?
This is on the todo, but has been lower priority, as so far everyone who has used it has largely been ok with the plugin or module way of building things |
||
|
||
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist | ||
# $1 - target path with name of binary | ||
# $2 - package url which can be installed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ jobs: | |
uses: golangci/golangci-lint-action@v8 | ||
with: | ||
version: v2.2.2 | ||
install-mode: goinstall |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@everettraven @JoelSpeed
Do you see a better way to install with Golang CI 2x?
Would it be possible to do a release of the linter like any initial version, such as v0.1.0, and provide its binary so that we can download it here instead to simplify the install?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're currently trying to build this as a plugin, which means you also need to build the golangci-lint binary within the same Go module so that they share dependencies.
I would recommend using the module version of KAL where you compile a complete custom version of golangci-lint with KAL installed. In the future I hope to have a complete CLI released that is a custom version of golangci-lint, I'll see if I can do something about that next week as that might make this easier