From a0522bda64fdeea16c1c128b51451215cf42a349 Mon Sep 17 00:00:00 2001 From: Richard Case Date: Thu, 13 Mar 2025 08:37:18 +0000 Subject: [PATCH 1/4] wip: add kal linter Signed-off-by: Richard Case --- .golangci-kal.yml | 109 ++++++++++++++++++++++++++++++++++++ Makefile | 17 +++++- hack/tools/.custom-gcl.yaml | 6 ++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 .golangci-kal.yml create mode 100644 hack/tools/.custom-gcl.yaml diff --git a/.golangci-kal.yml b/.golangci-kal.yml new file mode 100644 index 0000000000..b01b99ab5d --- /dev/null +++ b/.golangci-kal.yml @@ -0,0 +1,109 @@ +run: + timeout: 10m + go: "1.22" + allow-parallel-runners: true + +linters: + disable-all: true + enable: + - kal # linter for Kube API conventions + +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: + enable: + #- "commentstart" # Ensure comments start with the serialized version of the field name. + #- "conditions" # Ensure conditions have the correct json tags and markers. + #- "integers" # Ensure only int32 and int64 are used for integers. + #- "jsontags" # Ensure every field has a json tag. + #- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items. + #- "nobools" # Bools do not evolve over time, should use enums instead. + - "nofloats" # Ensure floats are not used. + #- "optionalorrequired" # Every field should be marked as `+optional` or `+required`. + # - "requiredfields" # Required fields should not be pointers, and should not have `omitempty`. + - "statussubresource" # All root objects that have a `status` field should have a status subresource. + + # Linters below this line are disabled, pending conversation on how and when to enable them. + disable: + - "*" # We will manually enable new linters after understanding the impact. Disable all by default. + lintersConfig: + conditions: + isFirstField: Warn # Require conditions to be the first field in the status struct. + usePatchStrategy: Forbid # Conditions should not use the patch strategy on CRDs. + useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required. + # jsonTags: + # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. + # optionalOrRequired: + # preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. + # preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. + # requiredFields: + # pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers. + +issues: + exclude-files: + - "zz_generated.*\\.go$" + - "vendored_openapi\\.go$" + # We don't want to invest time to fix new linter findings in old API types. + - "internal/apis/.*" + - ".*_test.go" # Exclude test files. + max-same-issues: 0 + max-issues-per-linter: 0 + exclude-rules: + # KAL should only run on API folders. + - path-except: "api//*" + linters: + - kal + - path: "api/v1beta1/*|api/v1alpha1/*" + text: "Conditions field must be a slice of metav1.Condition" + linters: + - kal + - path: "api/v1beta1/*" + text: "type ClusterIPFamily should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" + linters: + - kal + - path: "exp/ipam/api/v1alpha1/*|exp/ipam/api/v1beta1/*" + text: "field Prefix should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" + linters: + - kal + # clusterctl and Runtime Hooks can be fixed once we bump their apiVersion. + - path: "cmd/clusterctl/api/v1alpha3|exp/runtime/hooks/api/v1alpha1" + text: "maxlength" + linters: + - kal + # controller-gen does not allow to add MaxItems to Schemaless fields + - path: "api/v1beta1/*" + text: "maxlength: field (AllOf|OneOf|AnyOf) must have a maximum items, add kubebuilder:validation:MaxItems marker" + linters: + - kal + # It does not make sense to add a maxItems marker on the *List structs as they are not used to generate CRD YAMLs. + # This exclude will be removed once https://github.com/JoelSpeed/kal/issues/38 is resolved. + - path: "api/v1beta1/*|api/v1alpha1/*" + text: "maxlength: field Items must have a maximum items, add kubebuilder:validation:MaxItems marker" + linters: + - kal + - path: "api/v1alpha1/*|api/v1beta1/*" + text: "nobools" + linters: + - kal + # We follow the current CustomResourceDefinition field's json tag pattern. + - path: "api/v1beta1/*" + text: "field (XPreserveUnknownFields|XPreserveUnknownFields|XValidations|XMetadata|XIntOrString) json tag does not match pattern" + linters: + - kal + # The following rules are disabled until we migrate to the new API. + - path: "bootstrap/kubeadm/api/v1beta1/kubeadm_types.go" + text: "field Token is marked as required, should not be a pointer" + linters: + - kal + - path: "api/v1beta1/clusterclass_types.go" + text: "field Ref is marked as required, should not be a pointer" + linters: + - kal + - path: "api/v1alpha1/*|api/v1beta1/*|api/v1alpha3/*" + text: "field Items must be marked as optional or required" + linters: + - kal diff --git a/Makefile b/Makefile index 9f86432316..d857badbcd 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,9 @@ GOLANGCI_LINT_BIN := golangci-lint GOLANGCI_LINT_VER := $(shell cat .github/workflows/pr-golangci-lint.yaml | grep [[:space:]]version: | sed 's/.*version: //') GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)) GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint +GOLANGCI_LINT_KAL_BIN := golangci-lint-kal +GOLANGCI_LINT_KAL_VER := $(shell cat ./hack/tools/.custom-gcl.yaml | grep name: | sed 's/name: golangci-lint-kal-//') +GOLANGCI_LINT_KAL := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_KAL_BIN)-$(GOLANGCI_LINT_KAL_VER)) KIND := $(TOOLS_BIN_DIR)/kind KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize MOCKGEN := $(TOOLS_BIN_DIR)/mockgen @@ -295,14 +298,26 @@ generate-go-apis: ## Alias for .build/generate-go-apis $(GOLANGCI_LINT): # Build golangci-lint from tools folder. GOBIN=$(abspath $(TOOLS_BIN_DIR)) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER) +$(GOLANGCI_LINT_KAL): $(GOLANGCI_LINT) # Build golangci-lint-kal from custom configuration. + cd $(TOOLS_DIR); $(GOLANGCI_LINT) custom + .PHONY: lint -lint: $(GOLANGCI_LINT) ## Lint codebase +lint: $(GOLANGCI_LINT) $(GOLANGCI_LINT_KAL) ## Lint codebase $(GOLANGCI_LINT) run -v --fast=false $(GOLANGCI_LINT_EXTRA_ARGS) + $(GOLANGCI_LINT_KAL) run -v --config $(REPO_ROOT)/.golangci-kal.yml $(GOLANGCI_LINT_EXTRA_ARGS) .PHONY: lint-fix lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint +.PHONY: lint-api +lint-api: $(GOLANGCI_LINT_KAL) + $(GOLANGCI_LINT_KAL) run -v --config $(REPO_ROOT)/.golangci-kal.yml $(GOLANGCI_LINT_EXTRA_ARGS) + +.PHONY: lint-api-fix +lint-api-fix: $(GOLANGCI_LINT_KAL) + GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint-api + modules: ## Runs go mod to ensure proper vendoring. go mod tidy cd $(TOOLS_DIR); go mod tidy diff --git a/hack/tools/.custom-gcl.yaml b/hack/tools/.custom-gcl.yaml new file mode 100644 index 0000000000..a01eaaf9c6 --- /dev/null +++ b/hack/tools/.custom-gcl.yaml @@ -0,0 +1,6 @@ +version: v1.63.4 +name: golangci-lint-kal-v1.63.4 +destination: ./bin +plugins: + - module: "github.com/JoelSpeed/kal" + version: v0.0.0-20250305092907-abd233a9fed8 From 6a9c13ec741d781d6bb2c1d548658ad921ba1548 Mon Sep 17 00:00:00 2001 From: Richard Case Date: Wed, 14 May 2025 17:56:18 +0100 Subject: [PATCH 2/4] wip: add kal linter Signed-off-by: Richard Case --- .github/workflows/pr-golangci-lint.yaml | 4 +- .golangci-kal.yml | 117 +-- .golangci.yml | 668 +++++++++--------- Makefile | 13 +- api/v1beta1/awscluster_conversion.go | 37 +- api/v1beta1/awsclustertemplate_conversion.go | 3 +- api/v1beta1/awsidentity_conversion.go | 3 +- api/v1beta1/awsmachine_conversion.go | 3 +- api/v1beta1/conversion.go | 1 + api/v1beta1/conversion_test.go | 1 + bootstrap/eks/api/v1beta1/conversion.go | 3 +- bootstrap/eks/api/v1beta1/conversion_test.go | 9 +- .../api/bootstrap/v1alpha1/conversion.go | 7 +- controlplane/eks/api/v1beta1/conversion.go | 22 +- .../eks/api/v1beta1/conversion_test.go | 1 + exp/api/v1beta1/conversion.go | 53 +- exp/api/v1beta1/conversion_test.go | 1 + hack/tools/.custom-gcl.yaml | 8 +- test/e2e/shared/aws_helpers.go | 10 +- versions.mk | 2 +- 20 files changed, 497 insertions(+), 469 deletions(-) diff --git a/.github/workflows/pr-golangci-lint.yaml b/.github/workflows/pr-golangci-lint.yaml index 99ea7da86f..6db66a2d74 100644 --- a/.github/workflows/pr-golangci-lint.yaml +++ b/.github/workflows/pr-golangci-lint.yaml @@ -28,6 +28,8 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@2e788936b09dd82dc280e845628a40d2ba6b204c # tag=v6.3.1 with: - version: v1.62.2 + version: v2.1.0 args: --out-format=colored-line-number working-directory: ${{matrix.working-directory}} + - name: Lint API + run: make lint-api diff --git a/.golangci-kal.yml b/.golangci-kal.yml index b01b99ab5d..9a7d650a1b 100644 --- a/.golangci-kal.yml +++ b/.golangci-kal.yml @@ -1,109 +1,110 @@ +version: "2" + run: timeout: 10m go: "1.22" allow-parallel-runners: true linters: - disable-all: true + default: none enable: - - kal # linter for Kube API conventions - -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: - enable: - #- "commentstart" # Ensure comments start with the serialized version of the field name. - #- "conditions" # Ensure conditions have the correct json tags and markers. - #- "integers" # Ensure only int32 and int64 are used for integers. - #- "jsontags" # Ensure every field has a json tag. - #- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items. - #- "nobools" # Bools do not evolve over time, should use enums instead. - - "nofloats" # Ensure floats are not used. - #- "optionalorrequired" # Every field should be marked as `+optional` or `+required`. - # - "requiredfields" # Required fields should not be pointers, and should not have `omitempty`. - - "statussubresource" # All root objects that have a `status` field should have a status subresource. + - kubeapilinter # linter for Kube API conventions + settings: + custom: + kubeapilinter: + type: "module" + description: KAL is the Kube-API-Linter and lints Kube like APIs based on API conventions and best practices. + settings: + linters: + enable: + #- "commentstart" # Ensure comments start with the serialized version of the field name. + #- "conditions" # Ensure conditions have the correct json tags and markers. + #- "integers" # Ensure only int32 and int64 are used for integers. + #- "jsontags" # Ensure every field has a json tag. + #- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items. + #- "nobools" # Bools do not evolve over time, should use enums instead. + #- "nofloats" # Ensure floats are not used. + #- "optionalorrequired" # Every field should be marked as `+optional` or `+required`. + # - "requiredfields" # Required fields should not be pointers, and should not have `omitempty`. + - "statussubresource" # All root objects that have a `status` field should have a status subresource. - # Linters below this line are disabled, pending conversation on how and when to enable them. - disable: - - "*" # We will manually enable new linters after understanding the impact. Disable all by default. - lintersConfig: - conditions: - isFirstField: Warn # Require conditions to be the first field in the status struct. - usePatchStrategy: Forbid # Conditions should not use the patch strategy on CRDs. - useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required. - # jsonTags: - # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. - # optionalOrRequired: - # preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. - # preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. - # requiredFields: - # pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers. + # Linters below this line are disabled, pending conversation on how and when to enable them. + disable: + - "*" # We will manually enable new linters after understanding the impact. Disable all by default. + lintersConfig: + conditions: + isFirstField: Warn # Require conditions to be the first field in the status struct. + usePatchStrategy: Forbid # Conditions should not use the patch strategy on CRDs. + useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required. + # jsonTags: + # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. + # optionalOrRequired: + # preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. + # preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. + # requiredFields: + # pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers. -issues: - exclude-files: - - "zz_generated.*\\.go$" - - "vendored_openapi\\.go$" - # We don't want to invest time to fix new linter findings in old API types. - - "internal/apis/.*" - - ".*_test.go" # Exclude test files. - max-same-issues: 0 - max-issues-per-linter: 0 - exclude-rules: +exclusions: + generated: strict + paths: + - zz_generated.*\.go$ + - ".*_test.go" # Exclude test files. + rules: # KAL should only run on API folders. - path-except: "api//*" linters: - - kal + - kubeapilinter - path: "api/v1beta1/*|api/v1alpha1/*" text: "Conditions field must be a slice of metav1.Condition" linters: - - kal + - kubeapilinter - path: "api/v1beta1/*" text: "type ClusterIPFamily should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" linters: - - kal + - kubeapilinter - path: "exp/ipam/api/v1alpha1/*|exp/ipam/api/v1beta1/*" text: "field Prefix should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements" linters: - - kal + - kubeapilinter # clusterctl and Runtime Hooks can be fixed once we bump their apiVersion. - path: "cmd/clusterctl/api/v1alpha3|exp/runtime/hooks/api/v1alpha1" text: "maxlength" linters: - - kal + - kubeapilinter # controller-gen does not allow to add MaxItems to Schemaless fields - path: "api/v1beta1/*" text: "maxlength: field (AllOf|OneOf|AnyOf) must have a maximum items, add kubebuilder:validation:MaxItems marker" linters: - - kal + - kubeapilinter # It does not make sense to add a maxItems marker on the *List structs as they are not used to generate CRD YAMLs. # This exclude will be removed once https://github.com/JoelSpeed/kal/issues/38 is resolved. - path: "api/v1beta1/*|api/v1alpha1/*" text: "maxlength: field Items must have a maximum items, add kubebuilder:validation:MaxItems marker" linters: - - kal + - kubeapilinter - path: "api/v1alpha1/*|api/v1beta1/*" text: "nobools" linters: - - kal + - kubeapilinter # We follow the current CustomResourceDefinition field's json tag pattern. - path: "api/v1beta1/*" text: "field (XPreserveUnknownFields|XPreserveUnknownFields|XValidations|XMetadata|XIntOrString) json tag does not match pattern" linters: - - kal + - kubeapilinter # The following rules are disabled until we migrate to the new API. - path: "bootstrap/kubeadm/api/v1beta1/kubeadm_types.go" text: "field Token is marked as required, should not be a pointer" linters: - - kal + - kubeapilinter - path: "api/v1beta1/clusterclass_types.go" text: "field Ref is marked as required, should not be a pointer" linters: - - kal + - kubeapilinter - path: "api/v1alpha1/*|api/v1beta1/*|api/v1alpha3/*" text: "field Items must be marked as optional or required" linters: - - kal + - kubeapilinter + +issues: + max-same-issues: 0 + max-issues-per-linter: 0 diff --git a/.golangci.yml b/.golangci.yml index 65193b1ff8..d87ebbdf39 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,329 +1,349 @@ -linters: - disable-all: true - enable: - - asasalint - - asciicheck - - bidichk - - bodyclose - - containedctx - - copyloopvar - - dogsled - - dupword - - durationcheck - - errcheck - - errchkjson - - gci - - ginkgolinter - - goconst - - gocritic - - godot - - gofmt - - goimports - - goprintffuncname - - gosec - - gosimple - - govet - - iface - - importas - - ineffassign - - intrange - - loggercheck - - misspell - - nakedret - - nilerr - - noctx - - nolintlint - - nosprintfhostport - - prealloc - - predeclared - - revive - - rowserrcheck - - staticcheck - - stylecheck - - thelper - - typecheck - - unconvert - - unparam - - unused - - usestdlibvars - - whitespace - -linters-settings: - gci: - sections: - - standard - - default - - prefix(sigs.k8s.io/cluster-api) - ginkgolinter: - forbid-focus-container: true - suppress-len-assertion: true # Suppress the wrong length assertion warning. - suppress-nil-assertion: false # Suppress the wrong nil assertion warning. - suppress-err-assertion: true # Suppress the wrong error assertion warning. - gocritic: - enabled-tags: - - diagnostic - - experimental - - performance - disabled-checks: - - appendAssign - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - evalOrder - - ifElseChain - - octalLiteral - - regexpSimplify - - sloppyReassign - - truncateCmp - - typeDefFirst - - unnamedResult - - unnecessaryDefer - - whyNoLint - - wrapperFunc - - rangeValCopy - - hugeParam - - filepathJoin - - emptyStringTest - godot: - # declarations - for top level declaration comments (default); - # toplevel - for top level comments; - # all - for all comments. - scope: toplevel - exclude: - - '^ \+.*' - - '^ ANCHOR.*' - revive: - rules: - # The following rules are recommended https://github.com/mgechev/revive#recommended-configuration - - name: blank-imports - - name: context-as-argument - - name: context-keys-type - - name: dot-imports - - name: error-return - - name: error-strings - - name: error-naming - - name: exported - - name: if-return - - name: increment-decrement - - name: var-naming - - name: var-declaration - - name: package-comments - - name: range - - name: receiver-naming - - name: time-naming - - name: unexported-return - - name: indent-error-flow - - name: errorf - - name: empty-block - - name: superfluous-else - - name: unreachable-code - - name: redefines-builtin-id - # - # Rules in addition to the recommended configuration above. - # - - name: bool-literal-in-expr - - name: constant-logical-expr - goconst: - ignore-tests: true - gosec: - excludes: - - G307 # Deferring unsafe method "Close" on type "\*os.File" - - G108 # Profiling endpoint is automatically exposed on /debug/pprof - importas: - no-unaliased: false - alias: - - pkg: k8s.io/api/core/v1 - alias: corev1 - - pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1 - alias: apiextensionsv1 - - pkg: k8s.io/apimachinery/pkg/apis/meta/v1 - alias: metav1 - - pkg: k8s.io/apimachinery/pkg/util/errors - alias: kerrors - - pkg: sigs.k8s.io/controller-runtime/pkg/conversion - alias: ctrlconversion - - pkg: sigs.k8s.io/cluster-api/util/conversion - alias: utilconversion - - pkg: k8s.io/apimachinery/pkg/conversion - alias: apiconversion - - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2 - alias: infrav1 - - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta1 - alias: infrav1beta1 - - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta1 - alias: expinfrav1beta1 - - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2 - alias: expinfrav1 - - pkg: k8s.io/client-go/kubernetes/scheme - alias: cgscheme - - pkg: k8s.io/client-go/tools/record - alias: cgrecord - - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta1 - alias: eksbootstrapv1beta1 - - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2 - alias: eksbootstrapv1 - - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta1 - alias: ekscontrolplanev1beta1 - - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2 - alias: ekscontrolplanev1 - - pkg: "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/controllers" - alias: eksbootstrapcontrollers - - pkg: "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/controllers" - alias: ekscontrolplanecontrollers - - pkg: "sigs.k8s.io/cluster-api-provider-aws/v2/exp/controllers" - alias: expcontrollers - - pkg: "k8s.io/apimachinery/pkg/runtime" - alias: runtime - - pkg: "k8s.io/apimachinery/pkg/runtime/serializer" - alias: runtimeserializer - - pkg: "k8s.io/apimachinery/pkg/runtime/serializer/yaml" - alias: yamlserializer - - pkg: "sigs.k8s.io/cluster-api/api/v1beta1" - alias: clusterv1 - - pkg: "sigs.k8s.io/cluster-api/util/defaulting" - alias: utildefaulting - - pkg: sigs.k8s.io/controller-runtime - alias: ctrl - - pkg: "k8s.io/apimachinery/pkg/api/errors" - alias: apierrors - - pkg: "sigs.k8s.io/controller-runtime/pkg/log" - alias: logf - - pkg: "github.com/google/gofuzz" - alias: fuzz - - pkg: "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/logs" - alias: awslogs - - pkg: "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/metrics" - alias: awsmetrics - - pkg: "sigs.k8s.io/cluster-api/errors" - alias: capierrors - - pkg: "github.com/aws/aws-sdk-go/aws/client" - alias: awsclient - - pkg: "github.com/aws/amazon-vpc-cni-k8s/pkg/apis/crd/v1alpha1" - alias: amazoncni - - pkg: "github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi" - alias: rgapi - - pkg: "crypto/rand" - alias: crand - - pkg: "sigs.k8s.io/controller-runtime/pkg/client" - alias: crclient - - pkg: "k8s.io/apimachinery/pkg/types" - alias: apimachinerytypes - - pkg: "sigs.k8s.io/cluster-api/exp/api/v1beta1" - alias: expclusterv1 - nolintlint: - allow-unused: false - allow-leading-space: false - require-specific: true - staticcheck: - go: "1.22" - stylecheck: - go: "1.22" - depguard: - rules: - main: - deny: - - pkg: "io/ioutil" - desc: "ioutil is deprecated starting with Go 1.16" -issues: - max-same-issues: 0 - max-issues-per-linter: 0 - # We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant - # changes in PRs and avoid nitpicking. - exclude-use-default: false - # List of regexps of issue texts to exclude, empty list by default. - exclude: - - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) - - "exported: (func|type) name will be used as (.+) by other packages, and that stutters; consider calling this (.+)" - - (G104|G107|G404|G505|ST1000) - - "G108: Profiling endpoint is automatically exposed on /debug/pprof" - # Exclude noctx error for calling http.Get directly. - # See https://pkg.go.dev/github.com/sonatard/noctx#readme-how-to-fix for reasons it breaks and ways to fix it. - # This exclusion should be removed if the decision is made to fix the error. - - "net/http.Get must not be called" - exclude-rules: - # Exclude revive's exported for certain packages and code, e.g. tests and fake. - - linters: - - revive - text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported" - - linters: - - errcheck - text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked - # Exclude some packages or code to require comments, for example test code, or fake clients. - - linters: - - revive - text: exported (method|function|type|const) (.+) should have comment or be unexported - source: (func|type).*Fake.* - - linters: - - revive - text: exported (method|function|type|const) (.+) should have comment or be unexported - path: fake_\.go - - linters: - - revive - text: exported (method|function|type|const) (.+) should have comment or be unexported - path: .*test/(providers|framework|e2e).*.go - - linters: - - errcheck - text: Error return value is not checked - path: _test\.go - - linters: - - errcheck - text: Error return value of (.+) is not checked - path: _test\.go - - linters: - - gosec - text: "G108: Profiling endpoint is automatically exposed on /debug/pprof" - - linters: - - godot - text: "Comment should end in a period" - path: "(.*)/(v1beta1|v1beta2)/(.*)types.go" - - linters: - - errcheck - text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked - # With Go 1.16, the new embed directive can be used with an un-named import, - # revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us. - # This directive allows the embed package to be imported with an underscore everywhere. - - linters: - - revive - source: _ "embed" - # This directive allows the variable in defaults.go files to have underscore - - linters: - - revive - text: "var-naming: don't use underscores in Go names; func (.+) should be (.+)" - path: .*/defaults.go - # These directives allow the mock and gc packages to be imported with an underscore everywhere. - - linters: - - revive - text: "var-naming: don't use an underscore in package name" - path: .*/.*(mock|gc_).*/.+\.go - # Disable unparam "always receives" which might not be really - # useful when building libraries. - - linters: - - unparam - text: always receives - # Dot imports for gomega or ginkgo are allowed - # within test files. - - path: _test\.go - text: should not use dot imports - - path: (framework|e2e)/.*.go - text: should not use dot imports - - path: _test\.go - text: cyclomatic complexity - - linters: - - unparam - text: (.+) - (`t`|`g`) is unused - - path: _test\.go - text: cyclomatic complexity - # Append should be able to assign to a different var/slice. - - linters: - - gocritic - text: "appendAssign: append result not assigned to the same slice" - +version: "2" run: - timeout: 10m build-tags: - tools - e2e - skip-files: - - "zz_generated.*\\.go$" - - ".*conversion.*\\.go$" - skip-dirs: - - third_party allow-parallel-runners: true +linters: + default: none + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - containedctx + - copyloopvar + - dogsled + - dupword + - durationcheck + - errcheck + - errchkjson + - ginkgolinter + - goconst + - gocritic + - godot + - goprintffuncname + - gosec + - govet + - iface + - importas + - ineffassign + - intrange + - loggercheck + - misspell + - nakedret + - nilerr + - noctx + - nolintlint + - nosprintfhostport + - prealloc + - predeclared + - revive + - rowserrcheck + - staticcheck + - thelper + - unconvert + - unparam + - unused + - usestdlibvars + - whitespace + settings: + depguard: + rules: + main: + deny: + - pkg: io/ioutil + desc: ioutil is deprecated starting with Go 1.16 + ginkgolinter: + suppress-len-assertion: true + suppress-nil-assertion: false + suppress-err-assertion: true + forbid-focus-container: true + gocritic: + disabled-checks: + - appendAssign + - dupImport + - evalOrder + - ifElseChain + - octalLiteral + - regexpSimplify + - sloppyReassign + - truncateCmp + - typeDefFirst + - unnamedResult + - unnecessaryDefer + - whyNoLint + - wrapperFunc + - rangeValCopy + - hugeParam + - filepathJoin + - emptyStringTest + enabled-tags: + - diagnostic + - experimental + - performance + godot: + scope: toplevel + exclude: + - ^ \+.* + - ^ ANCHOR.* + gosec: + excludes: + - G307 + - G108 + importas: + alias: + - pkg: k8s.io/api/core/v1 + alias: corev1 + - pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1 + alias: apiextensionsv1 + - pkg: k8s.io/apimachinery/pkg/apis/meta/v1 + alias: metav1 + - pkg: k8s.io/apimachinery/pkg/util/errors + alias: kerrors + - pkg: sigs.k8s.io/controller-runtime/pkg/conversion + alias: ctrlconversion + - pkg: sigs.k8s.io/cluster-api/util/conversion + alias: utilconversion + - pkg: k8s.io/apimachinery/pkg/conversion + alias: apiconversion + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2 + alias: infrav1 + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta1 + alias: infrav1beta1 + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta1 + alias: expinfrav1beta1 + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2 + alias: expinfrav1 + - pkg: k8s.io/client-go/kubernetes/scheme + alias: cgscheme + - pkg: k8s.io/client-go/tools/record + alias: cgrecord + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta1 + alias: eksbootstrapv1beta1 + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2 + alias: eksbootstrapv1 + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta1 + alias: ekscontrolplanev1beta1 + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2 + alias: ekscontrolplanev1 + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/controllers + alias: eksbootstrapcontrollers + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/controllers + alias: ekscontrolplanecontrollers + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/exp/controllers + alias: expcontrollers + - pkg: k8s.io/apimachinery/pkg/runtime + alias: runtime + - pkg: k8s.io/apimachinery/pkg/runtime/serializer + alias: runtimeserializer + - pkg: k8s.io/apimachinery/pkg/runtime/serializer/yaml + alias: yamlserializer + - pkg: sigs.k8s.io/cluster-api/api/v1beta1 + alias: clusterv1 + - pkg: sigs.k8s.io/cluster-api/util/defaulting + alias: utildefaulting + - pkg: sigs.k8s.io/controller-runtime + alias: ctrl + - pkg: k8s.io/apimachinery/pkg/api/errors + alias: apierrors + - pkg: sigs.k8s.io/controller-runtime/pkg/log + alias: logf + - pkg: github.com/google/gofuzz + alias: fuzz + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/logs + alias: awslogs + - pkg: sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/metrics + alias: awsmetrics + - pkg: sigs.k8s.io/cluster-api/errors + alias: capierrors + - pkg: github.com/aws/aws-sdk-go/aws/client + alias: awsclient + - pkg: github.com/aws/amazon-vpc-cni-k8s/pkg/apis/crd/v1alpha1 + alias: amazoncni + - pkg: github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi + alias: rgapi + - pkg: crypto/rand + alias: crand + - pkg: sigs.k8s.io/controller-runtime/pkg/client + alias: crclient + - pkg: k8s.io/apimachinery/pkg/types + alias: apimachinerytypes + - pkg: sigs.k8s.io/cluster-api/exp/api/v1beta1 + alias: expclusterv1 + no-unaliased: false + nolintlint: + require-specific: true + allow-unused: false + revive: + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: unreachable-code + - name: redefines-builtin-id + - name: bool-literal-in-expr + - name: constant-logical-expr + exclusions: + generated: lax + rules: + - linters: + - errcheck + text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv|outputPrinter.Print|printer.Print). is not checked + # - linters: + # - errcheck + # text: Error return value of `outputPrinter.Print` is not checked + - linters: + - gosec + text: 'G103: Use of unsafe calls should be audited' + path: .*(api|types|test)\/.*\/.*conversion.*\.go$ + - linters: + - staticcheck + text: 'QF1008: could remove embedded field .*' + # TODO: change to use time.Time.Equal + - linters: + - staticcheck + text: 'QF1009: probably want to use time.Time.Equal instead' + - linters: + - revive + # Ignoring stylistic checks for generated code + path: .*(api|types|test)\/.*\/.*conversion.*\.go$ + # Exported function and methods should have comments. This warns on undocumented exported functions and methods. + text: exported (method|function|type|const) (.+) should have comment or be unexported + - linters: + - revive + # Ignoring stylistic checks for generated code + path: .*(api|types)\/.*\/.*conversion.*\.go$ + # By convention, receiver names in a method should reflect their identity. + text: 'receiver-naming: receiver name (.+) should be consistent with previous receiver name (.+)' + - linters: + - revive + # Ignoring stylistic checks for generated code + path: .*(api|types|test)\/.*\/.*conversion.*\.go$ + # Checking if an error is nil to just after return the error or nil is redundant + text: 'if-return: redundant if ...; err != nil check, just return error instead' + - linters: + - revive + text: 'exported: exported method .*\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported' + - linters: + - errcheck + text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked + - linters: + - revive + text: exported (method|function|type|const) (.+) should have comment or be unexported + source: (func|type).*Fake.* + - linters: + - revive + path: fake_\.go + text: exported (method|function|type|const) (.+) should have comment or be unexported + - linters: + - revive + path: .*test/(providers|framework|e2e).*.go + text: exported (method|function|type|const) (.+) should have comment or be unexported + - linters: + - errcheck + path: _test\.go + text: Error return value is not checked + - linters: + - errcheck + path: _test\.go + text: Error return value of (.+) is not checked + - linters: + - gosec + text: 'G108: Profiling endpoint is automatically exposed on /debug/pprof' + - linters: + - godot + path: (.*)/(v1beta1|v1beta2)/(.*)types.go + text: Comment should end in a period + - linters: + - errcheck + text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked + - linters: + - revive + source: _ "embed" + - linters: + - revive + path: .*/defaults.go + text: 'var-naming: don''t use underscores in Go names; func (.+) should be (.+)' + - linters: + - revive + path: .*/.*(mock|gc_).*/.+\.go + text: 'var-naming: don''t use an underscore in package name' + - linters: + - revive + # Ignoring stylistic checks for generated code + path: .*(api|types|test)\/.*\/.*conversion.*\.go$ + # This rule warns when initialism, variable or package naming conventions are not followed. + text: 'var-naming: don''t use underscores in Go names' + - linters: + - unparam + text: always receives + - path: _test\.go + text: should not use dot imports + - path: (framework|e2e)/.*.go + text: should not use dot imports + - path: _test\.go + text: cyclomatic complexity + - linters: + - unparam + text: (.+) - g is unused + - path: _test\.go + text: cyclomatic complexity + - linters: + - gocritic + text: 'appendAssign: append result not assigned to the same slice' + - path: (.+)\.go$ + text: (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) + - path: (.+)\.go$ + text: 'exported: (func|type) name will be used as (.+) by other packages, and that stutters; consider calling this (.+)' + - path: (.+)\.go$ + text: (G104|G107|G404|G505|ST1000) + - path: (.+)\.go$ + text: 'G108: Profiling endpoint is automatically exposed on /debug/pprof' + - path: (.+)\.go$ + text: net/http.Get must not be called + - linters: + - goconst + path: (.+)_test\.go + paths: + - third_party$ + - builtin$ + - examples$ +issues: + max-issues-per-linter: 0 + max-same-issues: 0 +formatters: + enable: + - gci + - gofmt + - goimports + settings: + gci: + sections: + - standard + - default + - prefix(sigs.k8s.io/cluster-api) + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index d857badbcd..259626e8d4 100644 --- a/Makefile +++ b/Makefile @@ -63,10 +63,10 @@ GOJQ := $(TOOLS_BIN_DIR)/gojq GOLANGCI_LINT_BIN := golangci-lint GOLANGCI_LINT_VER := $(shell cat .github/workflows/pr-golangci-lint.yaml | grep [[:space:]]version: | sed 's/.*version: //') GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)) -GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint -GOLANGCI_LINT_KAL_BIN := golangci-lint-kal -GOLANGCI_LINT_KAL_VER := $(shell cat ./hack/tools/.custom-gcl.yaml | grep name: | sed 's/name: golangci-lint-kal-//') -GOLANGCI_LINT_KAL := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_KAL_BIN)-$(GOLANGCI_LINT_KAL_VER)) +GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint +GOLANGCI_LINT_KAL_BIN := golangci-lint-kube-api-linter +GOLANGCI_LINT_KAL_VER := $(shell cat ./hack/tools/.custom-gcl.yaml | grep version: | sed 's/version: //') +GOLANGCI_LINT_KAL := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_KAL_BIN)) KIND := $(TOOLS_BIN_DIR)/kind KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize MOCKGEN := $(TOOLS_BIN_DIR)/mockgen @@ -303,9 +303,8 @@ $(GOLANGCI_LINT_KAL): $(GOLANGCI_LINT) # Build golangci-lint-kal from custom con .PHONY: lint lint: $(GOLANGCI_LINT) $(GOLANGCI_LINT_KAL) ## Lint codebase - $(GOLANGCI_LINT) run -v --fast=false $(GOLANGCI_LINT_EXTRA_ARGS) - $(GOLANGCI_LINT_KAL) run -v --config $(REPO_ROOT)/.golangci-kal.yml $(GOLANGCI_LINT_EXTRA_ARGS) - + $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) + .PHONY: lint-fix lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint diff --git a/api/v1beta1/awscluster_conversion.go b/api/v1beta1/awscluster_conversion.go index 9bdaf07261..1ebb979848 100644 --- a/api/v1beta1/awscluster_conversion.go +++ b/api/v1beta1/awscluster_conversion.go @@ -18,27 +18,28 @@ package v1beta1 import ( apiconversion "k8s.io/apimachinery/pkg/conversion" - infrav2 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" - utilconversion "sigs.k8s.io/cluster-api/util/conversion" "sigs.k8s.io/controller-runtime/pkg/conversion" + + infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" + utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) // ConvertTo converts the v1beta1 AWSCluster receiver to a v1beta2 AWSCluster. func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav2.AWSCluster) + dst := dstRaw.(*infrav1.AWSCluster) if err := Convert_v1beta1_AWSCluster_To_v1beta2_AWSCluster(src, dst, nil); err != nil { return err } // Manually restore data. - restored := &infrav2.AWSCluster{} + restored := &infrav1.AWSCluster{} if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { return err } if restored.Spec.ControlPlaneLoadBalancer != nil { if dst.Spec.ControlPlaneLoadBalancer == nil { - dst.Spec.ControlPlaneLoadBalancer = &infrav2.AWSLoadBalancerSpec{} + dst.Spec.ControlPlaneLoadBalancer = &infrav1.AWSLoadBalancerSpec{} } restoreControlPlaneLoadBalancer(restored.Spec.ControlPlaneLoadBalancer, dst.Spec.ControlPlaneLoadBalancer) } @@ -46,7 +47,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error { if restored.Spec.SecondaryControlPlaneLoadBalancer != nil { if dst.Spec.SecondaryControlPlaneLoadBalancer == nil { - dst.Spec.SecondaryControlPlaneLoadBalancer = &infrav2.AWSLoadBalancerSpec{} + dst.Spec.SecondaryControlPlaneLoadBalancer = &infrav1.AWSLoadBalancerSpec{} } restoreControlPlaneLoadBalancer(restored.Spec.SecondaryControlPlaneLoadBalancer, dst.Spec.SecondaryControlPlaneLoadBalancer) } @@ -72,7 +73,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error { if restored.Spec.NetworkSpec.VPC.IPAMPool != nil { if dst.Spec.NetworkSpec.VPC.IPAMPool == nil { - dst.Spec.NetworkSpec.VPC.IPAMPool = &infrav2.IPAMPool{} + dst.Spec.NetworkSpec.VPC.IPAMPool = &infrav1.IPAMPool{} } restoreIPAMPool(restored.Spec.NetworkSpec.VPC.IPAMPool, dst.Spec.NetworkSpec.VPC.IPAMPool) @@ -80,7 +81,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error { if restored.Spec.NetworkSpec.VPC.IsIPv6Enabled() && restored.Spec.NetworkSpec.VPC.IPv6.IPAMPool != nil { if dst.Spec.NetworkSpec.VPC.IPv6.IPAMPool == nil { - dst.Spec.NetworkSpec.VPC.IPv6.IPAMPool = &infrav2.IPAMPool{} + dst.Spec.NetworkSpec.VPC.IPv6.IPAMPool = &infrav1.IPAMPool{} } restoreIPAMPool(restored.Spec.NetworkSpec.VPC.IPv6.IPAMPool, dst.Spec.NetworkSpec.VPC.IPv6.IPAMPool) @@ -92,7 +93,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error { if restored.Spec.NetworkSpec.VPC.IPAMPool != nil { if dst.Spec.NetworkSpec.VPC.IPAMPool == nil { - dst.Spec.NetworkSpec.VPC.IPAMPool = &infrav2.IPAMPool{} + dst.Spec.NetworkSpec.VPC.IPAMPool = &infrav1.IPAMPool{} } restoreIPAMPool(restored.Spec.NetworkSpec.VPC.IPAMPool, dst.Spec.NetworkSpec.VPC.IPAMPool) @@ -100,7 +101,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error { if restored.Spec.NetworkSpec.VPC.IsIPv6Enabled() && restored.Spec.NetworkSpec.VPC.IPv6.IPAMPool != nil { if dst.Spec.NetworkSpec.VPC.IPv6.IPAMPool == nil { - dst.Spec.NetworkSpec.VPC.IPv6.IPAMPool = &infrav2.IPAMPool{} + dst.Spec.NetworkSpec.VPC.IPv6.IPAMPool = &infrav1.IPAMPool{} } restoreIPAMPool(restored.Spec.NetworkSpec.VPC.IPv6.IPAMPool, dst.Spec.NetworkSpec.VPC.IPv6.IPAMPool) @@ -114,7 +115,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error { if restored.Spec.NetworkSpec.VPC.ElasticIPPool != nil { if dst.Spec.NetworkSpec.VPC.ElasticIPPool == nil { - dst.Spec.NetworkSpec.VPC.ElasticIPPool = &infrav2.ElasticIPPool{} + dst.Spec.NetworkSpec.VPC.ElasticIPPool = &infrav1.ElasticIPPool{} } if restored.Spec.NetworkSpec.VPC.ElasticIPPool.PublicIpv4Pool != nil { dst.Spec.NetworkSpec.VPC.ElasticIPPool.PublicIpv4Pool = restored.Spec.NetworkSpec.VPC.ElasticIPPool.PublicIpv4Pool @@ -147,7 +148,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error { // restoreControlPlaneLoadBalancerStatus manually restores the control plane loadbalancer status data. // Assumes restored and dst are non-nil. -func restoreControlPlaneLoadBalancerStatus(restored, dst *infrav2.LoadBalancer) { +func restoreControlPlaneLoadBalancerStatus(restored, dst *infrav1.LoadBalancer) { dst.ARN = restored.ARN dst.LoadBalancerType = restored.LoadBalancerType dst.ELBAttributes = restored.ELBAttributes @@ -166,7 +167,7 @@ func restoreControlPlaneLoadBalancerStatus(restored, dst *infrav2.LoadBalancer) // restoreIPAMPool manually restores the ipam pool data. // Assumes restored and dst are non-nil. -func restoreIPAMPool(restored, dst *infrav2.IPAMPool) { +func restoreIPAMPool(restored, dst *infrav1.IPAMPool) { dst.ID = restored.ID dst.Name = restored.Name dst.NetmaskLength = restored.NetmaskLength @@ -174,7 +175,7 @@ func restoreIPAMPool(restored, dst *infrav2.IPAMPool) { // restoreControlPlaneLoadBalancer manually restores the control plane loadbalancer data. // Assumes restored and dst are non-nil. -func restoreControlPlaneLoadBalancer(restored, dst *infrav2.AWSLoadBalancerSpec) { +func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec) { dst.Name = restored.Name dst.HealthCheckProtocol = restored.HealthCheckProtocol dst.HealthCheck = restored.HealthCheck @@ -191,7 +192,7 @@ func restoreControlPlaneLoadBalancer(restored, dst *infrav2.AWSLoadBalancerSpec) // ConvertFrom converts the v1beta1 AWSCluster receiver to a v1beta1 AWSCluster. func (r *AWSCluster) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav2.AWSCluster) + src := srcRaw.(*infrav1.AWSCluster) if err := Convert_v1beta2_AWSCluster_To_v1beta1_AWSCluster(src, r, nil); err != nil { return err @@ -207,18 +208,18 @@ func (r *AWSCluster) ConvertFrom(srcRaw conversion.Hub) error { // ConvertTo converts the v1beta1 AWSClusterList receiver to a v1beta2 AWSClusterList. func (src *AWSClusterList) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav2.AWSClusterList) + dst := dstRaw.(*infrav1.AWSClusterList) return Convert_v1beta1_AWSClusterList_To_v1beta2_AWSClusterList(src, dst, nil) } // ConvertFrom converts the v1beta2 AWSClusterList receiver to a v1beta1 AWSClusterList. func (r *AWSClusterList) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav2.AWSClusterList) + src := srcRaw.(*infrav1.AWSClusterList) return Convert_v1beta2_AWSClusterList_To_v1beta1_AWSClusterList(src, r, nil) } -func Convert_v1beta2_SubnetSpec_To_v1beta1_SubnetSpec(in *infrav2.SubnetSpec, out *SubnetSpec, s apiconversion.Scope) error { +func Convert_v1beta2_SubnetSpec_To_v1beta1_SubnetSpec(in *infrav1.SubnetSpec, out *SubnetSpec, s apiconversion.Scope) error { return autoConvert_v1beta2_SubnetSpec_To_v1beta1_SubnetSpec(in, out, s) } diff --git a/api/v1beta1/awsclustertemplate_conversion.go b/api/v1beta1/awsclustertemplate_conversion.go index 4790fa7ee4..eeb4a4318e 100644 --- a/api/v1beta1/awsclustertemplate_conversion.go +++ b/api/v1beta1/awsclustertemplate_conversion.go @@ -17,9 +17,10 @@ limitations under the License. package v1beta1 import ( + "sigs.k8s.io/controller-runtime/pkg/conversion" + infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" utilconversion "sigs.k8s.io/cluster-api/util/conversion" - "sigs.k8s.io/controller-runtime/pkg/conversion" ) // ConvertTo converts the v1beta1 AWSClusterTemplate receiver to a v1beta2 AWSClusterTemplate. diff --git a/api/v1beta1/awsidentity_conversion.go b/api/v1beta1/awsidentity_conversion.go index a6c6dcb855..47e4ea1e59 100644 --- a/api/v1beta1/awsidentity_conversion.go +++ b/api/v1beta1/awsidentity_conversion.go @@ -17,8 +17,9 @@ limitations under the License. package v1beta1 import ( - infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" "sigs.k8s.io/controller-runtime/pkg/conversion" + + infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" ) // ConvertTo converts the v1beta1 AWSClusterControllerIdentity receiver to a v1beta2 AWSClusterControllerIdentity. diff --git a/api/v1beta1/awsmachine_conversion.go b/api/v1beta1/awsmachine_conversion.go index c5ac50ade1..5f44ccbecd 100644 --- a/api/v1beta1/awsmachine_conversion.go +++ b/api/v1beta1/awsmachine_conversion.go @@ -17,9 +17,10 @@ limitations under the License. package v1beta1 import ( + "sigs.k8s.io/controller-runtime/pkg/conversion" + infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" utilconversion "sigs.k8s.io/cluster-api/util/conversion" - "sigs.k8s.io/controller-runtime/pkg/conversion" ) // ConvertTo converts the v1beta1 AWSMachine receiver to a v1beta2 AWSMachine. diff --git a/api/v1beta1/conversion.go b/api/v1beta1/conversion.go index 2b124f027a..6247cfeab1 100644 --- a/api/v1beta1/conversion.go +++ b/api/v1beta1/conversion.go @@ -20,6 +20,7 @@ import ( "unsafe" "k8s.io/apimachinery/pkg/conversion" + "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" ) diff --git a/api/v1beta1/conversion_test.go b/api/v1beta1/conversion_test.go index 24aa530ac2..c0d261f219 100644 --- a/api/v1beta1/conversion_test.go +++ b/api/v1beta1/conversion_test.go @@ -24,6 +24,7 @@ import ( "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime" runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" + "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) diff --git a/bootstrap/eks/api/v1beta1/conversion.go b/bootstrap/eks/api/v1beta1/conversion.go index 48762a5b84..9fde9c37eb 100644 --- a/bootstrap/eks/api/v1beta1/conversion.go +++ b/bootstrap/eks/api/v1beta1/conversion.go @@ -18,9 +18,10 @@ package v1beta1 import ( apiconversion "k8s.io/apimachinery/pkg/conversion" + "sigs.k8s.io/controller-runtime/pkg/conversion" + "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2" utilconversion "sigs.k8s.io/cluster-api/util/conversion" - "sigs.k8s.io/controller-runtime/pkg/conversion" ) // ConvertTo converts the v1beta1 EKSConfig receiver to a v1beta2 EKSConfig. diff --git a/bootstrap/eks/api/v1beta1/conversion_test.go b/bootstrap/eks/api/v1beta1/conversion_test.go index 47dcb9736d..6970379a4e 100644 --- a/bootstrap/eks/api/v1beta1/conversion_test.go +++ b/bootstrap/eks/api/v1beta1/conversion_test.go @@ -21,7 +21,8 @@ import ( . "github.com/onsi/gomega" runtime "k8s.io/apimachinery/pkg/runtime" - v1beta2 "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2" + + eksbootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2" utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) @@ -29,17 +30,17 @@ func TestFuzzyConversion(t *testing.T) { g := NewWithT(t) scheme := runtime.NewScheme() g.Expect(AddToScheme(scheme)).To(Succeed()) - g.Expect(v1beta2.AddToScheme(scheme)).To(Succeed()) + g.Expect(eksbootstrapv1.AddToScheme(scheme)).To(Succeed()) t.Run("for EKSConfig", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Scheme: scheme, - Hub: &v1beta2.EKSConfig{}, + Hub: &eksbootstrapv1.EKSConfig{}, Spoke: &EKSConfig{}, })) t.Run("for EKSConfigTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Scheme: scheme, - Hub: &v1beta2.EKSConfigTemplate{}, + Hub: &eksbootstrapv1.EKSConfigTemplate{}, Spoke: &EKSConfigTemplate{}, })) } diff --git a/cmd/clusterawsadm/api/bootstrap/v1alpha1/conversion.go b/cmd/clusterawsadm/api/bootstrap/v1alpha1/conversion.go index 6409805b64..4a437658f5 100644 --- a/cmd/clusterawsadm/api/bootstrap/v1alpha1/conversion.go +++ b/cmd/clusterawsadm/api/bootstrap/v1alpha1/conversion.go @@ -17,15 +17,16 @@ limitations under the License. package v1alpha1 import ( - conversion "k8s.io/apimachinery/pkg/conversion" + apiconversion "k8s.io/apimachinery/pkg/conversion" + "sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/api/bootstrap/v1beta1" ) // Convert_v1beta1_AWSIAMConfigurationSpec_To_v1alpha1_AWSIAMConfigurationSpec is an autogenerated conversion function. -func Convert_v1beta1_AWSIAMConfigurationSpec_To_v1alpha1_AWSIAMConfigurationSpec(in *v1beta1.AWSIAMConfigurationSpec, out *AWSIAMConfigurationSpec, s conversion.Scope) error { +func Convert_v1beta1_AWSIAMConfigurationSpec_To_v1alpha1_AWSIAMConfigurationSpec(in *v1beta1.AWSIAMConfigurationSpec, out *AWSIAMConfigurationSpec, s apiconversion.Scope) error { return autoConvert_v1beta1_AWSIAMConfigurationSpec_To_v1alpha1_AWSIAMConfigurationSpec(in, out, s) } -func Convert_v1beta1_AWSIAMRoleSpec_To_v1alpha1_AWSIAMRoleSpec(in *v1beta1.AWSIAMRoleSpec, out *AWSIAMRoleSpec, s conversion.Scope) error { +func Convert_v1beta1_AWSIAMRoleSpec_To_v1alpha1_AWSIAMRoleSpec(in *v1beta1.AWSIAMRoleSpec, out *AWSIAMRoleSpec, s apiconversion.Scope) error { return autoConvert_v1beta1_AWSIAMRoleSpec_To_v1alpha1_AWSIAMRoleSpec(in, out, s) } diff --git a/controlplane/eks/api/v1beta1/conversion.go b/controlplane/eks/api/v1beta1/conversion.go index d87cef2103..9a0c2720c6 100644 --- a/controlplane/eks/api/v1beta1/conversion.go +++ b/controlplane/eks/api/v1beta1/conversion.go @@ -18,12 +18,12 @@ package v1beta1 import ( apiconversion "k8s.io/apimachinery/pkg/conversion" + "sigs.k8s.io/controller-runtime/pkg/conversion" + infrav1beta1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta1" - infrav1beta2 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" + infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2" - v1beta2 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2" utilconversion "sigs.k8s.io/cluster-api/util/conversion" - "sigs.k8s.io/controller-runtime/pkg/conversion" ) // ConvertTo converts the v1beta1 AWSManagedControlPlane receiver to a v1beta2 AWSManagedControlPlane. @@ -80,32 +80,32 @@ func (r *AWSManagedControlPlaneList) ConvertFrom(srcRaw conversion.Hub) error { } // Convert_v1beta1_NetworkSpec_To_v1beta2_NetworkSpec is a conversion function. -func Convert_v1beta1_NetworkSpec_To_v1beta2_NetworkSpec(in *infrav1beta1.NetworkSpec, out *infrav1beta2.NetworkSpec, s apiconversion.Scope) error { +func Convert_v1beta1_NetworkSpec_To_v1beta2_NetworkSpec(in *infrav1beta1.NetworkSpec, out *infrav1.NetworkSpec, s apiconversion.Scope) error { return infrav1beta1.Convert_v1beta1_NetworkSpec_To_v1beta2_NetworkSpec(in, out, s) } // Convert_v1beta2_NetworkSpec_To_v1beta1_NetworkSpec is a generated conversion function. -func Convert_v1beta2_NetworkSpec_To_v1beta1_NetworkSpec(in *infrav1beta2.NetworkSpec, out *infrav1beta1.NetworkSpec, s apiconversion.Scope) error { +func Convert_v1beta2_NetworkSpec_To_v1beta1_NetworkSpec(in *infrav1.NetworkSpec, out *infrav1beta1.NetworkSpec, s apiconversion.Scope) error { return infrav1beta1.Convert_v1beta2_NetworkSpec_To_v1beta1_NetworkSpec(in, out, s) } // Convert_v1beta1_NetworkStatus_To_v1beta2_NetworkStatus is a conversion function. -func Convert_v1beta1_NetworkStatus_To_v1beta2_NetworkStatus(in *infrav1beta1.NetworkStatus, out *infrav1beta2.NetworkStatus, s apiconversion.Scope) error { +func Convert_v1beta1_NetworkStatus_To_v1beta2_NetworkStatus(in *infrav1beta1.NetworkStatus, out *infrav1.NetworkStatus, s apiconversion.Scope) error { return infrav1beta1.Convert_v1beta1_NetworkStatus_To_v1beta2_NetworkStatus(in, out, s) } // Convert_v1beta2_NetworkStatus_To_v1beta1_NetworkStatus is a conversion function. -func Convert_v1beta2_NetworkStatus_To_v1beta1_NetworkStatus(in *infrav1beta2.NetworkStatus, out *infrav1beta1.NetworkStatus, s apiconversion.Scope) error { +func Convert_v1beta2_NetworkStatus_To_v1beta1_NetworkStatus(in *infrav1.NetworkStatus, out *infrav1beta1.NetworkStatus, s apiconversion.Scope) error { return infrav1beta1.Convert_v1beta2_NetworkStatus_To_v1beta1_NetworkStatus(in, out, s) } // Convert_v1beta1_Bastion_To_v1beta2_Bastion is a generated conversion function. -func Convert_v1beta1_Bastion_To_v1beta2_Bastion(in *infrav1beta1.Bastion, out *infrav1beta2.Bastion, s apiconversion.Scope) error { +func Convert_v1beta1_Bastion_To_v1beta2_Bastion(in *infrav1beta1.Bastion, out *infrav1.Bastion, s apiconversion.Scope) error { return infrav1beta1.Convert_v1beta1_Bastion_To_v1beta2_Bastion(in, out, s) } // Convert_v1beta2_Bastion_To_v1beta1_Bastion is a generated conversion function. -func Convert_v1beta2_Bastion_To_v1beta1_Bastion(in *infrav1beta2.Bastion, out *infrav1beta1.Bastion, s apiconversion.Scope) error { +func Convert_v1beta2_Bastion_To_v1beta1_Bastion(in *infrav1.Bastion, out *infrav1beta1.Bastion, s apiconversion.Scope) error { return infrav1beta1.Convert_v1beta2_Bastion_To_v1beta1_Bastion(in, out, s) } @@ -117,12 +117,12 @@ func Convert_v1beta2_VpcCni_To_v1beta1_VpcCni(in *ekscontrolplanev1.VpcCni, out return autoConvert_v1beta2_VpcCni_To_v1beta1_VpcCni(in, out, s) } -// Convert_v1beta2_AWSManagedControlPlaneSpec_To_v1beta1_AWSManagedControlPlaneSpec is a generated conversion function +// Convert_v1beta2_AWSManagedControlPlaneSpec_To_v1beta1_AWSManagedControlPlaneSpec is a generated conversion function. func Convert_v1beta2_AWSManagedControlPlaneSpec_To_v1beta1_AWSManagedControlPlaneSpec(in *ekscontrolplanev1.AWSManagedControlPlaneSpec, out *AWSManagedControlPlaneSpec, scope apiconversion.Scope) error { return autoConvert_v1beta2_AWSManagedControlPlaneSpec_To_v1beta1_AWSManagedControlPlaneSpec(in, out, scope) } // Convert_v1beta2_AWSManagedControlPlaneStatus_To_v1beta1_AWSManagedControlPlaneStatus is an autogenerated conversion function. -func Convert_v1beta2_AWSManagedControlPlaneStatus_To_v1beta1_AWSManagedControlPlaneStatus(in *v1beta2.AWSManagedControlPlaneStatus, out *AWSManagedControlPlaneStatus, s apiconversion.Scope) error { +func Convert_v1beta2_AWSManagedControlPlaneStatus_To_v1beta1_AWSManagedControlPlaneStatus(in *ekscontrolplanev1.AWSManagedControlPlaneStatus, out *AWSManagedControlPlaneStatus, s apiconversion.Scope) error { return autoConvert_v1beta2_AWSManagedControlPlaneStatus_To_v1beta1_AWSManagedControlPlaneStatus(in, out, s) } diff --git a/controlplane/eks/api/v1beta1/conversion_test.go b/controlplane/eks/api/v1beta1/conversion_test.go index b7b360d1d1..32b32fc3e0 100644 --- a/controlplane/eks/api/v1beta1/conversion_test.go +++ b/controlplane/eks/api/v1beta1/conversion_test.go @@ -24,6 +24,7 @@ import ( "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime" runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" + "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2" utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) diff --git a/exp/api/v1beta1/conversion.go b/exp/api/v1beta1/conversion.go index e69c17691d..49277c73a7 100644 --- a/exp/api/v1beta1/conversion.go +++ b/exp/api/v1beta1/conversion.go @@ -18,23 +18,23 @@ package v1beta1 import ( apiconversion "k8s.io/apimachinery/pkg/conversion" - utilconversion "sigs.k8s.io/cluster-api/util/conversion" "sigs.k8s.io/controller-runtime/pkg/conversion" infrav1beta1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta1" infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" - infrav1exp "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2" + expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2" + utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) // ConvertTo converts the v1beta1 AWSMachinePool receiver to a v1beta2 AWSMachinePool. func (src *AWSMachinePool) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav1exp.AWSMachinePool) + dst := dstRaw.(*expinfrav1.AWSMachinePool) if err := Convert_v1beta1_AWSMachinePool_To_v1beta2_AWSMachinePool(src, dst, nil); err != nil { return err } // Manually restore data. - restored := &infrav1exp.AWSMachinePool{} + restored := &expinfrav1.AWSMachinePool{} if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { return err } @@ -76,7 +76,7 @@ func (src *AWSMachinePool) ConvertTo(dstRaw conversion.Hub) error { // ConvertFrom converts the v1beta2 AWSMachinePool receiver to v1beta1 AWSMachinePool. func (dst *AWSMachinePool) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav1exp.AWSMachinePool) + src := srcRaw.(*expinfrav1.AWSMachinePool) if err := Convert_v1beta2_AWSMachinePool_To_v1beta1_AWSMachinePool(src, dst, nil); err != nil { return err @@ -87,24 +87,24 @@ func (dst *AWSMachinePool) ConvertFrom(srcRaw conversion.Hub) error { // ConvertTo converts the v1beta1 AWSMachinePoolList receiver to a v1beta2 AWSMachinePoolList. func (src *AWSMachinePoolList) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav1exp.AWSMachinePoolList) + dst := dstRaw.(*expinfrav1.AWSMachinePoolList) return Convert_v1beta1_AWSMachinePoolList_To_v1beta2_AWSMachinePoolList(src, dst, nil) } // ConvertFrom converts the v1beta2 AWSMachinePoolList receiver to v1beta1 AWSMachinePoolList. func (r *AWSMachinePoolList) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav1exp.AWSMachinePoolList) + src := srcRaw.(*expinfrav1.AWSMachinePoolList) return Convert_v1beta2_AWSMachinePoolList_To_v1beta1_AWSMachinePoolList(src, r, nil) } // ConvertTo converts the v1beta1 AWSManagedMachinePool receiver to a v1beta2 AWSManagedMachinePool. func (src *AWSManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav1exp.AWSManagedMachinePool) + dst := dstRaw.(*expinfrav1.AWSManagedMachinePool) if err := Convert_v1beta1_AWSManagedMachinePool_To_v1beta2_AWSManagedMachinePool(src, dst, nil); err != nil { return err } // Manually restore data. - restored := &infrav1exp.AWSManagedMachinePool{} + restored := &expinfrav1.AWSManagedMachinePool{} if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { return err } @@ -127,7 +127,6 @@ func (src *AWSManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error { if restored.Spec.AWSLaunchTemplate.MarketType != "" { dst.Spec.AWSLaunchTemplate.MarketType = restored.Spec.AWSLaunchTemplate.MarketType } - } if restored.Spec.AvailabilityZoneSubnetType != nil { dst.Spec.AvailabilityZoneSubnetType = restored.Spec.AvailabilityZoneSubnetType @@ -144,7 +143,7 @@ func (src *AWSManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error { // ConvertFrom converts the v1beta2 AWSManagedMachinePool receiver to v1beta1 AWSManagedMachinePool. func (r *AWSManagedMachinePool) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav1exp.AWSManagedMachinePool) + src := srcRaw.(*expinfrav1.AWSManagedMachinePool) if err := Convert_v1beta2_AWSManagedMachinePool_To_v1beta1_AWSManagedMachinePool(src, r, nil); err != nil { return err @@ -154,37 +153,37 @@ func (r *AWSManagedMachinePool) ConvertFrom(srcRaw conversion.Hub) error { } // Convert_v1beta2_AWSManagedMachinePoolSpec_To_v1beta1_AWSManagedMachinePoolSpec is a conversion function. -func Convert_v1beta2_AWSManagedMachinePoolSpec_To_v1beta1_AWSManagedMachinePoolSpec(in *infrav1exp.AWSManagedMachinePoolSpec, out *AWSManagedMachinePoolSpec, s apiconversion.Scope) error { +func Convert_v1beta2_AWSManagedMachinePoolSpec_To_v1beta1_AWSManagedMachinePoolSpec(in *expinfrav1.AWSManagedMachinePoolSpec, out *AWSManagedMachinePoolSpec, s apiconversion.Scope) error { return autoConvert_v1beta2_AWSManagedMachinePoolSpec_To_v1beta1_AWSManagedMachinePoolSpec(in, out, s) } -func Convert_v1beta2_AWSMachinePoolStatus_To_v1beta1_AWSMachinePoolStatus(in *infrav1exp.AWSMachinePoolStatus, out *AWSMachinePoolStatus, s apiconversion.Scope) error { +func Convert_v1beta2_AWSMachinePoolStatus_To_v1beta1_AWSMachinePoolStatus(in *expinfrav1.AWSMachinePoolStatus, out *AWSMachinePoolStatus, s apiconversion.Scope) error { return autoConvert_v1beta2_AWSMachinePoolStatus_To_v1beta1_AWSMachinePoolStatus(in, out, s) } // ConvertTo converts the v1beta1 AWSManagedMachinePoolList receiver to a v1beta2 AWSManagedMachinePoolList. func (src *AWSManagedMachinePoolList) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav1exp.AWSManagedMachinePoolList) + dst := dstRaw.(*expinfrav1.AWSManagedMachinePoolList) return Convert_v1beta1_AWSManagedMachinePoolList_To_v1beta2_AWSManagedMachinePoolList(src, dst, nil) } // ConvertFrom converts the v1beta2 AWSManagedMachinePoolList receiver to v1beta1 AWSManagedMachinePoolList. func (r *AWSManagedMachinePoolList) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav1exp.AWSManagedMachinePoolList) + src := srcRaw.(*expinfrav1.AWSManagedMachinePoolList) return Convert_v1beta2_AWSManagedMachinePoolList_To_v1beta1_AWSManagedMachinePoolList(src, r, nil) } // ConvertTo converts the v1beta1 AWSFargateProfile receiver to a v1beta2 AWSFargateProfile. func (src *AWSFargateProfile) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav1exp.AWSFargateProfile) + dst := dstRaw.(*expinfrav1.AWSFargateProfile) if err := Convert_v1beta1_AWSFargateProfile_To_v1beta2_AWSFargateProfile(src, dst, nil); err != nil { return err } // Manually restore data. - restored := &infrav1exp.AWSFargateProfile{} + restored := &expinfrav1.AWSFargateProfile{} if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { return err } @@ -197,7 +196,7 @@ func (src *AWSFargateProfile) ConvertTo(dstRaw conversion.Hub) error { // ConvertFrom converts the v1beta2 AWSFargateProfile receiver to v1beta1 AWSFargateProfile. func (r *AWSFargateProfile) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav1exp.AWSFargateProfile) + src := srcRaw.(*expinfrav1.AWSFargateProfile) if err := Convert_v1beta2_AWSFargateProfile_To_v1beta1_AWSFargateProfile(src, r, nil); err != nil { return err @@ -209,13 +208,13 @@ func (r *AWSFargateProfile) ConvertFrom(srcRaw conversion.Hub) error { // ConvertTo converts the v1beta1 AWSFargateProfileList receiver to a v1beta2 AWSFargateProfileList. func (src *AWSFargateProfileList) ConvertTo(dstRaw conversion.Hub) error { - dst := dstRaw.(*infrav1exp.AWSFargateProfileList) + dst := dstRaw.(*expinfrav1.AWSFargateProfileList) return Convert_v1beta1_AWSFargateProfileList_To_v1beta2_AWSFargateProfileList(src, dst, nil) } // ConvertFrom converts the v1beta2 AWSFargateProfileList receiver to v1beta1 AWSFargateProfileList. func (r *AWSFargateProfileList) ConvertFrom(srcRaw conversion.Hub) error { - src := srcRaw.(*infrav1exp.AWSFargateProfileList) + src := srcRaw.(*expinfrav1.AWSFargateProfileList) return Convert_v1beta2_AWSFargateProfileList_To_v1beta1_AWSFargateProfileList(src, r, nil) } @@ -241,33 +240,33 @@ func Convert_v1beta1_Instance_To_v1beta2_Instance(in *infrav1beta1.Instance, out } // Convert_v1beta2_AWSLaunchTemplate_To_v1beta1_AWSLaunchTemplate converts the v1beta2 AWSLaunchTemplate receiver to a v1beta1 AWSLaunchTemplate. -func Convert_v1beta2_AWSLaunchTemplate_To_v1beta1_AWSLaunchTemplate(in *infrav1exp.AWSLaunchTemplate, out *AWSLaunchTemplate, s apiconversion.Scope) error { +func Convert_v1beta2_AWSLaunchTemplate_To_v1beta1_AWSLaunchTemplate(in *expinfrav1.AWSLaunchTemplate, out *AWSLaunchTemplate, s apiconversion.Scope) error { return autoConvert_v1beta2_AWSLaunchTemplate_To_v1beta1_AWSLaunchTemplate(in, out, s) } -func Convert_v1beta1_AWSMachinePoolSpec_To_v1beta2_AWSMachinePoolSpec(in *AWSMachinePoolSpec, out *infrav1exp.AWSMachinePoolSpec, s apiconversion.Scope) error { +func Convert_v1beta1_AWSMachinePoolSpec_To_v1beta2_AWSMachinePoolSpec(in *AWSMachinePoolSpec, out *expinfrav1.AWSMachinePoolSpec, s apiconversion.Scope) error { return autoConvert_v1beta1_AWSMachinePoolSpec_To_v1beta2_AWSMachinePoolSpec(in, out, s) } -func Convert_v1beta2_AWSMachinePoolSpec_To_v1beta1_AWSMachinePoolSpec(in *infrav1exp.AWSMachinePoolSpec, out *AWSMachinePoolSpec, s apiconversion.Scope) error { +func Convert_v1beta2_AWSMachinePoolSpec_To_v1beta1_AWSMachinePoolSpec(in *expinfrav1.AWSMachinePoolSpec, out *AWSMachinePoolSpec, s apiconversion.Scope) error { return autoConvert_v1beta2_AWSMachinePoolSpec_To_v1beta1_AWSMachinePoolSpec(in, out, s) } -func Convert_v1beta1_AutoScalingGroup_To_v1beta2_AutoScalingGroup(in *AutoScalingGroup, out *infrav1exp.AutoScalingGroup, s apiconversion.Scope) error { +func Convert_v1beta1_AutoScalingGroup_To_v1beta2_AutoScalingGroup(in *AutoScalingGroup, out *expinfrav1.AutoScalingGroup, s apiconversion.Scope) error { return autoConvert_v1beta1_AutoScalingGroup_To_v1beta2_AutoScalingGroup(in, out, s) } -func Convert_v1beta2_AutoScalingGroup_To_v1beta1_AutoScalingGroup(in *infrav1exp.AutoScalingGroup, out *AutoScalingGroup, s apiconversion.Scope) error { +func Convert_v1beta2_AutoScalingGroup_To_v1beta1_AutoScalingGroup(in *expinfrav1.AutoScalingGroup, out *AutoScalingGroup, s apiconversion.Scope) error { // explicitly ignore CurrentlySuspended. return autoConvert_v1beta2_AutoScalingGroup_To_v1beta1_AutoScalingGroup(in, out, s) } // Convert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences converts the v1beta2 RefreshPreferences receiver to a v1beta1 RefreshPreferences. -func Convert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences(in *infrav1exp.RefreshPreferences, out *RefreshPreferences, s apiconversion.Scope) error { +func Convert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences(in *expinfrav1.RefreshPreferences, out *RefreshPreferences, s apiconversion.Scope) error { // spec.refreshPreferences.disable has been added to v1beta2. return autoConvert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences(in, out, s) } -func Convert_v1beta2_FargateProfileSpec_To_v1beta1_FargateProfileSpec(in *infrav1exp.FargateProfileSpec, out *FargateProfileSpec, s apiconversion.Scope) error { +func Convert_v1beta2_FargateProfileSpec_To_v1beta1_FargateProfileSpec(in *expinfrav1.FargateProfileSpec, out *FargateProfileSpec, s apiconversion.Scope) error { return autoConvert_v1beta2_FargateProfileSpec_To_v1beta1_FargateProfileSpec(in, out, s) } diff --git a/exp/api/v1beta1/conversion_test.go b/exp/api/v1beta1/conversion_test.go index 3cedcf3342..5992c664be 100644 --- a/exp/api/v1beta1/conversion_test.go +++ b/exp/api/v1beta1/conversion_test.go @@ -21,6 +21,7 @@ import ( . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2" utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) diff --git a/hack/tools/.custom-gcl.yaml b/hack/tools/.custom-gcl.yaml index a01eaaf9c6..5253dd8852 100644 --- a/hack/tools/.custom-gcl.yaml +++ b/hack/tools/.custom-gcl.yaml @@ -1,6 +1,6 @@ -version: v1.63.4 -name: golangci-lint-kal-v1.63.4 +version: v2.1.0 +name: golangci-lint-kube-api-linter destination: ./bin plugins: - - module: "github.com/JoelSpeed/kal" - version: v0.0.0-20250305092907-abd233a9fed8 +- module: 'sigs.k8s.io/kube-api-linter' + version: v0.0.0-20250411141643-33ef95a5ee04 diff --git a/test/e2e/shared/aws_helpers.go b/test/e2e/shared/aws_helpers.go index 72da8e9326..89ddba99e9 100644 --- a/test/e2e/shared/aws_helpers.go +++ b/test/e2e/shared/aws_helpers.go @@ -47,13 +47,9 @@ func WaitForLoadBalancerToExistForService(input WaitForLoadBalancerToExistForSer By(fmt.Sprintf("Waiting for AWS load balancer of type %s to exist for service %s/%s", input.Type, input.ServiceNamespace, input.ServiceName)) Eventually(func() bool { - arns, err := GetLoadBalancerARNs(GetLoadBalancerARNsInput{ //nolint: gosimple - AWSSession: input.AWSSession, - ServiceName: input.ServiceName, - ServiceNamespace: input.ServiceNamespace, - ClusterName: input.ClusterName, - Type: input.Type, - }) + input := GetLoadBalancerARNsInput(input) + + arns, err := GetLoadBalancerARNs(input) if err != nil { fmt.Fprintf(GinkgoWriter, "Error getting loadbalancer arns: %v\n", err) diff --git a/versions.mk b/versions.mk index e21d9fcec0..e9b940a774 100644 --- a/versions.mk +++ b/versions.mk @@ -18,6 +18,6 @@ CERT_MANAGER_VERSION := v1.16.1 CAPI_VERSION := v1.9.4 KPROMO_VERSION := v4.0.4 YQ_VERSION := v4.25.2 -GOLANGCI_LINT_VERSION := v1.53.3 +GOLANGCI_LINT_VERSION := v2.1.0 RELEASE_NOTES_VERSION := v0.16.5 GORELEASER_VERSION := v1.24.0 From fad1e81490dca4a660d3c0d45cbb605ce88efcf7 Mon Sep 17 00:00:00 2001 From: Richard Case Date: Wed, 14 May 2025 17:58:42 +0100 Subject: [PATCH 3/4] wip: add kal linter Signed-off-by: Richard Case --- .github/workflows/pr-golangci-lint.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-golangci-lint.yaml b/.github/workflows/pr-golangci-lint.yaml index 6db66a2d74..0a705b756c 100644 --- a/.github/workflows/pr-golangci-lint.yaml +++ b/.github/workflows/pr-golangci-lint.yaml @@ -17,16 +17,16 @@ jobs: working-directory: - "" steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2 - name: Calculate go version id: vars run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT - name: Set up Go - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # tag=v5.0.0 + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # tag=v5.5.0 with: go-version: ${{ steps.vars.outputs.go_version }} - name: golangci-lint - uses: golangci/golangci-lint-action@2e788936b09dd82dc280e845628a40d2ba6b204c # tag=v6.3.1 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # tag=v8.0.0 with: version: v2.1.0 args: --out-format=colored-line-number From 36c7812f155da02f80f7b66871eef468aeab1787 Mon Sep 17 00:00:00 2001 From: Richard Case Date: Wed, 14 May 2025 18:00:11 +0100 Subject: [PATCH 4/4] wip: add kal linter Signed-off-by: Richard Case --- .github/workflows/pr-golangci-lint.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr-golangci-lint.yaml b/.github/workflows/pr-golangci-lint.yaml index 0a705b756c..be19cccadd 100644 --- a/.github/workflows/pr-golangci-lint.yaml +++ b/.github/workflows/pr-golangci-lint.yaml @@ -29,7 +29,6 @@ jobs: uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # tag=v8.0.0 with: version: v2.1.0 - args: --out-format=colored-line-number working-directory: ${{matrix.working-directory}} - name: Lint API run: make lint-api