diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index fc668c644..ff1a5c518 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -12,7 +12,7 @@ jobs: - uses: codespell-project/actions-codespell@94259cd8be02ad2903ba34a22d9c13de21a74461 # v2.0 with: - skip: .git,_artifacts,*.sum + skip: .git,_artifacts,*.sum,.golangci.yml ignore_words_file: .codespellignore check_filenames: true check_hidden: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 58c18edde..691e7eaf6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,5 +23,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1 with: - timeout: 10m - version: v1.57 + version: v1.58 diff --git a/.golangci.yml b/.golangci.yml index 0eec77c3b..010766de8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,41 +1,111 @@ +--- linters: disable-all: true enable: - - asciicheck - - bodyclose - - depguard - - dogsled - - errcheck - - exportloopref - - goconst - - gocritic - - gocyclo - - godot - - gofmt - - goimports - - goprintffuncname - - gosec - - gosimple - - govet - - importas - - ineffassign - - misspell - - nakedret - - nilerr - - noctx - - nolintlint - - prealloc - - predeclared - - revive - - rowserrcheck - - staticcheck - - stylecheck - - thelper - - typecheck - - unconvert - - unparam - - unused - - whitespace + - asasalint + - asciicheck + - bidichk + - bodyclose + - canonicalheader + # - copyloopvar // only on go1.22 + - decorder + - dogsled + - durationcheck + - errcheck + - errchkjson + - errname + - exportloopref + - fatcontext + - ginkgolinter + - gocheckcompilerdirectives + - gochecksumtype + - goconst + - gocritic + - gocyclo + - godox + - gofmt + - gofumpt + - goheader + - goimports + - gomodguard + - goprintffuncname + - gosec + - gosimple + - gosmopolitan + - govet + - grouper + - importas + - ineffassign + # - intrange // only on go1.22 + - loggercheck + - makezero + - mirror + - misspell + - musttag + - nakedret + - nolintlint + - nosprintfhostport + - perfsprint + - prealloc + - predeclared + - promlinter + - protogetter + - reassign + - revive + - rowserrcheck + - sloglint + - spancheck + - sqlclosecheck + - staticcheck + - stylecheck + - tagalign + - tenv + - testableexamples + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + - zerologlint + # - containedctx + # - cyclop + # - depguard + # - dupword + # - err113 + # - errorlint + # - exhaustive + # - exhaustruct + # - forbidigo + # - forcetypeassert + # - funlen + # - gci + # - gochecknoglobals + # - gochecknoinits + # - gocognit + # - godot + # - inamedparam + # - interfacebloat + # - ireturn + # - lll + # - maintidx + # - mnd + # - nestif + # - nilerr + # - nilnil + # - nlreturn + # - noctx + # - nonamedreturns + # - paralleltest + # - tagliatelle + # - testifylint + # - testpackage + # - thelper + # - tparallel + # - varnamelen + # - wrapcheck + # - wsl linters-settings: importas: @@ -55,17 +125,6 @@ linters-settings: # Controller Runtime - pkg: sigs.k8s.io/controller-runtime alias: ctrl - staticcheck: - go: "1.18" - stylecheck: - go: "1.18" - depguard: - rules: - main: - deny: - - pkg: "io/ioutil" - desc: "ioutil is deprecated starting with Go 1.16" - issues: max-same-issues: 0 @@ -73,66 +132,65 @@ issues: # 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 + exclude-files: + - "zz_generated.*\\.go$" + - ".*conversion.*\\.go$" + exclude-dirs: + - mock* # List of regexps of issue texts to exclude, empty list by default. exclude: - # The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time. - # If it is decided they will not be addressed they should be moved above this comment. - - Subprocess launch(ed with variable|ing should be audited) - - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) - - (G104|G307) + # The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time. + # If it is decided they will not be addressed they should be moved above this comment. + - Subprocess launch(ed with variable|ing should be audited) + - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) + - (G104|G307) exclude-rules: - - linters: - - gosec - text: "G108: Profiling endpoint is automatically exposed on /debug/pprof" - - 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 - # 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" - # 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: "(framework|e2e|infrastructure/docker)/.*.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 - # Append should be able to assign to a different var/slice. - - linters: - - gocritic - text: "appendAssign: append result not assigned to the same slice" - + - linters: + - gosec + text: "G108: Profiling endpoint is automatically exposed on /debug/pprof" + - 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 + # 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" + # 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: "(framework|e2e|infrastructure/docker)/.*.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 + # Append should be able to assign to a different var/slice. + - linters: + - gocritic + text: "appendAssign: append result not assigned to the same slice" run: timeout: 10m - skip-files: - - "zz_generated.*\\.go$" - - ".*conversion.*\\.go$" - skip-dirs: - - mock* allow-parallel-runners: true diff --git a/Dockerfile b/Dockerfile index b8a307a5b..cf4530e71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ # limitations under the License. # Build the manager binary -FROM golang:1.21.9@sha256:ff6cfbd291c157a5b67e121b050e80a646a88b55de5c489a5c07acb9528a1feb as builder +FROM golang:1.21.10@sha256:45f2cab1eebfb90d214ab8ce896cefc320e5c8768b4b34bb402652d90c670875 as builder WORKDIR /workspace # Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy diff --git a/Makefile b/Makefile index ab413ca3d..5bdf236a9 100644 --- a/Makefile +++ b/Makefile @@ -145,7 +145,7 @@ endif # Build time versioning details. LDFLAGS := $(shell hack/version.sh) -GOLANG_VERSION := 1.21.9 +GOLANG_VERSION := 1.21.10 # CI CAPG_WORKER_CLUSTER_KUBECONFIG ?= "/tmp/kubeconfig" @@ -489,7 +489,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KIND) $(KUBECTL) ./hack/install-cert-manager.sh $(CERT_MANAGER_VER) # Deploy CAPI - curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.1/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f - + curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.2/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f - # Deploy CAPG $(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=clusterapi diff --git a/Tiltfile b/Tiltfile index 2e2727f74..0dbb12a31 100644 --- a/Tiltfile +++ b/Tiltfile @@ -18,7 +18,7 @@ settings = { "deploy_cert_manager": True, "preload_images_for_kind": True, "kind_cluster_name": "capg", - "capi_version": "v1.7.1", + "capi_version": "v1.7.2", "cert_manager_version": "v1.14.4", "kubernetes_version": "v1.29.3", } diff --git a/api/v1beta1/gcpcluster_webhook.go b/api/v1beta1/gcpcluster_webhook.go index b3748280b..d085a4ca3 100644 --- a/api/v1beta1/gcpcluster_webhook.go +++ b/api/v1beta1/gcpcluster_webhook.go @@ -41,8 +41,10 @@ func (c *GCPCluster) SetupWebhookWithManager(mgr ctrl.Manager) error { // +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-gcpcluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclusters,versions=v1beta1,name=validation.gcpcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1 // +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-gcpcluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclusters,versions=v1beta1,name=default.gcpcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1 -var _ webhook.Validator = &GCPCluster{} -var _ webhook.Defaulter = &GCPCluster{} +var ( + _ webhook.Validator = &GCPCluster{} + _ webhook.Defaulter = &GCPCluster{} +) // Default implements webhook.Defaulter so a webhook will be registered for the type. func (c *GCPCluster) Default() { diff --git a/api/v1beta1/gcpclustertemplate_webhook_test.go b/api/v1beta1/gcpclustertemplate_webhook_test.go index c56a74a72..35fdd0c5f 100644 --- a/api/v1beta1/gcpclustertemplate_webhook_test.go +++ b/api/v1beta1/gcpclustertemplate_webhook_test.go @@ -39,7 +39,8 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) { Spec: GCPClusterSpec{ Project: "test-gcp-cluster", Region: "ap-south-1", - }}, + }, + }, }, }, oldTemplate: &GCPClusterTemplate{ @@ -48,7 +49,8 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) { Spec: GCPClusterSpec{ Project: "test-gcp-cluster", Region: "ap-south-1", - }}, + }, + }, }, }, wantErr: false, @@ -61,7 +63,8 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) { Spec: GCPClusterSpec{ Project: "test-gcp-cluster", Region: "ap-south-1", - }}, + }, + }, }, }, oldTemplate: &GCPClusterTemplate{ @@ -70,7 +73,8 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) { Spec: GCPClusterSpec{ Project: "test-gcp-cluster", Region: "ap-east-1", - }}, + }, + }, }, }, wantErr: true, diff --git a/api/v1beta1/gcpmachine_webhook.go b/api/v1beta1/gcpmachine_webhook.go index 2b8057ad4..423befd5b 100644 --- a/api/v1beta1/gcpmachine_webhook.go +++ b/api/v1beta1/gcpmachine_webhook.go @@ -126,14 +126,14 @@ func checkKeyType(key *CustomerEncryptionKey) error { switch key.KeyType { case CustomerManagedKey: if key.ManagedKey == nil || key.SuppliedKey != nil { - return fmt.Errorf("CustomerEncryptionKey KeyType of Managed requires only ManagedKey to be set") + return errors.New("CustomerEncryptionKey KeyType of Managed requires only ManagedKey to be set") } case CustomerSuppliedKey: if key.SuppliedKey == nil || key.ManagedKey != nil { - return fmt.Errorf("CustomerEncryptionKey KeyType of Supplied requires only SuppliedKey to be set") + return errors.New("CustomerEncryptionKey KeyType of Supplied requires only SuppliedKey to be set") } if len(key.SuppliedKey.RawKey) > 0 && len(key.SuppliedKey.RSAEncryptedKey) > 0 { - return fmt.Errorf("CustomerEncryptionKey KeyType of Supplied requires either RawKey or RSAEncryptedKey to be set, not both") + return errors.New("CustomerEncryptionKey KeyType of Supplied requires either RawKey or RSAEncryptedKey to be set, not both") } default: return fmt.Errorf("invalid value for CustomerEncryptionKey KeyType %s", key.KeyType) diff --git a/api/v1beta1/gcpmachinetemplate_webhook_test.go b/api/v1beta1/gcpmachinetemplate_webhook_test.go index 3a20f14df..9c07ff19c 100644 --- a/api/v1beta1/gcpmachinetemplate_webhook_test.go +++ b/api/v1beta1/gcpmachinetemplate_webhook_test.go @@ -40,7 +40,8 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) { Spec: GCPMachineSpec{ InstanceType: "n2d-standard-4", OnHostMaintenance: &onHostMaintenanceTerminate, - }}, + }, + }, }, }, wantErr: false, @@ -54,7 +55,8 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) { InstanceType: "n2d-standard-4", ConfidentialCompute: &confidentialComputeEnabled, OnHostMaintenance: &onHostMaintenanceTerminate, - }}, + }, + }, }, }, wantErr: false, @@ -68,7 +70,8 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) { InstanceType: "n2d-standard-4", ConfidentialCompute: &confidentialComputeEnabled, OnHostMaintenance: &onHostMaintenanceMigrate, - }}, + }, + }, }, }, wantErr: true, @@ -81,7 +84,8 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) { Spec: GCPMachineSpec{ InstanceType: "n2d-standard-4", ConfidentialCompute: &confidentialComputeEnabled, - }}, + }, + }, }, }, wantErr: true, @@ -95,7 +99,8 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) { InstanceType: "e2-standard-4", ConfidentialCompute: &confidentialComputeEnabled, OnHostMaintenance: &onHostMaintenanceTerminate, - }}, + }, + }, }, }, wantErr: true, diff --git a/api/v1beta1/types.go b/api/v1beta1/types.go index bf865003d..763916cb2 100644 --- a/api/v1beta1/types.go +++ b/api/v1beta1/types.go @@ -116,7 +116,6 @@ type NetworkSpec struct { // LoadBalancerSpec contains configuration for one or more LoadBalancers. type LoadBalancerSpec struct { - // APIServerInstanceGroupTagOverride overrides the default setting for the // tag used when creating the API Server Instance Group. // +kubebuilder:validation:Optional diff --git a/cloud/scope/clients.go b/cloud/scope/clients.go index e92c3fa3c..5309df04c 100644 --- a/cloud/scope/clients.go +++ b/cloud/scope/clients.go @@ -147,7 +147,7 @@ func newInstanceGroupManagerClient(ctx context.Context, credentialsRef *infrav1. func newTagBindingsClient(ctx context.Context, credentialsRef *infrav1.ObjectReference, crClient client.Client, location string) (*resourcemanager.TagBindingsClient, error) { opts, err := defaultClientOptions(ctx, credentialsRef, crClient) - endpoint := fmt.Sprintf("%s-cloudresourcemanager.googleapis.com:443", location) + endpoint := location + "-cloudresourcemanager.googleapis.com:443" opts = append(opts, option.WithEndpoint(endpoint)) if err != nil { return nil, fmt.Errorf("getting default gcp client options: %w", err) diff --git a/cloud/scope/cluster.go b/cloud/scope/cluster.go index a00f36e25..6f7cb0a98 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -259,7 +259,7 @@ func (s *ClusterScope) FirewallRulesSpec() []*compute.Firewall { "130.211.0.0/22", }, TargetTags: []string{ - fmt.Sprintf("%s-control-plane", s.Name()), + s.Name() + "-control-plane", }, }, { @@ -272,12 +272,12 @@ func (s *ClusterScope) FirewallRulesSpec() []*compute.Firewall { }, Direction: "INGRESS", SourceTags: []string{ - fmt.Sprintf("%s-control-plane", s.Name()), - fmt.Sprintf("%s-node", s.Name()), + s.Name() + "-control-plane", + s.Name() + "-node", }, TargetTags: []string{ - fmt.Sprintf("%s-control-plane", s.Name()), - fmt.Sprintf("%s-node", s.Name()), + s.Name() + "-control-plane", + s.Name() + "-node", }, }, } diff --git a/cloud/scope/machine.go b/cloud/scope/machine.go index 19ac07b99..918b98ee1 100644 --- a/cloud/scope/machine.go +++ b/cloud/scope/machine.go @@ -388,7 +388,8 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance { ClusterName: m.ClusterGetter.Name(), Lifecycle: infrav1.ResourceLifecycleOwned, Role: ptr.To[string](m.Role()), - // TODO(vincepri): Check what needs to be added for the cloud provider label. + //nolint: godox + // TODO: Check what needs to be added for the cloud provider label. Additional: m.ClusterGetter.AdditionalLabels().AddLabels(m.GCPMachine.Spec.AdditionalLabels), }), Scheduling: &compute.Scheduling{ diff --git a/cloud/scope/managedcluster.go b/cloud/scope/managedcluster.go index 71cdc37c1..e9445a4be 100644 --- a/cloud/scope/managedcluster.go +++ b/cloud/scope/managedcluster.go @@ -259,7 +259,7 @@ func (s *ManagedClusterScope) FirewallRulesSpec() []*compute.Firewall { "130.211.0.0/22", }, TargetTags: []string{ - fmt.Sprintf("%s-control-plane", s.Name()), + s.Name() + "-control-plane", }, }, { @@ -272,12 +272,12 @@ func (s *ManagedClusterScope) FirewallRulesSpec() []*compute.Firewall { }, Direction: "INGRESS", SourceTags: []string{ - fmt.Sprintf("%s-control-plane", s.Name()), - fmt.Sprintf("%s-node", s.Name()), + s.Name() + "-control-plane", + s.Name() + "-node", }, TargetTags: []string{ - fmt.Sprintf("%s-control-plane", s.Name()), - fmt.Sprintf("%s-node", s.Name()), + s.Name() + "-control-plane", + s.Name() + "-node", }, }, } diff --git a/cloud/scope/managedmachinepool_test.go b/cloud/scope/managedmachinepool_test.go index 039e56f50..b8fa01dd0 100644 --- a/cloud/scope/managedmachinepool_test.go +++ b/cloud/scope/managedmachinepool_test.go @@ -11,9 +11,11 @@ import ( clusterv1exp "sigs.k8s.io/cluster-api/exp/api/v1beta1" ) -var TestGCPMMP *v1beta1.GCPManagedMachinePool -var TestMP *clusterv1exp.MachinePool -var TestClusterName string +var ( + TestGCPMMP *v1beta1.GCPManagedMachinePool + TestMP *clusterv1exp.MachinePool + TestClusterName string +) var _ = Describe("GCPManagedMachinePool Scope", func() { BeforeEach(func() { diff --git a/cloud/services/compute/loadbalancers/reconcile_test.go b/cloud/services/compute/loadbalancers/reconcile_test.go index 0a66157fd..d837badb7 100644 --- a/cloud/services/compute/loadbalancers/reconcile_test.go +++ b/cloud/services/compute/loadbalancers/reconcile_test.go @@ -106,7 +106,7 @@ func TestService_createOrGetInstanceGroup(t *testing.T) { { name: "instanceGroup name is overridden (should create instanceGroup)", scope: func(s *scope.ClusterScope) Scope { - var tagOverride = "master" + tagOverride := "master" s.GCPCluster.Spec.LoadBalancer = infrav1.LoadBalancerSpec{ APIServerInstanceGroupTagOverride: &tagOverride, } diff --git a/cloud/services/container/clusters/errors.go b/cloud/services/container/clusters/errors.go index b3bbf3fa5..6b25e36b6 100644 --- a/cloud/services/container/clusters/errors.go +++ b/cloud/services/container/clusters/errors.go @@ -17,25 +17,22 @@ limitations under the License. package clusters import ( - "fmt" - "github.com/pkg/errors" ) -var ( - // ErrAutopilotClusterMachinePoolsNotAllowed is used when there are machine pools specified for an autopilot enabled cluster. - ErrAutopilotClusterMachinePoolsNotAllowed = errors.New("cannot use machine pools with an autopilot enabled cluster") -) +// ErrAutopilotClusterMachinePoolsNotAllowed is used when there are machine pools specified for an autopilot enabled cluster. +var ErrAutopilotClusterMachinePoolsNotAllowed = errors.New("cannot use machine pools with an autopilot enabled cluster") // NewErrUnexpectedClusterStatus creates a new error for an unexpected cluster status. func NewErrUnexpectedClusterStatus(status string) error { - return &errUnexpectedClusterStatus{status} + return &UnexpectedClusterStatusError{status} } -type errUnexpectedClusterStatus struct { +// UnexpectedClusterStatusError is the error struct +type UnexpectedClusterStatusError struct { status string } -func (e *errUnexpectedClusterStatus) Error() string { - return fmt.Sprintf("unexpected error status: %s", e.status) +func (e *UnexpectedClusterStatusError) Error() string { + return "unexpected error status: " + e.status } diff --git a/cloud/services/container/clusters/kubeconfig.go b/cloud/services/container/clusters/kubeconfig.go index ef23516e3..978ead85c 100644 --- a/cloud/services/container/clusters/kubeconfig.go +++ b/cloud/services/container/clusters/kubeconfig.go @@ -207,13 +207,13 @@ func (s *Service) updateCAPIKubeconfigSecret(ctx context.Context, configSecret * func (s *Service) getKubeConfigContextName(isUser bool) string { contextName := fmt.Sprintf("gke_%s_%s_%s", s.scope.GCPManagedControlPlane.Spec.Project, s.scope.GCPManagedControlPlane.Spec.Location, s.scope.ClusterName()) if isUser { - contextName = fmt.Sprintf("%s-user", contextName) + contextName += "-user" } return contextName } func (s *Service) createBaseKubeConfig(contextName string, cluster *containerpb.Cluster) (*api.Config, error) { - certData, err := base64.StdEncoding.DecodeString(cluster.MasterAuth.ClusterCaCertificate) + certData, err := base64.StdEncoding.DecodeString(cluster.GetMasterAuth().GetClusterCaCertificate()) if err != nil { return nil, fmt.Errorf("decoding cluster CA cert: %w", err) } @@ -221,7 +221,7 @@ func (s *Service) createBaseKubeConfig(contextName string, cluster *containerpb. APIVersion: api.SchemeGroupVersion.Version, Clusters: map[string]*api.Cluster{ contextName: { - Server: fmt.Sprintf("https://%s", cluster.Endpoint), + Server: "https://" + cluster.GetEndpoint(), CertificateAuthorityData: certData, }, }, @@ -239,7 +239,7 @@ func (s *Service) createBaseKubeConfig(contextName string, cluster *containerpb. func (s *Service) generateToken(ctx context.Context) (string, error) { req := &credentialspb.GenerateAccessTokenRequest{ - Name: fmt.Sprintf("projects/-/serviceAccounts/%s", s.scope.GetCredential().ClientEmail), + Name: "projects/-/serviceAccounts/" + s.scope.GetCredential().ClientEmail, Scope: []string{ GkeScope, }, @@ -248,5 +248,6 @@ func (s *Service) generateToken(ctx context.Context) (string, error) { if err != nil { return "", errors.Errorf("error generating access token: %v", err) } - return resp.AccessToken, nil + + return resp.GetAccessToken(), nil } diff --git a/cloud/services/container/clusters/reconcile.go b/cloud/services/container/clusters/reconcile.go index ee047aa52..5a3f8cb08 100644 --- a/cloud/services/container/clusters/reconcile.go +++ b/cloud/services/container/clusters/reconcile.go @@ -94,10 +94,10 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { return ctrl.Result{RequeueAfter: reconciler.DefaultRetryTime}, nil } - log.V(2).Info("gke cluster found", "status", cluster.Status) - s.scope.GCPManagedControlPlane.Status.CurrentVersion = convertToSdkMasterVersion(cluster.CurrentMasterVersion) + log.V(2).Info("gke cluster found", "status", cluster.GetStatus()) + s.scope.GCPManagedControlPlane.Status.CurrentVersion = convertToSdkMasterVersion(cluster.GetCurrentMasterVersion()) - switch cluster.Status { + switch cluster.GetStatus() { case containerpb.Cluster_PROVISIONING: log.Info("Cluster provisioning in progress") conditions.MarkFalse(s.scope.ConditionSetter(), clusterv1.ReadyCondition, infrav1exp.GKEControlPlaneCreatingReason, clusterv1.ConditionSeverityInfo, "") @@ -122,8 +122,8 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { return ctrl.Result{RequeueAfter: reconciler.DefaultRetryTime}, nil case containerpb.Cluster_ERROR, containerpb.Cluster_DEGRADED: var msg string - if len(cluster.Conditions) > 0 { - msg = cluster.Conditions[0].GetMessage() + if len(cluster.GetConditions()) > 0 { + msg = cluster.GetConditions()[0].GetMessage() } log.Error(errors.New("Cluster in error/degraded state"), msg, "name", s.scope.ClusterName()) conditions.MarkFalse(s.scope.ConditionSetter(), infrav1exp.GKEControlPlaneReadyCondition, infrav1exp.GKEControlPlaneErrorReason, clusterv1.ConditionSeverityError, "") @@ -133,8 +133,8 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { case containerpb.Cluster_RUNNING: log.Info("Cluster running") default: - statusErr := NewErrUnexpectedClusterStatus(string(cluster.Status)) - log.Error(statusErr, fmt.Sprintf("Unhandled cluster status %s", cluster.Status), "name", s.scope.ClusterName()) + statusErr := NewErrUnexpectedClusterStatus(string(cluster.GetStatus())) + log.Error(statusErr, fmt.Sprintf("Unhandled cluster status %s", cluster.GetStatus()), "name", s.scope.ClusterName()) return ctrl.Result{}, statusErr } @@ -165,7 +165,7 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { return ctrl.Result{}, err } - s.scope.SetEndpoint(cluster.Endpoint) + s.scope.SetEndpoint(cluster.GetEndpoint()) conditions.MarkTrue(s.scope.ConditionSetter(), clusterv1.ReadyCondition) conditions.MarkTrue(s.scope.ConditionSetter(), infrav1exp.GKEControlPlaneReadyCondition) conditions.MarkFalse(s.scope.ConditionSetter(), infrav1exp.GKEControlPlaneCreatingCondition, infrav1exp.GKEControlPlaneCreatedReason, clusterv1.ConditionSeverityInfo, "") @@ -192,7 +192,7 @@ func (s *Service) Delete(ctx context.Context) (ctrl.Result, error) { return ctrl.Result{}, nil } - switch cluster.Status { + switch cluster.GetStatus() { case containerpb.Cluster_PROVISIONING: log.Info("Cluster provisioning in progress") return ctrl.Result{}, nil @@ -266,7 +266,7 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error { cluster.InitialClusterVersion = convertToSdkMasterVersion(*s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion) } if !s.scope.IsAutopilotCluster() { - cluster.NodePools = scope.ConvertToSdkNodePools(nodePools, machinePools, isRegional, cluster.Name) + cluster.NodePools = scope.ConvertToSdkNodePools(nodePools, machinePools, isRegional, cluster.GetName()) } createClusterRequest := &containerpb.CreateClusterRequest{ @@ -383,8 +383,8 @@ func (s *Service) checkDiffAndPrepareUpdate(existingCluster *containerpb.Cluster clusterUpdate := containerpb.ClusterUpdate{} // Release channel desiredReleaseChannel := convertToSdkReleaseChannel(s.scope.GCPManagedControlPlane.Spec.ReleaseChannel) - if desiredReleaseChannel != existingCluster.ReleaseChannel.Channel { - log.V(2).Info("Release channel update required", "current", existingCluster.ReleaseChannel.Channel, "desired", desiredReleaseChannel) + if desiredReleaseChannel != existingCluster.GetReleaseChannel().GetChannel() { + log.V(2).Info("Release channel update required", "current", existingCluster.GetReleaseChannel().GetChannel(), "desired", desiredReleaseChannel) needUpdate = true clusterUpdate.DesiredReleaseChannel = &containerpb.ReleaseChannel{ Channel: desiredReleaseChannel, @@ -393,7 +393,7 @@ func (s *Service) checkDiffAndPrepareUpdate(existingCluster *containerpb.Cluster // Master version if s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion != nil { desiredMasterVersion := convertToSdkMasterVersion(*s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion) - existingClusterMasterVersion := convertToSdkMasterVersion(existingCluster.CurrentMasterVersion) + existingClusterMasterVersion := convertToSdkMasterVersion(existingCluster.GetCurrentMasterVersion()) if desiredMasterVersion != existingClusterMasterVersion { needUpdate = true clusterUpdate.DesiredMasterVersion = desiredMasterVersion @@ -404,12 +404,12 @@ func (s *Service) checkDiffAndPrepareUpdate(existingCluster *containerpb.Cluster // DesiredMasterAuthorizedNetworksConfig // When desiredMasterAuthorizedNetworksConfig is nil, it means that the user wants to disable the feature. desiredMasterAuthorizedNetworksConfig := convertToSdkMasterAuthorizedNetworksConfig(s.scope.GCPManagedControlPlane.Spec.MasterAuthorizedNetworksConfig) - if !compareMasterAuthorizedNetworksConfig(desiredMasterAuthorizedNetworksConfig, existingCluster.MasterAuthorizedNetworksConfig) { + if !compareMasterAuthorizedNetworksConfig(desiredMasterAuthorizedNetworksConfig, existingCluster.GetMasterAuthorizedNetworksConfig()) { needUpdate = true clusterUpdate.DesiredMasterAuthorizedNetworksConfig = desiredMasterAuthorizedNetworksConfig - log.V(2).Info("Master authorized networks config update required", "current", existingCluster.MasterAuthorizedNetworksConfig, "desired", desiredMasterAuthorizedNetworksConfig) + log.V(2).Info("Master authorized networks config update required", "current", existingCluster.GetMasterAuthorizedNetworksConfig(), "desired", desiredMasterAuthorizedNetworksConfig) } - log.V(4).Info("Master authorized networks config update check", "current", existingCluster.MasterAuthorizedNetworksConfig) + log.V(4).Info("Master authorized networks config update check", "current", existingCluster.GetMasterAuthorizedNetworksConfig()) if desiredMasterAuthorizedNetworksConfig != nil { log.V(4).Info("Master authorized networks config update check", "desired", desiredMasterAuthorizedNetworksConfig) } @@ -431,20 +431,20 @@ func compareMasterAuthorizedNetworksConfig(a, b *containerpb.MasterAuthorizedNet return false } - if a.Enabled != b.Enabled { + if a.GetEnabled() != b.GetEnabled() { return false } if (a.GcpPublicCidrsAccessEnabled == nil && b.GcpPublicCidrsAccessEnabled != nil) || (a.GcpPublicCidrsAccessEnabled != nil && b.GcpPublicCidrsAccessEnabled == nil) { return false } - if a.GcpPublicCidrsAccessEnabled != nil && b.GcpPublicCidrsAccessEnabled != nil && *a.GcpPublicCidrsAccessEnabled != *b.GcpPublicCidrsAccessEnabled { + if a.GcpPublicCidrsAccessEnabled != nil && b.GcpPublicCidrsAccessEnabled != nil && a.GetGcpPublicCidrsAccessEnabled() != b.GetGcpPublicCidrsAccessEnabled() { return false } // if one cidrBlocks is nil, but the other is empty, they are equal. - if (a.CidrBlocks == nil && b.CidrBlocks != nil && len(b.CidrBlocks) == 0) || (b.CidrBlocks == nil && a.CidrBlocks != nil && len(a.CidrBlocks) == 0) { + if (a.CidrBlocks == nil && b.CidrBlocks != nil && len(b.GetCidrBlocks()) == 0) || (b.CidrBlocks == nil && a.CidrBlocks != nil && len(a.GetCidrBlocks()) == 0) { return true } - if !cmp.Equal(a.CidrBlocks, b.CidrBlocks) { + if !cmp.Equal(a.GetCidrBlocks(), b.GetCidrBlocks()) { return false } return true diff --git a/cloud/services/container/nodepools/reconcile.go b/cloud/services/container/nodepools/reconcile.go index 68ade86e0..1f91c2f5c 100644 --- a/cloud/services/container/nodepools/reconcile.go +++ b/cloud/services/container/nodepools/reconcile.go @@ -82,7 +82,7 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { conditions.MarkTrue(s.scope.ConditionSetter(), infrav1exp.GKEMachinePoolCreatingCondition) return ctrl.Result{RequeueAfter: reconciler.DefaultRetryTime}, nil } - log.V(2).Info("Node pool found", "cluster", s.scope.Cluster.Name, "nodepool", nodePool.Name) + log.V(2).Info("Node pool found", "cluster", s.scope.Cluster.Name, "nodepool", nodePool.GetName()) instances, err := s.getInstances(ctx, nodePool) if err != nil { @@ -91,10 +91,10 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { } providerIDList := []string{} for _, instance := range instances { - log.V(4).Info("parsing gce instance url", "url", *instance.Instance) - providerID, err := providerid.NewFromResourceURL(*instance.Instance) + log.V(4).Info("parsing gce instance url", "url", instance.GetInstance()) + providerID, err := providerid.NewFromResourceURL(instance.GetInstance()) if err != nil { - log.Error(err, "parsing instance url", "url", *instance.Instance) + log.Error(err, "parsing instance url", "url", instance.GetInstance()) conditions.MarkFalse(s.scope.ConditionSetter(), infrav1exp.GKEMachinePoolReadyCondition, infrav1exp.GKEMachinePoolErrorReason, clusterv1.ConditionSeverityError, "") return ctrl.Result{}, err } @@ -104,7 +104,7 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { s.scope.GCPManagedMachinePool.Status.Replicas = int32(len(providerIDList)) // Update GKEManagedMachinePool conditions based on GKE node pool status - switch nodePool.Status { + switch nodePool.GetStatus() { case containerpb.NodePool_PROVISIONING: // node pool is creating log.Info("Node pool provisioning in progress") @@ -127,8 +127,8 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { case containerpb.NodePool_ERROR, containerpb.NodePool_RUNNING_WITH_ERROR: // node pool is in error or degraded state var msg string - if len(nodePool.Conditions) > 0 { - msg = nodePool.Conditions[0].GetMessage() + if len(nodePool.GetConditions()) > 0 { + msg = nodePool.GetConditions()[0].GetMessage() } log.Error(errors.New("Node pool in error/degraded state"), msg, "name", s.scope.GCPManagedMachinePool.Name) conditions.MarkFalse(s.scope.ConditionSetter(), infrav1exp.GKEMachinePoolReadyCondition, infrav1exp.GKEMachinePoolErrorReason, clusterv1.ConditionSeverityError, "") @@ -140,7 +140,7 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) { conditions.MarkFalse(s.scope.ConditionSetter(), infrav1exp.GKEMachinePoolCreatingCondition, infrav1exp.GKEMachinePoolCreatedReason, clusterv1.ConditionSeverityInfo, "") log.Info("Node pool running") default: - log.Error(errors.New("Unhandled node pool status"), fmt.Sprintf("Unhandled node pool status %s", nodePool.Status), "name", s.scope.GCPManagedMachinePool.Name) + log.Error(errors.New("Unhandled node pool status"), fmt.Sprintf("Unhandled node pool status %s", nodePool.GetStatus()), "name", s.scope.GCPManagedMachinePool.Name) return ctrl.Result{}, nil } @@ -210,7 +210,7 @@ func (s *Service) Delete(ctx context.Context) (ctrl.Result, error) { return ctrl.Result{}, err } - switch nodePool.Status { + switch nodePool.GetStatus() { case containerpb.NodePool_PROVISIONING: log.Info("Node pool provisioning in progress") return ctrl.Result{RequeueAfter: reconciler.DefaultRetryTime}, nil @@ -260,7 +260,7 @@ func (s *Service) describeNodePool(ctx context.Context, log *logr.Logger) (*cont func (s *Service) getInstances(ctx context.Context, nodePool *containerpb.NodePool) ([]*computepb.ManagedInstance, error) { instances := []*computepb.ManagedInstance{} - for _, url := range nodePool.InstanceGroupUrls { + for _, url := range nodePool.GetInstanceGroupUrls() { resourceURL, err := resourceurl.Parse(url) if err != nil { return nil, errors.Wrap(err, "error parsing instance group url") @@ -357,47 +357,47 @@ func (s *Service) checkDiffAndPrepareUpdateConfig(existingNodePool *containerpb. // Node version if s.scope.NodePoolVersion() != nil { desiredNodePoolVersion := infrav1exp.ConvertFromSdkNodeVersion(*s.scope.NodePoolVersion()) - if desiredNodePoolVersion != infrav1exp.ConvertFromSdkNodeVersion(existingNodePool.Version) { + if desiredNodePoolVersion != infrav1exp.ConvertFromSdkNodeVersion(existingNodePool.GetVersion()) { needUpdate = true updateNodePoolRequest.NodeVersion = desiredNodePoolVersion } } // Kubernetes labels - if !cmp.Equal(desiredNodePool.Config.GetLabels(), existingNodePool.Config.Labels) { + if !cmp.Equal(desiredNodePool.GetConfig().GetLabels(), existingNodePool.GetConfig().GetLabels()) { needUpdate = true updateNodePoolRequest.Labels = &containerpb.NodeLabels{ - Labels: desiredNodePool.Config.Labels, + Labels: desiredNodePool.GetConfig().GetLabels(), } } // Kubernetes taints - if !cmp.Equal(desiredNodePool.Config.GetTaints(), existingNodePool.Config.Taints) { + if !cmp.Equal(desiredNodePool.GetConfig().GetTaints(), existingNodePool.GetConfig().GetTaints()) { needUpdate = true updateNodePoolRequest.Taints = &containerpb.NodeTaints{ - Taints: desiredNodePool.Config.GetTaints(), + Taints: desiredNodePool.GetConfig().GetTaints(), } } // Node image type // GCP API returns image type string in all uppercase, we can do a case-insensitive check here. - if desiredNodePool.Config.ImageType != "" && !strings.EqualFold(desiredNodePool.Config.ImageType, existingNodePool.Config.ImageType) { + if desiredNodePool.GetConfig().GetImageType() != "" && !strings.EqualFold(desiredNodePool.GetConfig().GetImageType(), existingNodePool.GetConfig().GetImageType()) { needUpdate = true - updateNodePoolRequest.ImageType = desiredNodePool.Config.ImageType + updateNodePoolRequest.ImageType = desiredNodePool.GetConfig().GetImageType() } // Additional resource labels - if !cmp.Equal(desiredNodePool.Config.ResourceLabels, existingNodePool.Config.ResourceLabels) { + if !cmp.Equal(desiredNodePool.GetConfig().GetResourceLabels(), existingNodePool.GetConfig().GetResourceLabels()) { needUpdate = true updateNodePoolRequest.ResourceLabels = &containerpb.ResourceLabels{ - Labels: desiredNodePool.Config.ResourceLabels, + Labels: desiredNodePool.GetConfig().GetResourceLabels(), } } // Locations desiredLocations := s.scope.GCPManagedMachinePool.Spec.NodeLocations - if desiredLocations != nil && !cmp.Equal(desiredLocations, existingNodePool.Locations) { + if desiredLocations != nil && !cmp.Equal(desiredLocations, existingNodePool.GetLocations()) { needUpdate = true updateNodePoolRequest.Locations = desiredLocations } // Network tags desiredNetworkTags := s.scope.GCPManagedMachinePool.Spec.NodeNetwork.Tags - if existingNodePool.Config != nil && !cmp.Equal(desiredNetworkTags, existingNodePool.Config.Tags) { + if existingNodePool.GetConfig() != nil && !cmp.Equal(desiredNetworkTags, existingNodePool.GetConfig().GetTags()) { needUpdate = true updateNodePoolRequest.Tags = &containerpb.NetworkTags{ Tags: desiredNetworkTags, @@ -405,7 +405,7 @@ func (s *Service) checkDiffAndPrepareUpdateConfig(existingNodePool *containerpb. } // LinuxNodeConfig desiredLinuxNodeConfig := infrav1exp.ConvertToSdkLinuxNodeConfig(s.scope.GCPManagedMachinePool.Spec.LinuxNodeConfig) - if !cmp.Equal(desiredLinuxNodeConfig, existingNodePool.Config.LinuxNodeConfig, cmpopts.IgnoreUnexported(containerpb.LinuxNodeConfig{})) { + if !cmp.Equal(desiredLinuxNodeConfig, existingNodePool.GetConfig().GetLinuxNodeConfig(), cmpopts.IgnoreUnexported(containerpb.LinuxNodeConfig{})) { needUpdate = true updateNodePoolRequest.LinuxNodeConfig = desiredLinuxNodeConfig } @@ -421,7 +421,7 @@ func (s *Service) checkDiffAndPrepareUpdateAutoscaling(existingNodePool *contain Name: s.scope.NodePoolFullName(), } - if !cmp.Equal(desiredAutoscaling, existingNodePool.Autoscaling, cmpopts.IgnoreUnexported(containerpb.NodePoolAutoscaling{})) { + if !cmp.Equal(desiredAutoscaling, existingNodePool.GetAutoscaling(), cmpopts.IgnoreUnexported(containerpb.NodePoolAutoscaling{})) { needUpdate = true setNodePoolAutoscalingRequest.Autoscaling = desiredAutoscaling } @@ -432,7 +432,7 @@ func (s *Service) checkDiffAndPrepareUpdateSize(existingNodePool *containerpb.No needUpdate := false desiredAutoscaling := infrav1exp.ConvertToSdkAutoscaling(s.scope.GCPManagedMachinePool.Spec.Scaling) - if desiredAutoscaling.Enabled { + if desiredAutoscaling.GetEnabled() { // Do not update node pool size if autoscaling is enabled. return false, nil } @@ -443,10 +443,10 @@ func (s *Service) checkDiffAndPrepareUpdateSize(existingNodePool *containerpb.No replicas := *s.scope.MachinePool.Spec.Replicas if shared.IsRegional(s.scope.Region()) { - replicas /= int32(len(existingNodePool.Locations)) + replicas /= int32(len(existingNodePool.GetLocations())) } - if replicas != existingNodePool.InitialNodeCount { + if replicas != existingNodePool.GetInitialNodeCount() { needUpdate = true setNodePoolSizeRequest.NodeCount = replicas } diff --git a/cloud/services/shared/tags.go b/cloud/services/shared/tags.go index 12b7fd5f3..cf8834702 100644 --- a/cloud/services/shared/tags.go +++ b/cloud/services/shared/tags.go @@ -38,7 +38,7 @@ func ResourceTagBinding(ctx context.Context, client *resourcemanager.TagBindings req := &rmpb.CreateTagBindingRequest{ TagBinding: &rmpb.TagBinding{ Parent: fmt.Sprintf("//container.googleapis.com/projects/%s/locations/%s/clusters/%s", tag.ParentID, spec.Region, name), - TagValue: tagValue.Name, + TagValue: tagValue.GetName(), }, } op, err := client.CreateTagBinding(ctx, req) @@ -71,7 +71,7 @@ func ResourceTagConvert(ctx context.Context, t infrav1.ResourceManagerTags) infr log.Error(err, "failed to retrieve tag value") continue } - tagValueList[tagValue.Parent] = tagValue.Name + tagValueList[tagValue.GetParent()] = tagValue.GetName() } return tagValueList diff --git a/exp/api/v1beta1/gcpmanagedcluster_webhook.go b/exp/api/v1beta1/gcpmanagedcluster_webhook.go index d77b01896..39f2ff054 100644 --- a/exp/api/v1beta1/gcpmanagedcluster_webhook.go +++ b/exp/api/v1beta1/gcpmanagedcluster_webhook.go @@ -118,7 +118,7 @@ func (r *GCPManagedCluster) validateCustomSubnet() error { if r.Spec.Network.AutoCreateSubnetworks == nil || *r.Spec.Network.AutoCreateSubnetworks { return nil } - var isSubnetExistInClusterRegion = false + isSubnetExistInClusterRegion := false for _, subnet := range r.Spec.Network.Subnets { if subnet.Region == r.Spec.Region { isSubnetExistInClusterRegion = true diff --git a/exp/api/v1beta1/gcpmanagedmachinepool_webhook.go b/exp/api/v1beta1/gcpmanagedmachinepool_webhook.go index 33b2e1821..5c1051c68 100644 --- a/exp/api/v1beta1/gcpmanagedmachinepool_webhook.go +++ b/exp/api/v1beta1/gcpmanagedmachinepool_webhook.go @@ -113,7 +113,7 @@ func (r *GCPManagedMachinePool) validateScaling() field.ErrorList { } // validates min <= max if max != nil && *max < *min { - allErrs = append(allErrs, field.Invalid(maxField, *max, fmt.Sprintf("must be greater than field %s", minField.String()))) + allErrs = append(allErrs, field.Invalid(maxField, *max, "must be greater than field "+minField.String())) } } } diff --git a/exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go b/exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go index c398dcd10..3dacba740 100644 --- a/exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go +++ b/exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go @@ -44,19 +44,19 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { It("should error when node pool name is too long", func() { gcpmmp.Spec.NodePoolName = strings.Repeat("A", maxNodePoolNameLength+1) errs := gcpmmp.validateSpec() - Expect(len(errs)).ToNot(BeZero()) + Expect(errs).ToNot(BeEmpty()) }) It("should pass when node pool name is within limit", func() { gcpmmp.Spec.NodePoolName = strings.Repeat("A", maxNodePoolNameLength) errs := gcpmmp.validateSpec() - Expect(len(errs)).To(BeZero()) + Expect(errs).To(BeEmpty()) }) }) Context("Test validateScaling", func() { It("should pass when scaling is not specified", func() { errs := gcpmmp.validateScaling() - Expect(len(errs)).To(BeZero()) + Expect(errs).To(BeEmpty()) }) It("should pass when min/max count is valid", func() { minCount := int32(1) @@ -67,7 +67,7 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { } errs := gcpmmp.validateScaling() - Expect(len(errs)).To(BeZero()) + Expect(errs).To(BeEmpty()) }) It("should fail when min is negative", func() { minCount := int32(-1) @@ -76,7 +76,7 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { } errs := gcpmmp.validateScaling() - Expect(len(errs)).ToNot(BeZero()) + Expect(errs).ToNot(BeEmpty()) }) It("should fail when min > max", func() { minCount := int32(3) @@ -87,7 +87,7 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { } errs := gcpmmp.validateScaling() - Expect(len(errs)).ToNot(BeZero()) + Expect(errs).ToNot(BeEmpty()) }) It("should fail when autoscaling is disabled and min/max is specified", func() { minCount := int32(1) @@ -102,14 +102,14 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { } errs := gcpmmp.validateScaling() - Expect(len(errs)).To(Equal(3)) + Expect(errs).To(HaveLen(3)) }) }) Context("Test validateImmutable", func() { It("should pass when node pool is not mutated", func() { old := gcpmmp.DeepCopy() errs := gcpmmp.validateImmutable(old) - Expect(len(errs)).To(BeZero()) + Expect(errs).To(BeEmpty()) }) It("should pass when mutable fields are mutated", func() { old := gcpmmp.DeepCopy() @@ -118,7 +118,7 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { } errs := gcpmmp.validateImmutable(old) - Expect(len(errs)).To(BeZero()) + Expect(errs).To(BeEmpty()) }) It("should fail when immutable fields are mutated", func() { old := gcpmmp.DeepCopy() @@ -131,14 +131,14 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { } errs := gcpmmp.validateImmutable(old) - Expect(len(errs)).To(Equal(3)) + Expect(errs).To(HaveLen(3)) }) }) Context("Test validateNonNegative", func() { It("should pass when number fields are not specified", func() { errs := gcpmmp.validateNonNegative() - Expect(len(errs)).To(BeZero()) + Expect(errs).To(BeEmpty()) }) It("should pass when number fields are non-negative", func() { maxPods := int64(10) @@ -149,7 +149,7 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { gcpmmp.Spec.DiskSizeGb = &diskSize errs := gcpmmp.validateNonNegative() - Expect(len(errs)).To(BeZero()) + Expect(errs).To(BeEmpty()) }) It("should pass when some number fields are negative", func() { maxPods := int64(-1) @@ -160,7 +160,7 @@ var _ = Describe("Test GCPManagedMachinePool Webhooks", func() { gcpmmp.Spec.DiskSizeGb = &diskSize errs := gcpmmp.validateNonNegative() - Expect(len(errs)).To(Equal(2)) + Expect(errs).To(HaveLen(2)) }) }) }) diff --git a/exp/api/v1beta1/webhook_suite_test.go b/exp/api/v1beta1/webhook_suite_test.go index b99f9676c..92545ad91 100644 --- a/exp/api/v1beta1/webhook_suite_test.go +++ b/exp/api/v1beta1/webhook_suite_test.go @@ -43,11 +43,13 @@ import ( // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment -var ctx context.Context -var cancel context.CancelFunc +var ( + cfg *rest.Config + k8sClient client.Client + testEnv *envtest.Environment + ctx context.Context + cancel context.CancelFunc +) func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) @@ -132,7 +134,6 @@ var _ = BeforeSuite(func() { conn.Close() return nil }).Should(Succeed()) - }) var _ = AfterSuite(func() { diff --git a/go.mod b/go.mod index 00a072b8c..0eacc83d3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ replace ( github.com/google/cel-go => github.com/google/cel-go v0.17.7 // kube-openapi should match the version imported by CAPI. k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 - sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.7.1 + sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.7.2 ) require ( @@ -35,8 +35,8 @@ require ( k8s.io/component-base v0.29.3 k8s.io/klog/v2 v2.110.1 k8s.io/utils v0.0.0-20240102154912-e7106e64919e - sigs.k8s.io/cluster-api v1.7.1 - sigs.k8s.io/cluster-api/test v1.7.1 + sigs.k8s.io/cluster-api v1.7.2 + sigs.k8s.io/cluster-api/test v1.7.2 sigs.k8s.io/controller-runtime v0.17.3 ) diff --git a/go.sum b/go.sum index 5b30af4a9..45cc882d5 100644 --- a/go.sum +++ b/go.sum @@ -543,10 +543,10 @@ k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCf k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 h1:TgtAeesdhpm2SGwkQasmbeqDo8th5wOBA5h/AjTKA4I= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0/go.mod h1:VHVDI/KrK4fjnV61bE2g3sA7tiETLn8sooImelsCx3Y= -sigs.k8s.io/cluster-api v1.7.1 h1:JkMAbAMzBM+WBHxXLTJXTiCisv1PAaHRzld/3qrmLYY= -sigs.k8s.io/cluster-api v1.7.1/go.mod h1:V9ZhKLvQtsDODwjXOKgbitjyCmC71yMBwDcMyNNIov0= -sigs.k8s.io/cluster-api/test v1.7.1 h1:QDru2586ZjIFBTW1Z7VVXVtauzR/yANm4tglUNLm9iE= -sigs.k8s.io/cluster-api/test v1.7.1/go.mod h1:yG0g5Mdq73fMn9JP4akgRQPSne973L+Qx6iVH+LjtSM= +sigs.k8s.io/cluster-api v1.7.2 h1:bRE8zoao7ajuLC0HijqfZVcubKQCPlZ04HMgcA53FGE= +sigs.k8s.io/cluster-api v1.7.2/go.mod h1:V9ZhKLvQtsDODwjXOKgbitjyCmC71yMBwDcMyNNIov0= +sigs.k8s.io/cluster-api/test v1.7.2 h1:muacGu5G/DGz2uTv3CUxml2QLi8fxbIra4CxA2S31KE= +sigs.k8s.io/cluster-api/test v1.7.2/go.mod h1:yG0g5Mdq73fMn9JP4akgRQPSne973L+Qx6iVH+LjtSM= sigs.k8s.io/controller-runtime v0.17.3 h1:65QmN7r3FWgTxDMz9fvGnO1kbf2nu+acg9p2R9oYYYk= sigs.k8s.io/controller-runtime v0.17.3/go.mod h1:N0jpP5Lo7lMTF9aL56Z/B2oWBJjey6StQM0jRbKQXtY= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= diff --git a/hack/tools/go.mod b/hack/tools/go.mod index 1c181c7f5..d448c867b 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -1,8 +1,8 @@ module sigs.k8s.io/cluster-api-provider-gcp/hack/tools -go 1.21.9 +go 1.21.10 -replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.7.1 +replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.7.2 require sigs.k8s.io/cluster-api/hack/tools v0.0.0-20240325211526-a53d4aa71661 diff --git a/hack/tools/go.sum b/hack/tools/go.sum index edb98e06a..dd705bea6 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -109,8 +109,8 @@ k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0= k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo= k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ= k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/cluster-api v1.7.1 h1:JkMAbAMzBM+WBHxXLTJXTiCisv1PAaHRzld/3qrmLYY= -sigs.k8s.io/cluster-api v1.7.1/go.mod h1:V9ZhKLvQtsDODwjXOKgbitjyCmC71yMBwDcMyNNIov0= +sigs.k8s.io/cluster-api v1.7.2 h1:bRE8zoao7ajuLC0HijqfZVcubKQCPlZ04HMgcA53FGE= +sigs.k8s.io/cluster-api v1.7.2/go.mod h1:V9ZhKLvQtsDODwjXOKgbitjyCmC71yMBwDcMyNNIov0= sigs.k8s.io/cluster-api/hack/tools v0.0.0-20240325211526-a53d4aa71661 h1:nSbbsL19ZwVzWq7+4PuH475FmA2Tu0YXVbH32lpk4Ts= sigs.k8s.io/cluster-api/hack/tools v0.0.0-20240325211526-a53d4aa71661/go.mod h1:5/Owkfx2pUBG+vdwmJtWpkFjKJJyr5MnjRg79SruzWc= sigs.k8s.io/controller-tools v0.14.0 h1:rnNoCC5wSXlrNoBKKzL70LNJKIQKEzT6lloG6/LF73A= diff --git a/netlify.toml b/netlify.toml index 54ade1966..c346207b2 100644 --- a/netlify.toml +++ b/netlify.toml @@ -4,7 +4,7 @@ publish = "docs/book/book" [build.environment] - GO_VERSION = "1.21.9" + GO_VERSION = "1.21.10" # Standard Netlify redirects [[redirects]] diff --git a/test/e2e/capi_test.go b/test/e2e/capi_test.go index 6396825c0..7614a2e71 100644 --- a/test/e2e/capi_test.go +++ b/test/e2e/capi_test.go @@ -30,9 +30,7 @@ import ( ) var _ = Describe("Running the Cluster API E2E tests", func() { - var ( - ctx = context.TODO() - ) + ctx := context.TODO() BeforeEach(func() { Expect(e2eConfig.Variables).To(HaveKey(capi_e2e.CNIPath)) @@ -111,5 +109,4 @@ var _ = Describe("Running the Cluster API E2E tests", func() { } }) }) - }) diff --git a/test/e2e/config/gcp-ci.yaml b/test/e2e/config/gcp-ci.yaml index 81e597f7a..058bff220 100644 --- a/test/e2e/config/gcp-ci.yaml +++ b/test/e2e/config/gcp-ci.yaml @@ -15,8 +15,8 @@ providers: - name: cluster-api type: CoreProvider versions: - - name: v1.7.1 - value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.1/core-components.yaml + - name: v1.7.2 + value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.2/core-components.yaml type: url files: - sourcePath: "../data/shared/v1beta1/metadata.yaml" @@ -28,8 +28,8 @@ providers: - name: kubeadm type: BootstrapProvider versions: - - name: v1.7.1 - value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.1/bootstrap-components.yaml + - name: v1.7.2 + value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.2/bootstrap-components.yaml type: url files: - sourcePath: "../data/shared/v1beta1/metadata.yaml" @@ -41,8 +41,8 @@ providers: - name: kubeadm type: ControlPlaneProvider versions: - - name: v1.7.1 - value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.1/control-plane-components.yaml + - name: v1.7.2 + value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.2/control-plane-components.yaml type: url files: - sourcePath: "../data/shared/v1beta1/metadata.yaml" diff --git a/test/e2e/conformance_test.go b/test/e2e/conformance_test.go index 357ef0260..41aa6f52b 100644 --- a/test/e2e/conformance_test.go +++ b/test/e2e/conformance_test.go @@ -54,7 +54,7 @@ var _ = Describe("Conformance Tests", func() { Expect(e2eConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName) Expect(clusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. clusterctlConfigPath must be an existing file when calling %s spec", specName) Expect(bootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. bootstrapClusterProxy can't be nil when calling %s spec", specName) - Expect(os.MkdirAll(artifactFolder, 0755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName) + Expect(os.MkdirAll(artifactFolder, 0o755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName) Expect(kubetestConfigFilePath).ToNot(BeNil(), "Invalid argument. kubetestConfigFilePath can't be nil") Expect(e2eConfig.Variables).To(HaveKey(KubernetesVersion)) diff --git a/test/e2e/e2e_gke_test.go b/test/e2e/e2e_gke_test.go index 7443c394d..d6fe45b93 100644 --- a/test/e2e/e2e_gke_test.go +++ b/test/e2e/e2e_gke_test.go @@ -53,7 +53,7 @@ var _ = Describe("GKE workload cluster creation", func() { Expect(e2eConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName) Expect(clusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. clusterctlConfigPath must be an existing file when calling %s spec", specName) Expect(bootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. bootstrapClusterProxy can't be nil when calling %s spec", specName) - Expect(os.MkdirAll(artifactFolder, 0755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName) + Expect(os.MkdirAll(artifactFolder, 0o755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName) Expect(e2eConfig.Variables).To(HaveKey(KubernetesVersion)) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index c690fb44e..cf36a585a 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -48,7 +48,7 @@ var _ = Describe("Workload cluster creation", func() { Expect(e2eConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName) Expect(clusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. clusterctlConfigPath must be an existing file when calling %s spec", specName) Expect(bootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. bootstrapClusterProxy can't be nil when calling %s spec", specName) - Expect(os.MkdirAll(artifactFolder, 0755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName) + Expect(os.MkdirAll(artifactFolder, 0o755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName) Expect(e2eConfig.Variables).To(HaveKey(KubernetesVersion)) diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index 5b271fb6a..5f8a1adf8 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -138,7 +138,7 @@ var _ = SynchronizedBeforeSuite(func() []byte { // Before all ParallelNodes. Expect(configPath).To(BeAnExistingFile(), "Invalid test suite argument. e2e.config should be an existing file.") - Expect(os.MkdirAll(artifactFolder, 0755)).To(Succeed(), "Invalid test suite argument. Can't create e2e.artifacts-folder %q", artifactFolder) + Expect(os.MkdirAll(artifactFolder, 0o755)).To(Succeed(), "Invalid test suite argument. Can't create e2e.artifacts-folder %q", artifactFolder) By("Initializing a runtime.Scheme with all the GVK relevant for this test") scheme := initScheme()