diff --git a/.github/workflows/pr-golangci-lint.yaml b/.github/workflows/pr-golangci-lint.yaml index 6b2a4fbafa..a8b0a48df2 100644 --- a/.github/workflows/pr-golangci-lint.yaml +++ b/.github/workflows/pr-golangci-lint.yaml @@ -28,7 +28,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@0a35821d5c230e903fcfe077583637dea1b27b47 # tag=v9.0.0 with: - version: v2.1.0 + version: v2.7.0 working-directory: ${{matrix.working-directory}} - name: Lint API run: make lint-api diff --git a/.golangci.yml b/.golangci.yml index 0dd639567a..049326f622 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -297,6 +297,38 @@ linters: 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: + - revive + path: 'exp/utils/*' + text: 'var-naming: avoid meaningless package names' + - linters: + - revive + path: 'cmd/clusterawsadm/cmd/ami/common' + text: 'var-naming: avoid meaningless package names' + - linters: + - revive + path: 'cmd/clusterawsadm/cmd/util' + text: 'var-naming: avoid meaningless package names' + - linters: + - revive + path: 'pkg/utils' + text: 'var-naming: avoid meaningless package names' + - linters: + - revive + path: 'pkg/cloud/services/common/' + text: 'var-naming: avoid meaningless package names' + - linters: + - revive + path: 'test/e2e/shared/' + text: 'var-naming: avoid meaningless package names' + - linters: + - revive + text: 'avoid package names that conflict with Go standard library package names' + path: 'pkg/internal/bytes/' + - linters: + - revive + text: 'avoid package names that conflict with Go standard library package names' + path: 'pkg/hash/' - linters: - unparam text: always receives @@ -330,6 +362,9 @@ linters: - linters: - staticcheck text: 'SA1019: "sigs.k8s.io/cluster-api/(.*)" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.' + - linters: + - staticcheck + text: "s.scope.ControlPlaneLoadBalancer is deprecated" paths: - third_party$ - builtin$ diff --git a/api/v1beta1/types.go b/api/v1beta1/types.go index 55ec56b0c7..5002243fd4 100644 --- a/api/v1beta1/types.go +++ b/api/v1beta1/types.go @@ -32,6 +32,7 @@ type AWSResourceReference struct { // ARN of resource. // +optional + // // Deprecated: This field has no function and is going to be removed in the next release. ARN *string `json:"arn,omitempty"` diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml index 4f871ecdc2..81cfd85073 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml @@ -80,6 +80,7 @@ spec: arn: description: |- ARN of resource. + Deprecated: This field has no function and is going to be removed in the next release. type: string filters: @@ -344,6 +345,7 @@ spec: arn: description: |- ARN of resource. + Deprecated: This field has no function and is going to be removed in the next release. type: string filters: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml index f8f0b32215..ac7689c7de 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml @@ -91,6 +91,7 @@ spec: arn: description: |- ARN of resource. + Deprecated: This field has no function and is going to be removed in the next release. type: string filters: @@ -360,6 +361,7 @@ spec: arn: description: |- ARN of resource. + Deprecated: This field has no function and is going to be removed in the next release. type: string filters: diff --git a/hack/tools/.custom-gcl.yaml b/hack/tools/.custom-gcl.yaml index 5253dd8852..9fbc2e1cac 100644 --- a/hack/tools/.custom-gcl.yaml +++ b/hack/tools/.custom-gcl.yaml @@ -1,4 +1,4 @@ -version: v2.1.0 +version: v2.7.0 name: golangci-lint-kube-api-linter destination: ./bin plugins: diff --git a/pkg/cloud/converters/eks.go b/pkg/cloud/converters/eks.go index 94b008cdc2..243b6d9cbd 100644 --- a/pkg/cloud/converters/eks.go +++ b/pkg/cloud/converters/eks.go @@ -189,11 +189,11 @@ func NodegroupUpdateconfigToSDK(updateConfig *expinfrav1.UpdateConfig) (*ekstype converted := &ekstypes.NodegroupUpdateConfig{} if updateConfig.MaxUnavailable != nil { - //nolint:gosec,G115 // Added golint exception as there is a kubebuilder validation configured + //nolint:G115 // Added golint exception as there is a kubebuilder validation configured converted.MaxUnavailable = aws.Int32(int32(*updateConfig.MaxUnavailable)) } if updateConfig.MaxUnavailablePercentage != nil { - //nolint:gosec,G115 // Added golint exception as there is a kubebuilder validation configured + //nolint:G115 // Added golint exception as there is a kubebuilder validation configured converted.MaxUnavailablePercentage = aws.Int32(int32(*updateConfig.MaxUnavailablePercentage)) } diff --git a/pkg/cloud/scope/cluster.go b/pkg/cloud/scope/cluster.go index cd51b966f2..c6a064d43e 100644 --- a/pkg/cloud/scope/cluster.go +++ b/pkg/cloud/scope/cluster.go @@ -209,6 +209,7 @@ func (s *ClusterScope) ControlPlaneLoadBalancers() []*infrav1.AWSLoadBalancerSpe } // ControlPlaneLoadBalancerScheme returns the Classic ELB scheme (public or internal facing). +// // Deprecated: This method is going to be removed in a future release. Use LoadBalancer.Scheme. func (s *ClusterScope) ControlPlaneLoadBalancerScheme() infrav1.ELBScheme { if s.ControlPlaneLoadBalancer() != nil && s.ControlPlaneLoadBalancer().Scheme != nil { diff --git a/pkg/cloud/scope/elb.go b/pkg/cloud/scope/elb.go index 8d092a92ee..0736cd3711 100644 --- a/pkg/cloud/scope/elb.go +++ b/pkg/cloud/scope/elb.go @@ -39,10 +39,12 @@ type ELBScope interface { VPC() *infrav1.VPCSpec // ControlPlaneLoadBalancer returns the AWSLoadBalancerSpec + // // Deprecated: Use ControlPlaneLoadBalancers() ControlPlaneLoadBalancer() *infrav1.AWSLoadBalancerSpec // ControlPlaneLoadBalancerScheme returns the Classic ELB scheme (public or internal facing) + // // Deprecated: This method is going to be removed in a future release. Use LoadBalancer.Scheme. ControlPlaneLoadBalancerScheme() infrav1.ELBScheme diff --git a/pkg/cloud/scope/sg.go b/pkg/cloud/scope/sg.go index 05409d835c..fd792ccb52 100644 --- a/pkg/cloud/scope/sg.go +++ b/pkg/cloud/scope/sg.go @@ -44,6 +44,7 @@ type SGScope interface { Bastion() *infrav1.Bastion // ControlPlaneLoadBalancer returns the load balancer settings that are requested. + // // Deprecated: Use ControlPlaneLoadBalancers() ControlPlaneLoadBalancer() *infrav1.AWSLoadBalancerSpec diff --git a/pkg/cloud/services/ec2/dedicatedhosts.go b/pkg/cloud/services/ec2/dedicatedhosts.go index 73b06c90db..676fe6451f 100644 --- a/pkg/cloud/services/ec2/dedicatedhosts.go +++ b/pkg/cloud/services/ec2/dedicatedhosts.go @@ -223,7 +223,7 @@ func (s *Service) convertToHostInfo(host types.Host) *infrav1.DedicatedHostInfo instanceCount = math.MaxInt32 } // bounds check ensures instanceCount <= math.MaxInt32, preventing integer overflow - usedCapacity := int32(instanceCount) //nolint:gosec + usedCapacity := int32(instanceCount) hostInfo.AvailableCapacity = hostInfo.TotalCapacity - usedCapacity // Convert tags diff --git a/pkg/cloud/services/ec2/instances.go b/pkg/cloud/services/ec2/instances.go index 95ad690860..7a311a9326 100644 --- a/pkg/cloud/services/ec2/instances.go +++ b/pkg/cloud/services/ec2/instances.go @@ -594,7 +594,7 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan for index, id := range i.NetworkInterfaces { netInterfaces = append(netInterfaces, types.InstanceNetworkInterfaceSpecification{ NetworkInterfaceId: aws.String(id), - DeviceIndex: aws.Int32(int32(index)), //nolint:gosec // disable G115 + DeviceIndex: aws.Int32(int32(index)), }) } netInterfaces[0].AssociatePublicIpAddress = i.PublicIPOnLaunch diff --git a/test/e2e/shared/aws.go b/test/e2e/shared/aws.go index ca6adde95b..ae5723b6f7 100644 --- a/test/e2e/shared/aws.go +++ b/test/e2e/shared/aws.go @@ -764,7 +764,7 @@ func ensureTestImageUploaded(ctx context.Context, e2eCtx *E2EContext) error { return err } - cmd := exec.Command("docker", "inspect", "--format='{{index .Id}}'", "gcr.io/k8s-staging-cluster-api/capa-manager:e2e") + cmd := exec.CommandContext(ctx, "docker", "inspect", "--format='{{index .Id}}'", "gcr.io/k8s-staging-cluster-api/capa-manager:e2e") var stdOut bytes.Buffer cmd.Stdout = &stdOut err := cmd.Run() @@ -775,7 +775,7 @@ func ensureTestImageUploaded(ctx context.Context, e2eCtx *E2EContext) error { imageSha := strings.ReplaceAll(strings.TrimSuffix(stdOut.String(), "\n"), "'", "") ecrImageName := repoName + ":e2e" - cmd = exec.Command("docker", "tag", imageSha, ecrImageName) //nolint:gosec + cmd = exec.CommandContext(ctx, "docker", "tag", imageSha, ecrImageName) //nolint:gosec err = cmd.Run() if err != nil { return err @@ -794,13 +794,13 @@ func ensureTestImageUploaded(ctx context.Context, e2eCtx *E2EContext) error { return errors.New("failed to decode ECR authentication token") } - cmd = exec.Command("docker", "login", "--username", strList[0], "--password", strList[1], "public.ecr.aws") //nolint:gosec + cmd = exec.CommandContext(ctx, "docker", "login", "--username", strList[0], "--password", strList[1], "public.ecr.aws") //nolint:gosec err = cmd.Run() if err != nil { return err } - cmd = exec.Command("docker", "push", ecrImageName) + cmd = exec.CommandContext(ctx, "docker", "push", ecrImageName) err = cmd.Run() if err != nil { return err diff --git a/test/e2e/shared/suite.go b/test/e2e/shared/suite.go index a5baf7ef48..2192a1d9b1 100644 --- a/test/e2e/shared/suite.go +++ b/test/e2e/shared/suite.go @@ -89,7 +89,7 @@ func Node1BeforeSuite(e2eCtx *E2EContext) []byte { templateDir := path.Join(e2eCtx.Settings.ArtifactFolder, "templates") newTemplatePath := templateDir + "/" + ciTemplateForUpgradeName - err = exec.Command("cp", ciTemplateForUpgradePath, newTemplatePath).Run() //nolint:gosec + err = exec.CommandContext(context.TODO(), "cp", ciTemplateForUpgradePath, newTemplatePath).Run() //nolint:gosec Expect(err).NotTo(HaveOccurred()) clusterctlCITemplateForUpgrade := clusterctl.Files{ diff --git a/test/helpers/envtest.go b/test/helpers/envtest.go index 56030a879d..60be9b5a45 100644 --- a/test/helpers/envtest.go +++ b/test/helpers/envtest.go @@ -271,7 +271,8 @@ func (t *TestEnvironment) WaitForWebhooks() { timeout := 1 * time.Second for { time.Sleep(1 * time.Second) - conn, err := net.DialTimeout("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(port)), timeout) + dialer := &net.Dialer{Timeout: timeout} + conn, err := dialer.DialContext(context.Background(), "tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(port))) if err != nil { klog.V(2).Infof("Webhook port is not ready, will retry in %v: %s", timeout, err) continue diff --git a/test/helpers/kubernetesversions/template.go b/test/helpers/kubernetesversions/template.go index aab1915763..961e4d7950 100644 --- a/test/helpers/kubernetesversions/template.go +++ b/test/helpers/kubernetesversions/template.go @@ -22,6 +22,7 @@ package kubernetesversions import ( "bytes" + "context" _ "embed" "errors" "fmt" @@ -128,7 +129,7 @@ func GenerateCIArtifactsInjectedTemplateForDebian(input GenerateCIArtifactsInjec if err := os.WriteFile(path.Join(overlayDir, "platform-kustomization.yaml"), input.PlatformKustomization, 0o600); err != nil { return "", err } - cmd := exec.Command("kustomize", "build", overlayDir) //nolint:gosec // We don't care about command injection here. + cmd := exec.CommandContext(context.TODO(), "kustomize", "build", overlayDir) //nolint:gosec // We don't care about command injection here. data, err := cmd.CombinedOutput() if err != nil { return "", err diff --git a/versions.mk b/versions.mk index 0fbd4751d0..9f3c04ac92 100644 --- a/versions.mk +++ b/versions.mk @@ -18,6 +18,6 @@ CERT_MANAGER_VERSION := v1.17.2 CAPI_VERSION := v1.11.1 KPROMO_VERSION := v4.0.5 YQ_VERSION := v4.25.2 -GOLANGCI_LINT_VERSION := v2.1.0 +GOLANGCI_LINT_VERSION := v2.7.0 RELEASE_NOTES_VERSION := v0.16.5 GORELEASER_VERSION := v1.24.0