From 2f745c5f911daa2dc6614ffe9ecff0c3a8f81960 Mon Sep 17 00:00:00 2001 From: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com> Date: Sun, 20 Jul 2025 05:32:27 +0100 Subject: [PATCH] KPA experimental install --- .github/workflows/lint-sample.yml | 2 +- .../testdata/project/.custom-gcl.yml | 7 +++ .../testdata/project/.golangci.yml | 12 +++++ .../testdata/project/Makefile | 6 +++ .../testdata/project/.custom-gcl.yml | 7 +++ .../testdata/project/.golangci.yml | 12 +++++ .../getting-started/testdata/project/Makefile | 6 +++ .../testdata/project/.custom-gcl.yml | 7 +++ .../testdata/project/.golangci.yml | 12 +++++ .../testdata/project/Makefile | 6 +++ pkg/plugins/golang/v4/scaffolds/init.go | 1 + .../internal/templates/custom-gcl.go | 51 +++++++++++++++++++ .../scaffolds/internal/templates/golangci.go | 12 +++++ .../scaffolds/internal/templates/makefile.go | 6 +++ .../project-v4-multigroup/.custom-gcl.yml | 7 +++ testdata/project-v4-multigroup/.golangci.yml | 12 +++++ testdata/project-v4-multigroup/Makefile | 6 +++ .../project-v4-with-plugins/.custom-gcl.yml | 7 +++ .../project-v4-with-plugins/.golangci.yml | 12 +++++ testdata/project-v4-with-plugins/Makefile | 6 +++ testdata/project-v4/.custom-gcl.yml | 7 +++ testdata/project-v4/.golangci.yml | 12 +++++ testdata/project-v4/Makefile | 6 +++ 23 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 docs/book/src/cronjob-tutorial/testdata/project/.custom-gcl.yml create mode 100644 docs/book/src/getting-started/testdata/project/.custom-gcl.yml create mode 100644 docs/book/src/multiversion-tutorial/testdata/project/.custom-gcl.yml create mode 100644 pkg/plugins/golang/v4/scaffolds/internal/templates/custom-gcl.go create mode 100644 testdata/project-v4-multigroup/.custom-gcl.yml create mode 100644 testdata/project-v4-with-plugins/.custom-gcl.yml create mode 100644 testdata/project-v4/.custom-gcl.yml diff --git a/.github/workflows/lint-sample.yml b/.github/workflows/lint-sample.yml index f76c5c3ae5e..39baf34ecc4 100644 --- a/.github/workflows/lint-sample.yml +++ b/.github/workflows/lint-sample.yml @@ -43,7 +43,7 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v8 with: - version: v2.2.2 + version: v2.3.0 working-directory: ${{ matrix.folder }} - name: Run linter via makefile target working-directory: ${{ matrix.folder }} diff --git a/docs/book/src/cronjob-tutorial/testdata/project/.custom-gcl.yml b/docs/book/src/cronjob-tutorial/testdata/project/.custom-gcl.yml new file mode 100644 index 00000000000..eec7e25694a --- /dev/null +++ b/docs/book/src/cronjob-tutorial/testdata/project/.custom-gcl.yml @@ -0,0 +1,7 @@ +version: v2.0.0 +name: golangci-custom-linters +destination: ./bin + +plugins: + - module: sigs.k8s.io/kube-api-linter + version: latest diff --git a/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml b/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml index e5b21b0f11c..f83ab7200a2 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml +++ b/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: ./bin/golangci-custom-linters + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: {} + lintersConfig: {} exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/docs/book/src/cronjob-tutorial/testdata/project/Makefile b/docs/book/src/cronjob-tutorial/testdata/project/Makefile index ea5e2ba96b9..3dc6b17c562 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/Makefile +++ b/docs/book/src/cronjob-tutorial/testdata/project/Makefile @@ -224,6 +224,12 @@ $(ENVTEST): $(LOCALBIN) 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)) + @echo "Running golangci-lint custom..." + @$(LOCALBIN)/golangci-lint custom || { \ + echo "golangci-lint failed. Cleaning up..."; \ + rm -f $(LOCALBIN)/golangci-lint; \ + exit 1; \ + } # 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 diff --git a/docs/book/src/getting-started/testdata/project/.custom-gcl.yml b/docs/book/src/getting-started/testdata/project/.custom-gcl.yml new file mode 100644 index 00000000000..eec7e25694a --- /dev/null +++ b/docs/book/src/getting-started/testdata/project/.custom-gcl.yml @@ -0,0 +1,7 @@ +version: v2.0.0 +name: golangci-custom-linters +destination: ./bin + +plugins: + - module: sigs.k8s.io/kube-api-linter + version: latest diff --git a/docs/book/src/getting-started/testdata/project/.golangci.yml b/docs/book/src/getting-started/testdata/project/.golangci.yml index e5b21b0f11c..f83ab7200a2 100644 --- a/docs/book/src/getting-started/testdata/project/.golangci.yml +++ b/docs/book/src/getting-started/testdata/project/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: ./bin/golangci-custom-linters + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: {} + lintersConfig: {} exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/docs/book/src/getting-started/testdata/project/Makefile b/docs/book/src/getting-started/testdata/project/Makefile index ccb6e7d8bd9..2006c819c4c 100644 --- a/docs/book/src/getting-started/testdata/project/Makefile +++ b/docs/book/src/getting-started/testdata/project/Makefile @@ -220,6 +220,12 @@ $(ENVTEST): $(LOCALBIN) 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)) + @echo "Running golangci-lint custom..." + @$(LOCALBIN)/golangci-lint custom || { \ + echo "golangci-lint failed. Cleaning up..."; \ + rm -f $(LOCALBIN)/golangci-lint; \ + exit 1; \ + } # 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 diff --git a/docs/book/src/multiversion-tutorial/testdata/project/.custom-gcl.yml b/docs/book/src/multiversion-tutorial/testdata/project/.custom-gcl.yml new file mode 100644 index 00000000000..eec7e25694a --- /dev/null +++ b/docs/book/src/multiversion-tutorial/testdata/project/.custom-gcl.yml @@ -0,0 +1,7 @@ +version: v2.0.0 +name: golangci-custom-linters +destination: ./bin + +plugins: + - module: sigs.k8s.io/kube-api-linter + version: latest diff --git a/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml b/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml index e5b21b0f11c..f83ab7200a2 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml +++ b/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: ./bin/golangci-custom-linters + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: {} + lintersConfig: {} exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/docs/book/src/multiversion-tutorial/testdata/project/Makefile b/docs/book/src/multiversion-tutorial/testdata/project/Makefile index ea5e2ba96b9..3dc6b17c562 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/Makefile +++ b/docs/book/src/multiversion-tutorial/testdata/project/Makefile @@ -224,6 +224,12 @@ $(ENVTEST): $(LOCALBIN) 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)) + @echo "Running golangci-lint custom..." + @$(LOCALBIN)/golangci-lint custom || { \ + echo "golangci-lint failed. Cleaning up..."; \ + rm -f $(LOCALBIN)/golangci-lint; \ + exit 1; \ + } # 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 diff --git a/pkg/plugins/golang/v4/scaffolds/init.go b/pkg/plugins/golang/v4/scaffolds/init.go index 712232bb721..5d5e2ea5d44 100644 --- a/pkg/plugins/golang/v4/scaffolds/init.go +++ b/pkg/plugins/golang/v4/scaffolds/init.go @@ -174,6 +174,7 @@ func (s *initScaffolder) Scaffold() error { &templates.DockerIgnore{}, &templates.Readme{CommandName: s.commandName}, &templates.Golangci{}, + &templates.CustomGcl{}, &e2e.Test{}, &e2e.WebhookTestUpdater{WireWebhook: false}, &e2e.SuiteTest{}, diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/custom-gcl.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/custom-gcl.go new file mode 100644 index 00000000000..d59388312a6 --- /dev/null +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/custom-gcl.go @@ -0,0 +1,51 @@ +/* +Copyright 2025 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package templates + +import ( + "sigs.k8s.io/kubebuilder/v4/pkg/machinery" +) + +var _ machinery.Template = &CustomGcl{} + +// CustomGcl scaffolds a file ..custom-gcl.yaml which define KAL configuration to install +type CustomGcl struct { + machinery.TemplateMixin + machinery.ProjectNameMixin +} + +// SetTemplateDefaults implements machinery.Template +func (f *CustomGcl) SetTemplateDefaults() error { + if f.Path == "" { + f.Path = ".custom-gcl.yml" + } + + f.TemplateBody = customGCLTemplate + + f.IfExistsAction = machinery.SkipFile + + return nil +} + +const customGCLTemplate = `version: v2.0.0 +name: golangci-custom-linters +destination: ./bin + +plugins: + - module: sigs.k8s.io/kube-api-linter + version: latest +` diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go index d2a1d1fc012..ce50eb4ccb0 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go @@ -64,11 +64,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: ./bin/golangci-custom-linters + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: {} + lintersConfig: {} exclusions: generated: lax rules: @@ -79,6 +88,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go index 135280fbf3b..75c1b3c87a4 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go @@ -299,6 +299,12 @@ $(ENVTEST): $(LOCALBIN) 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)) + @echo "Running golangci-lint custom..." + @$(LOCALBIN)/golangci-lint custom || { \ + echo "golangci-lint failed. Cleaning up..."; \ + rm -f $(LOCALBIN)/golangci-lint; \ + exit 1; \ + } # 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 diff --git a/testdata/project-v4-multigroup/.custom-gcl.yml b/testdata/project-v4-multigroup/.custom-gcl.yml new file mode 100644 index 00000000000..eec7e25694a --- /dev/null +++ b/testdata/project-v4-multigroup/.custom-gcl.yml @@ -0,0 +1,7 @@ +version: v2.0.0 +name: golangci-custom-linters +destination: ./bin + +plugins: + - module: sigs.k8s.io/kube-api-linter + version: latest diff --git a/testdata/project-v4-multigroup/.golangci.yml b/testdata/project-v4-multigroup/.golangci.yml index e5b21b0f11c..f83ab7200a2 100644 --- a/testdata/project-v4-multigroup/.golangci.yml +++ b/testdata/project-v4-multigroup/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: ./bin/golangci-custom-linters + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: {} + lintersConfig: {} exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/testdata/project-v4-multigroup/Makefile b/testdata/project-v4-multigroup/Makefile index 4b8cb2f2c1e..1ab8c62dee0 100644 --- a/testdata/project-v4-multigroup/Makefile +++ b/testdata/project-v4-multigroup/Makefile @@ -220,6 +220,12 @@ $(ENVTEST): $(LOCALBIN) 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)) + @echo "Running golangci-lint custom..." + @$(LOCALBIN)/golangci-lint custom || { \ + echo "golangci-lint failed. Cleaning up..."; \ + rm -f $(LOCALBIN)/golangci-lint; \ + exit 1; \ + } # 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 diff --git a/testdata/project-v4-with-plugins/.custom-gcl.yml b/testdata/project-v4-with-plugins/.custom-gcl.yml new file mode 100644 index 00000000000..eec7e25694a --- /dev/null +++ b/testdata/project-v4-with-plugins/.custom-gcl.yml @@ -0,0 +1,7 @@ +version: v2.0.0 +name: golangci-custom-linters +destination: ./bin + +plugins: + - module: sigs.k8s.io/kube-api-linter + version: latest diff --git a/testdata/project-v4-with-plugins/.golangci.yml b/testdata/project-v4-with-plugins/.golangci.yml index e5b21b0f11c..f83ab7200a2 100644 --- a/testdata/project-v4-with-plugins/.golangci.yml +++ b/testdata/project-v4-with-plugins/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: ./bin/golangci-custom-linters + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: {} + lintersConfig: {} exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/testdata/project-v4-with-plugins/Makefile b/testdata/project-v4-with-plugins/Makefile index 15e229ab6ee..2fb116cb47e 100644 --- a/testdata/project-v4-with-plugins/Makefile +++ b/testdata/project-v4-with-plugins/Makefile @@ -220,6 +220,12 @@ $(ENVTEST): $(LOCALBIN) 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)) + @echo "Running golangci-lint custom..." + @$(LOCALBIN)/golangci-lint custom || { \ + echo "golangci-lint failed. Cleaning up..."; \ + rm -f $(LOCALBIN)/golangci-lint; \ + exit 1; \ + } # 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 diff --git a/testdata/project-v4/.custom-gcl.yml b/testdata/project-v4/.custom-gcl.yml new file mode 100644 index 00000000000..eec7e25694a --- /dev/null +++ b/testdata/project-v4/.custom-gcl.yml @@ -0,0 +1,7 @@ +version: v2.0.0 +name: golangci-custom-linters +destination: ./bin + +plugins: + - module: sigs.k8s.io/kube-api-linter + version: latest diff --git a/testdata/project-v4/.golangci.yml b/testdata/project-v4/.golangci.yml index e5b21b0f11c..f83ab7200a2 100644 --- a/testdata/project-v4/.golangci.yml +++ b/testdata/project-v4/.golangci.yml @@ -21,11 +21,20 @@ linters: - unconvert - unparam - unused + - kubeapilinter settings: revive: rules: - name: comment-spacings - name: import-shadowing + custom: + kubeapilinter: + path: ./bin/golangci-custom-linters + description: "Kube API Linter plugin" + original-url: "sigs.k8s.io/kube-api-linter" + settings: + linters: {} + lintersConfig: {} exclusions: generated: lax rules: @@ -36,6 +45,9 @@ linters: - dupl - lll path: internal/* + - path-except: "^api/" + linters: + - kubeapilinter paths: - third_party$ - builtin$ diff --git a/testdata/project-v4/Makefile b/testdata/project-v4/Makefile index 0d4c65f6a81..f387a04c93a 100644 --- a/testdata/project-v4/Makefile +++ b/testdata/project-v4/Makefile @@ -220,6 +220,12 @@ $(ENVTEST): $(LOCALBIN) 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)) + @echo "Running golangci-lint custom..." + @$(LOCALBIN)/golangci-lint custom || { \ + echo "golangci-lint failed. Cleaning up..."; \ + rm -f $(LOCALBIN)/golangci-lint; \ + exit 1; \ + } # 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