diff --git a/.github/workflows/pr-golangci-lint.yaml b/.github/workflows/pr-golangci-lint.yaml index 80a73805de6..f777d80e63c 100644 --- a/.github/workflows/pr-golangci-lint.yaml +++ b/.github/workflows/pr-golangci-lint.yaml @@ -30,9 +30,8 @@ jobs: go-version: ${{ steps.vars.outputs.go_version }} - name: golangci-lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # tag=v6.5.2 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # tag=v7.0.0 with: # update the version when updating golangci-lint - version: v1.64.8 - args: --out-format=colored-line-number + version: v2.1.2 working-directory: ${{matrix.working-directory}} diff --git a/.golangci.yml b/.golangci.yml index 51bf1fda7f6..9914d416e7c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,11 +1,10 @@ +version: "2" run: - timeout: 10m build-tags: - e2e allow-parallel-runners: true - linters: - disable-all: true + default: none enable: - asasalint # warns about passing []any to func(...any) without expanding it - asciicheck # non ascii symbols @@ -19,16 +18,12 @@ linters: - errcheck # unchecked errors - errchkjson # invalid types passed to json encoder - exhaustruct # checks if all structure fields are initialized - - gci # ensures imports are organized - ginkgolinter # ginkgo and gomega - goconst # strings that can be replaced by constants - gocritic # bugs, performance, style (we could add custom ones to this one) - godot # checks that comments end in a period - - gofmt # warns about incorrect use of fmt functions - - goimports # import formatting - goprintffuncname # printft-like functions should be named with f at the end - gosec # potential security problems - - gosimple # simplify code - govet # basically 'go vet' - importas # consistent import aliases - ineffassign # ineffectual assignments @@ -45,7 +40,6 @@ linters: - predeclared # shadowing predeclared identifiers - revive # better version of golint - staticcheck # some of staticcheck's rules - - stylecheck # another replacement for golint - thelper # test helpers not starting with t.Helper() - unconvert # unnecessary type conversions - unparam # unused function parameters @@ -53,258 +47,279 @@ linters: - usestdlibvars # using variables/constants from the standard library - usetesting # reports uses of functions with replacement inside the testing package - whitespace # unnecessary newlines - -linters-settings: - exhaustruct: - include: - # Hub ASO agent pools should be fully defined to prevent unnecessary updates - - '.*storage\..*AgentPoolProfile$' - gosec: - excludes: - - G307 # Deferring unsafe method "Close" on type "\*os.File" - - G108 # Profiling endpoint is automatically exposed on /debug/pprof - - G115 # integer overflow conversion int -> int32 - gci: - sections: - - standard # Standard section: captures all standard packages. - - default # Default section: contains all imports that could not be matched to another section type. - - prefix(sigs.k8s.io/cluster-api-provider-azure) # Custom section: groups all imports with the specified Prefix. - custom-order: true - ginkgolinter: - forbid-focus-container: true - goconst: - ignore-tests: true - godot: - # declarations - for top level declaration comments (default); - # toplevel - for top level comments; - # all - for all comments. - scope: toplevel - exclude: - - '^ \+.*' - - '^ ANCHOR.*' - gocritic: - enabled-tags: - - "experimental" - disabled-checks: - - appendAssign - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - evalOrder - - ifElseChain - - octalLiteral - - regexpSimplify - - sloppyReassign - - truncateCmp - - typeDefFirst - - unnamedResult - - unnecessaryDefer - - whyNoLint - - wrapperFunc - importas: - no-unaliased: true - alias: - # Kubernetes - - 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/api/errors - alias: apierrors - - pkg: k8s.io/apimachinery/pkg/util/errors - alias: kerrors - # Controller Runtime - - pkg: sigs.k8s.io/controller-runtime - alias: ctrl - # CAPI - - pkg: sigs.k8s.io/cluster-api/api/v1beta1 - alias: clusterv1 - # CAPI exp - - pkg: sigs.k8s.io/cluster-api/exp/api/v1beta1 - alias: expv1 - # CAPZ - - pkg: sigs.k8s.io/cluster-api-provider-azure/api/v1beta1 - alias: infrav1 - # CAPZ exp - - pkg: sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1 - alias: infrav1exp - - pkg: sigs.k8s.io/cluster-api-provider-azure/util/webhook - alias: webhookutils - # Azure - - pkg: github.com/Azure/go-autorest/autorest/azure - alias: azureautorest - # ASO - - pkg: github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601 - alias: asoresourcesv1 - # Azureutil - - pkg: sigs.k8s.io/cluster-api-provider-azure/util/azure - alias: azureutil - # Deprecated - - pkg: github.com/Azure/go-autorest/autorest/to - alias: deprecated-use-k8s.io-utils-pointer - nolintlint: - allow-unused: false - require-specific: true - revive: + settings: + exhaustruct: + include: + # Hub ASO agent pools should be fully defined to prevent unnecessary updates + - .*storage\..*AgentPoolProfile$ + ginkgolinter: + forbid-focus-container: true + gocritic: + disabled-checks: + - appendAssign + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - evalOrder + - ifElseChain + - octalLiteral + - regexpSimplify + - sloppyReassign + - truncateCmp + - typeDefFirst + - unnamedResult + - unnecessaryDefer + - whyNoLint + - wrapperFunc + enabled-tags: + - experimental + godot: + # declarations - for top level declaration comments (default); + # toplevel - for top level comments; + # all - for all comments. + scope: toplevel + exclude: + - ^ \+.* + - ^ ANCHOR.* + gosec: + excludes: + - G307 # Deferring unsafe method "Close" on type "\*os.File" + - G108 # Profiling endpoint is automatically exposed on /debug/pprof + - G115 # integer overflow conversion int -> int32 + importas: + alias: + # Kubernetes + - 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/api/errors + alias: apierrors + - pkg: k8s.io/apimachinery/pkg/util/errors + alias: kerrors + # Controller Runtime + - pkg: sigs.k8s.io/controller-runtime + alias: ctrl + # CAPI + - pkg: sigs.k8s.io/cluster-api/api/v1beta1 + alias: clusterv1 + # CAPI exp + - pkg: sigs.k8s.io/cluster-api/exp/api/v1beta1 + alias: expv1 + # CAPZ + - pkg: sigs.k8s.io/cluster-api-provider-azure/api/v1beta1 + alias: infrav1 + # CAPZ exp + - pkg: sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1 + alias: infrav1exp + - pkg: sigs.k8s.io/cluster-api-provider-azure/util/webhook + alias: webhookutils + # Azure + - pkg: github.com/Azure/go-autorest/autorest/azure + alias: azureautorest + # ASO + - pkg: github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601 + alias: asoresourcesv1 + # Azureutil + - pkg: sigs.k8s.io/cluster-api-provider-azure/util/azure + alias: azureutil + # Deprecated + - pkg: github.com/Azure/go-autorest/autorest/to + alias: deprecated-use-k8s.io-utils-pointer + no-unaliased: true + nolintlint: + require-specific: true + allow-unused: false + 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: 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: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + # + # Rules in addition to the recommended configuration above. + # + - name: bool-literal-in-expr + - name: constant-logical-expr + - name: exported + arguments: + - disableStutteringCheck + exclusions: + generated: lax 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: 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: unused-parameter - - name: unreachable-code - - name: redefines-builtin-id - # - # Rules in addition to the recommended configuration above. - # - - name: bool-literal-in-expr - - name: constant-logical-expr - - name: exported - arguments: - - disableStutteringCheck -issues: - exclude-files: - - 'zz_generated\.(\w*)\.go$' - exclude-rules: - - path: '(\w*)conversion.go' - text: "use underscores in Go names|receiver name (.+) should be consistent|methods on the same type should have the same receiver name" - - path: 'mock(\w+)/doc.go$' - text: "use underscores in package names|don't use an underscore in package name" - - path: (^test/|_test.go$) - linters: - - dogsled - - exhaustruct - - goconst - - godot - - path: (^test/|_test.go$) - text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported - - source: \"github.com/onsi/(ginkgo/v2|gomega)\" - text: "should not use dot imports" - # 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 - # Dot imports for gomega and ginkgo are allowed - # within test files and test utils. - - linters: - - revive - - stylecheck - path: _test\.go - text: should not use dot imports - - linters: - - revive - # 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" - # Ignoring stylistic checks for generated code - path: .*(api|types|test)\/.*\/conversion.*\.go$ - - linters: - - revive - # 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 - # Ignoring stylistic checks for generated code - path: .*(api|types|test)\/.*\/conversion.*\.go$ - - linters: - - revive - # By convention, receiver names in a method should reflect their identity. - text: "receiver-naming: receiver name" - # Ignoring stylistic checks for generated code - path: .*(api|types)\/.*\/conversion.*\.go$ - - linters: - - stylecheck - text: "ST1016: methods on the same type should have the same receiver name" - path: .*(api|types)\/.*\/conversion.*\.go$ - # We don't care about defer in for loops in test files. - - linters: - - gocritic - text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop" - path: _test\.go + - path: (\w*)conversion.go + text: use underscores in Go names|receiver name (.+) should be consistent|methods on the same type should have the same receiver name + - path: mock(\w+)/doc.go$ + text: use underscores in package names|don't use an underscore in package name + - linters: + - dogsled + - exhaustruct + - goconst + - godot + path: (^test/|_test.go$) + - path: (^test/|_test.go$) + text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported + - text: should not use dot imports + source: \"github.com/onsi/(ginkgo/v2|gomega)\" + - 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 + # Dot imports for gomega and ginkgo are allowed + # within test files and test utils. + - linters: + - revive + - staticcheck + path: _test\.go + text: should not use dot imports + # Exclude some packages or code to require comments, for example test code, or fake clients. + - 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 + # 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' + - linters: + - staticcheck + # Ignoring stylistic checks for generated code + path: .*(api|types)\/.*\/conversion.*\.go$ + text: 'ST1016: methods on the same type should have the same receiver name' + - linters: + - staticcheck + text: 'QF1008: could remove embedded field' + # We don't care about defer in for loops in test files. + - linters: + - gocritic + path: _test\.go + text: 'deferInLoop: Possible resource leak, ''defer'' is called in the ''for'' loop' # Ignore non-constant format string in call to condition utils - - linters: - - govet - text: "non-constant format string in call to sigs\\.k8s\\.io\\/cluster-api\\/util\\/conditions\\." - # for i = x; i < y; i++ {} is already optimal; Ignore this linter message - - linters: - - intrange - text: "for loop can be changed to use an integer range" - # Ignore the return value of below functions in test files - - linters: - - errcheck - text: Error return value of (`os.Setenv`|`fmt.Fprintf`|`resp.Body.Close`|`os.Unsetenv`|`fmt.Fprintln`|`[\w\.]+\.Close`|`[\w\.]+\.Flush`|`[\w\.]+\.RemoveAll`) is not checked - path: (^test\/e2e\/.*\.go$|.*_test\.go$) - # Do not validate file paths in tests - - linters: - - gosec - text: "G304: Potential file inclusion via variable" - path: ^test\/e2e\/.*\.go$ - # Ignore the elevated access that "others" have for dirs/files created in tests with 0755 permissions - - linters: - - gosec - text: "G301: Expect directory permissions to be 0750 or less" - path: ^test\/e2e\/.*\.go$ - # Ignore the elevated access that "group" and "others" have for dirs/files opened in tests with 0644 permissions - - linters: - - gosec - text: "G302: Expect file permissions to be 0600 or less" - path: ^test\/e2e\/.*\.go$ - # Ignore unhandled errors in test files when using os.Setenv - - linters: - - gosec - text: "G104: Errors unhandled." - path: ^test\/e2e\/.*\.go$ - # Ignore the unhandled errors on using os.Setenv in test files - - linters: - - gosec - text: "G104: Errors unhandled." - path: .*_test\.go$ - # Ignore unused parameters in test files - - linters: - - revive - text: "^unused-parameter: parameter '.*' seems to be unused, consider removing or renaming it as _$" - path: .*(_test|test)\.go$ - # Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files. - - linters: - - revive - text: "^package-comments: package comment should be of the form \".*\"$" - path: .*\.go$ - # Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files. - - linters: - - revive - text: "package-comments: should have a package comment" - path: .*\.go$ - # Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files. - - linters: - - stylecheck - text: "ST1000: at least one file in a package should have a package comment" - path: .*\.go$ - # Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files. - - linters: - - stylecheck - text: "ST1000: package comment should be of the form \".*\"$" - path: .*\.go$ + - linters: + - govet + text: non-constant format string in call to sigs\.k8s\.io\/cluster-api\/util\/conditions\. + # for i = x; i < y; i++ {} is already optimal; Ignore this linter message + - linters: + - intrange + text: for loop can be changed to use an integer range + # Ignore the return value of below functions in test files + - linters: + - errcheck + path: (^test\/e2e\/.*\.go$|.*_test\.go$) + text: Error return value of (`os.Setenv`|`fmt.Fprintf`|`resp.Body.Close`|`os.Unsetenv`|`fmt.Fprintln`|`[\w\.]+\.Close`|`[\w\.]+\.Flush`|`[\w\.]+\.RemoveAll`) is not checked + # Do not validate file paths in tests + - linters: + - gosec + path: ^test\/e2e\/.*\.go$ + text: 'G304: Potential file inclusion via variable' + # Ignore the elevated access that "others" have for dirs/files created in tests with 0755 permissions + - linters: + - gosec + path: ^test\/e2e\/.*\.go$ + text: 'G301: Expect directory permissions to be 0750 or less' + # Ignore the elevated access that "group" and "others" have for dirs/files opened in tests with 0644 permissions + - linters: + - gosec + path: ^test\/e2e\/.*\.go$ + text: 'G302: Expect file permissions to be 0600 or less' + # # Ignore unhandled errors in test files when using os.Setenv + # - linters: + # - gosec + # path: ^test\/e2e\/.*\.go$ + # text: 'G104: Errors unhandled.' + # # Ignore the unhandled errors on using os.Setenv in test files + # - linters: + # - gosec + # path: .*_test\.go$ + # text: 'G104: Errors unhandled.' + # Ignore unused parameters in test files + - linters: + - revive + path: .*(_test|test)\.go$ + text: '^unused-parameter: parameter ''.*'' seems to be unused, consider removing or renaming it as _$' + # Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files. + - linters: + - revive + path: .*\.go$ + text: '^package-comments: package comment should be of the form ".*"$' + # Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files. + - linters: + - revive + path: .*\.go$ + text: 'package-comments: should have a package comment' + # Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files. + - linters: + - staticcheck + path: .*\.go$ + text: 'ST1000: at least one file in a package should have a package comment' + # Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files. + - linters: + - staticcheck + path: .*\.go$ + text: 'ST1000: package comment should be of the form ".*"$' + - linters: + - goconst + path: (.+)_test\.go + paths: + - zz_generated\.(\w*)\.go$ + - third_party$ + - builtin$ + - examples$ # 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 +issues: max-issues-per-linter: 0 max-same-issues: 0 +formatters: + enable: + - gci # ensures imports are organized + - gofmt # warns about incorrect use of fmt functions + - goimports # import formatting + settings: + gci: + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(sigs.k8s.io/cluster-api-provider-azure) # Custom section: groups all imports with the specified Prefix. + custom-order: true + exclusions: + generated: lax + paths: + - zz_generated\.(\w*)\.go$ + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 5e58743f8bd..2d90fab4201 100644 --- a/Makefile +++ b/Makefile @@ -595,19 +595,23 @@ help: ## Display this help. ##@ Linting: .PHONY: lint -lint: $(GOLANGCI_LINT) lint-latest ## Lint codebase. - $(GOLANGCI_LINT) run -v --print-resources-usage --go=$(GO_VERSION) $(GOLANGCI_LINT_EXTRA_ARGS) +lint: $(GOLANGCI_LINT) lint-azure-latest ## Lint the codebase. + $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) + +.PHONY: lint-fast +lint-fast: $(GOLANGCI_LINT) ## Lint the codebase with fast linters only. + GOLANGCI_LINT_EXTRA_ARGS+=--fast-only $(MAKE) lint .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 + GOLANGCI_LINT_EXTRA_ARGS+=--fix $(MAKE) lint -lint-full: $(GOLANGCI_LINT) ## Run slower linters to detect possible issues. - $(GOLANGCI_LINT) run -v --fast=false --go=$(GO_VERSION) +.PHONY: lint-full +lint-full: $(GOLANGCI_LINT) lint ## Lint the codebase. -.PHONY: lint-latest ## TODO: update the lint-latest to lint-azure-latest -lint-latest: - ./hack/lint-latest.sh ## TODO: update the lint-latest.sh to lint-azure-latest.sh +.PHONY: lint-azure-latest ## Check for usage of the "latest" floating Azure API version. +lint-azure-latest: + ./hack/lint-azure-latest.sh ## -------------------------------------- ## Release @@ -830,7 +834,7 @@ $(ENVSUBST): ## Build envsubst from tools folder. GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/drone/envsubst/v2/cmd/envsubst $(ENVSUBST_BIN) $(ENVSUBST_VER) $(GOLANGCI_LINT): ## Build golangci-lint from tools folder. - GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER) + GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/v2/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER) $(KUSTOMIZE): ## Build kustomize from tools folder. GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) sigs.k8s.io/kustomize/kustomize/v5 $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER) diff --git a/api/v1beta1/azureimage_validation.go b/api/v1beta1/azureimage_validation.go index 42eba08b1c6..d9e14e932e0 100644 --- a/api/v1beta1/azureimage_validation.go +++ b/api/v1beta1/azureimage_validation.go @@ -49,11 +49,7 @@ func ValidateImage(image *Image, fldPath *field.Path) field.ErrorList { func validateSingleDetailsOnly(image *Image, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} - imageDetailsFound := false - - if image.ID != nil { - imageDetailsFound = true - } + imageDetailsFound := (image.ID != nil) if image.Marketplace != nil { if imageDetailsFound { diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook.go b/api/v1beta1/azuremanagedcontrolplane_webhook.go index 539b9f3f8e0..3eff0314865 100644 --- a/api/v1beta1/azuremanagedcontrolplane_webhook.go +++ b/api/v1beta1/azuremanagedcontrolplane_webhook.go @@ -1007,14 +1007,15 @@ func validateAKSExtensions(extensions []AKSExtension, fldPath *field.Path) field allErrs = append(allErrs, field.Forbidden(fldPath.Child("ReleaseTrain"), "ReleaseTrain must not be given if AutoUpgradeMinorVersion is false")) } if extension.Scope != nil { - if extension.Scope.ScopeType == ExtensionScopeCluster { + switch extension.Scope.ScopeType { + case ExtensionScopeCluster: if extension.Scope.ReleaseNamespace == "" { allErrs = append(allErrs, field.Required(fldPath.Child("Scope", "ReleaseNamespace"), "ReleaseNamespace must be provided if Scope is Cluster")) } if extension.Scope.TargetNamespace != "" { allErrs = append(allErrs, field.Forbidden(fldPath.Child("Scope", "TargetNamespace"), "TargetNamespace can only be given if Scope is Namespace")) } - } else if extension.Scope.ScopeType == ExtensionScopeNamespace { + case ExtensionScopeNamespace: if extension.Scope.TargetNamespace == "" { allErrs = append(allErrs, field.Required(fldPath.Child("Scope", "TargetNamespace"), "TargetNamespace must be provided if Scope is Namespace")) } diff --git a/api/v1beta1/azuremanagedmachinepool_webhook.go b/api/v1beta1/azuremanagedmachinepool_webhook.go index 3afe5093f23..4437c15307e 100644 --- a/api/v1beta1/azuremanagedmachinepool_webhook.go +++ b/api/v1beta1/azuremanagedmachinepool_webhook.go @@ -422,7 +422,7 @@ func validateNamePattern(name *string, fieldNameMessage string, fldPath *field.P } for _, char := range *name { - if !(unicode.IsLower(char) || unicode.IsNumber(char)) { + if !unicode.IsLower(char) && !unicode.IsNumber(char) { return field.Invalid( fldPath, name, diff --git a/azure/scope/machinepool.go b/azure/scope/machinepool.go index c636bfb982b..4b2672ee647 100644 --- a/azure/scope/machinepool.go +++ b/azure/scope/machinepool.go @@ -324,7 +324,7 @@ func (m *MachinePoolScope) NeedsRequeue() bool { } desiredMatchesActual := len(m.vmssState.Instances) == int(m.DesiredReplicas()) - return !(state != nil && infrav1.IsTerminalProvisioningState(*state) && desiredMatchesActual) + return state == nil || !infrav1.IsTerminalProvisioningState(*state) || !desiredMatchesActual } // DesiredReplicas returns the replica count on machine pool or 0 if machine pool replicas is nil. diff --git a/azure/services/aksextensions/spec.go b/azure/services/aksextensions/spec.go index c0c3bcbe526..bb27fe6bd6b 100644 --- a/azure/services/aksextensions/spec.go +++ b/azure/services/aksextensions/spec.go @@ -91,13 +91,14 @@ func (s *AKSExtensionSpec) Parameters(_ context.Context, existingAKSExtension *a Type: (*asokubernetesconfigurationv1.Extension_Properties_AksAssignedIdentity_Type_Spec)(ptr.To(s.AKSAssignedIdentityType)), } } - if s.Scope.ScopeType == infrav1.ExtensionScopeCluster { + switch s.Scope.ScopeType { + case infrav1.ExtensionScopeCluster: aksExtension.Spec.Scope = &asokubernetesconfigurationv1.Scope{ Cluster: &asokubernetesconfigurationv1.ScopeCluster{ ReleaseNamespace: ptr.To(s.Scope.ReleaseNamespace), }, } - } else if s.Scope.ScopeType == infrav1.ExtensionScopeNamespace { + case infrav1.ExtensionScopeNamespace: aksExtension.Spec.Scope = &asokubernetesconfigurationv1.Scope{ Namespace: &asokubernetesconfigurationv1.ScopeNamespace{ TargetNamespace: ptr.To(s.Scope.TargetNamespace), diff --git a/azure/services/scalesets/spec.go b/azure/services/scalesets/spec.go index 3781d987082..2a12b8dc24d 100644 --- a/azure/services/scalesets/spec.go +++ b/azure/services/scalesets/spec.go @@ -239,11 +239,12 @@ func (s *ScaleSetSpec) Parameters(ctx context.Context, existing interface{}) (pa } // Assign Identity to VMSS - if s.Identity == infrav1.VMIdentitySystemAssigned { + switch s.Identity { + case infrav1.VMIdentitySystemAssigned: vmss.Identity = &armcompute.VirtualMachineScaleSetIdentity{ Type: ptr.To(armcompute.ResourceIdentityTypeSystemAssigned), } - } else if s.Identity == infrav1.VMIdentityUserAssigned { + case infrav1.VMIdentityUserAssigned: userIdentitiesMap, err := converters.UserAssignedIdentitiesToVMSSSDK(s.UserAssignedIdentities) if err != nil { return vmss, errors.Wrapf(err, "failed to assign identity %q", s.Name) diff --git a/hack/lint-latest.sh b/hack/lint-azure-latest.sh similarity index 100% rename from hack/lint-latest.sh rename to hack/lint-azure-latest.sh