From bb4123346260b24063e54e99dc2fbcd79d1dad87 Mon Sep 17 00:00:00 2001 From: Kashif Khan Date: Mon, 4 Mar 2024 17:21:23 +0200 Subject: [PATCH] Bump golangci-lint to v1.56.2 Signed-off-by: Kashif Khan --- .github/workflows/golangci-lint.yml | 2 +- .golangci.yaml | 1 + baremetal/metal3data_manager.go | 16 +++++++++------- baremetal/metal3data_manager_test.go | 8 ++++---- baremetal/metal3machine_manager_test.go | 4 ++-- baremetal/metal3remediation_manager_test.go | 2 +- controllers/metal3labelsync_controller_test.go | 4 ++-- .../metal3machine_controller_integration_test.go | 2 +- controllers/metal3remediation_controller.go | 4 ++-- hack/ensure-golangci-lint.sh | 6 +++--- test/e2e/cert_rotation.go | 2 +- test/e2e/common.go | 3 ++- test/e2e/pivoting.go | 4 ++-- test/e2e/upgrade_clusterctl_test.go | 2 +- test/e2e/upgrade_ironic.go | 2 +- 15 files changed, 33 insertions(+), 29 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 4f69461fb5..9fd20b77ef 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -32,5 +32,5 @@ jobs: - name: golangci-lint-${{matrix.working-directory}} uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0 with: - version: v1.54.2 + version: v1.56.2 working-directory: ${{matrix.working-directory}} diff --git a/.golangci.yaml b/.golangci.yaml index 6354c5fd37..f754245bb9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -134,6 +134,7 @@ issues: linters: - unused - unparam + - goconst # Specific exclude rules for deprecated fields that are still part of the codebase. # These should be removed as the referenced deprecated item is removed from the project. - linters: diff --git a/baremetal/metal3data_manager.go b/baremetal/metal3data_manager.go index 3853ab6e80..bed0392001 100644 --- a/baremetal/metal3data_manager.go +++ b/baremetal/metal3data_manager.go @@ -44,11 +44,13 @@ import ( ) const ( - m3machine = "metal3machine" - host = "baremetalhost" - capimachine = "machine" - DataLabelName = "infrastructure.cluster.x-k8s.io/data-name" - PoolLabelName = "infrastructure.cluster.x-k8s.io/pool-name" + m3machine = "metal3machine" + host = "baremetalhost" + capimachine = "machine" + DataLabelName = "infrastructure.cluster.x-k8s.io/data-name" + PoolLabelName = "infrastructure.cluster.x-k8s.io/pool-name" + networkDataSuffix = "-networdata" + metaDataSuffix = "-metadata" ) var ( @@ -162,7 +164,7 @@ func (m *DataManager) createSecrets(ctx context.Context) error { // If the secret name is unset, set it if m.Data.Spec.MetaData == nil || m.Data.Spec.MetaData.Name == "" { m.Data.Spec.MetaData = &corev1.SecretReference{ - Name: m3m.Name + "-metadata", + Name: m3m.Name + metaDataSuffix, Namespace: m.Data.Namespace, } } @@ -188,7 +190,7 @@ func (m *DataManager) createSecrets(ctx context.Context) error { // If the secret name is unset, set it if m.Data.Spec.NetworkData == nil || m.Data.Spec.NetworkData.Name == "" { m.Data.Spec.NetworkData = &corev1.SecretReference{ - Name: m3m.Name + "-networkdata", + Name: m3m.Name + networkDataSuffix, Namespace: m.Data.Namespace, } } diff --git a/baremetal/metal3data_manager_test.go b/baremetal/metal3data_manager_test.go index c705522666..02fcf893b7 100644 --- a/baremetal/metal3data_manager_test.go +++ b/baremetal/metal3data_manager_test.go @@ -212,7 +212,7 @@ var _ = Describe("Metal3Data manager", func() { tmpSecret := corev1.Secret{} err = fakeClient.Get(context.TODO(), client.ObjectKey{ - Name: metal3machineName + "-metadata", + Name: metal3machineName + metaDataSuffix, Namespace: namespaceName, }, &tmpSecret, @@ -224,7 +224,7 @@ var _ = Describe("Metal3Data manager", func() { tmpSecret := corev1.Secret{} err = fakeClient.Get(context.TODO(), client.ObjectKey{ - Name: metal3machineName + "-networkdata", + Name: metal3machineName + networkDataSuffix, Namespace: namespaceName, }, &tmpSecret, @@ -370,13 +370,13 @@ var _ = Describe("Metal3Data manager", func() { Spec: infrav1.Metal3DataClaimSpec{}, }, metadataSecret: &corev1.Secret{ - ObjectMeta: testObjectMeta(metal3machineName+"-metadata", namespaceName, ""), + ObjectMeta: testObjectMeta(metal3machineName+metaDataSuffix, namespaceName, ""), Data: map[string][]byte{ "metaData": []byte("Hello"), }, }, networkdataSecret: &corev1.Secret{ - ObjectMeta: testObjectMeta(metal3machineName+"-networkdata", namespaceName, ""), + ObjectMeta: testObjectMeta(metal3machineName+networkDataSuffix, namespaceName, ""), Data: map[string][]byte{ "networkData": []byte("Bye"), }, diff --git a/baremetal/metal3machine_manager_test.go b/baremetal/metal3machine_manager_test.go index 35fd22eb4e..7d2703595e 100644 --- a/baremetal/metal3machine_manager_test.go +++ b/baremetal/metal3machine_manager_test.go @@ -2550,7 +2550,7 @@ var _ = Describe("Metal3Machine manager", func() { BMHHost := newBareMetalHost(baremetalhostName, nil, bmov1alpha1.StateNone, nil, false, "metadata", false, tc.HostID) fakeClient := fake.NewClientBuilder().WithScheme(s).WithObjects(BMHHost).Build() corev1Client := clientfake.NewSimpleClientset(tc.TargetObjects...).CoreV1() - m := func(ctx context.Context, client client.Client, cluster *clusterv1.Cluster) ( + m := func(_ context.Context, _ client.Client, _ *clusterv1.Cluster) ( clientcorev1.CoreV1Interface, error, ) { return corev1Client, nil @@ -2667,7 +2667,7 @@ var _ = Describe("Metal3Machine manager", func() { BMHHost := newBareMetalHost(baremetalhostName, nil, bmov1alpha1.StateNone, nil, false, "metadata", false, tc.HostID) fakeClient := fake.NewClientBuilder().WithScheme(s).WithObjects(BMHHost).Build() corev1Client := clientfake.NewSimpleClientset(tc.TargetObjects...).CoreV1() - m := func(ctx context.Context, client client.Client, cluster *clusterv1.Cluster) ( + m := func(_ context.Context, _ client.Client, _ *clusterv1.Cluster) ( clientcorev1.CoreV1Interface, error, ) { return corev1Client, nil diff --git a/baremetal/metal3remediation_manager_test.go b/baremetal/metal3remediation_manager_test.go index 21c081261c..dbb3a74cfa 100644 --- a/baremetal/metal3remediation_manager_test.go +++ b/baremetal/metal3remediation_manager_test.go @@ -953,7 +953,7 @@ var _ = Describe("Metal3Remediation manager", func() { corev1Client := clientfake.NewSimpleClientset(&corev1.Node{ObjectMeta: metav1.ObjectMeta{ Name: node.Name, }}).CoreV1() - clientGetter := func(ctx context.Context, client client.Client, cluster *clusterv1.Cluster) (clientcorev1.CoreV1Interface, error) { + clientGetter := func(_ context.Context, _ client.Client, _ *clusterv1.Cluster) (clientcorev1.CoreV1Interface, error) { return corev1Client, nil } remediationMgr, err := NewRemediationManager(fakeClient, clientGetter, m3Remediation, nil, capiMachine, diff --git a/controllers/metal3labelsync_controller_test.go b/controllers/metal3labelsync_controller_test.go index 48cdacd801..1226b85c4c 100644 --- a/controllers/metal3labelsync_controller_test.go +++ b/controllers/metal3labelsync_controller_test.go @@ -409,7 +409,7 @@ var _ = Describe("Metal3LabelSync controller", func() { Client: fakeClient, ManagerFactory: baremetal.NewManagerFactory(fakeClient), Log: logr.Discard(), - CapiClientGetter: func(ctx context.Context, client client.Client, cluster *clusterv1.Cluster) ( + CapiClientGetter: func(_ context.Context, _ client.Client, _ *clusterv1.Cluster) ( clientcorev1.CoreV1Interface, error, ) { return corev1Client, nil @@ -540,7 +540,7 @@ var _ = Describe("Metal3LabelSync controller", func() { Client: fakeClient, ManagerFactory: baremetal.NewManagerFactory(fakeClient), Log: logr.Discard(), - CapiClientGetter: func(ctx context.Context, client client.Client, cluster *clusterv1.Cluster) ( + CapiClientGetter: func(_ context.Context, _ client.Client, _ *clusterv1.Cluster) ( clientcorev1.CoreV1Interface, error, ) { return corev1Client, nil diff --git a/controllers/metal3machine_controller_integration_test.go b/controllers/metal3machine_controller_integration_test.go index 0455251456..d376203d05 100644 --- a/controllers/metal3machine_controller_integration_test.go +++ b/controllers/metal3machine_controller_integration_test.go @@ -197,7 +197,7 @@ var _ = Describe("Reconcile metal3machine", func() { oldProviderID := testBMmachine.Spec.ProviderID fakeClient := fake.NewClientBuilder().WithScheme(setupScheme()).WithObjects(tc.Objects...).WithStatusSubresource(tc.Objects...).Build() - mockCapiClientGetter := func(ctx context.Context, c client.Client, cluster *clusterv1.Cluster) ( + mockCapiClientGetter := func(_ context.Context, _ client.Client, _ *clusterv1.Cluster) ( clientcorev1.CoreV1Interface, error, ) { return clientfake.NewSimpleClientset(tc.TargetObjects...).CoreV1(), nil diff --git a/controllers/metal3remediation_controller.go b/controllers/metal3remediation_controller.go index 4492859ece..7e5699bbc9 100644 --- a/controllers/metal3remediation_controller.go +++ b/controllers/metal3remediation_controller.go @@ -376,7 +376,7 @@ func (r *Metal3RemediationReconciler) restoreNode(ctx context.Context, remediati } // set annotations - if len(annotations) > 0 { + if annotations != "" { nodeAnnotations, err := unmarshal(annotations) if err != nil { r.Log.Error(err, "failed to unmarshal node annotations", "node", node.Name, "annotations", annotations) @@ -389,7 +389,7 @@ func (r *Metal3RemediationReconciler) restoreNode(ctx context.Context, remediati } // set labels - if len(labels) > 0 { + if labels != "" { nodeLabels, err := unmarshal(labels) if err != nil { r.Log.Error(err, "failed to unmarshal node labels", "node", node.Name, "labels", labels) diff --git a/hack/ensure-golangci-lint.sh b/hack/ensure-golangci-lint.sh index 51de7685e7..aee12a0f93 100755 --- a/hack/ensure-golangci-lint.sh +++ b/hack/ensure-golangci-lint.sh @@ -60,10 +60,10 @@ download_and_install_golangci_lint() KERNEL_OS="$(uname | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" GOLANGCI_LINT="golangci-lint" - GOLANGCI_VERSION="1.54.2" + GOLANGCI_VERSION="1.56.2" case "${KERNEL_OS}-${ARCH}" in - darwin-arm64) GOLANGCI_SHA256="7b33fb1be2f26b7e3d1f3c10ce9b2b5ce6d13bb1d8468a4b2ba794f05b4445e1" ;; - linux-amd64) GOLANGCI_SHA256="17c9ca05253efe833d47f38caf670aad2202b5e6515879a99873fabd4c7452b3" ;; + darwin-arm64) GOLANGCI_SHA256="5f9ecda712c7ae08fbf872336fae3db866720e5865903d4c53903184b2a2c2dc" ;; + linux-amd64) GOLANGCI_SHA256="e1c313fb5fc85a33890fdee5dbb1777d1f5829c84d655a47a55688f3aad5e501" ;; *) echo >&2 "error:${KERNEL_OS}-${ARCH} not supported. Please obtain the binary and calculate sha256 manually." exit 1 diff --git a/test/e2e/cert_rotation.go b/test/e2e/cert_rotation.go index a85cc13351..1a02f3ce6b 100644 --- a/test/e2e/cert_rotation.go +++ b/test/e2e/cert_rotation.go @@ -32,7 +32,7 @@ func certRotation(ctx context.Context, inputGetter func() CertRotationInput) { mariadbEnabled := input.E2EConfig.GetVariable(ironicMariadb) == "true" By("Check if Ironic pod is running") ironicNamespace := input.E2EConfig.GetVariable("NAMEPREFIX") + "-system" - ironicDeploymentName := input.E2EConfig.GetVariable("NAMEPREFIX") + "-ironic" + ironicDeploymentName := input.E2EConfig.GetVariable("NAMEPREFIX") + ironicSuffix ironicDeployment, err := getDeployment(ctx, clusterClient, ironicDeploymentName, ironicNamespace) Eventually(func() error { ironicPod, err := getPodFromDeployment(ctx, clientSet, ironicDeployment, ironicNamespace) diff --git a/test/e2e/common.go b/test/e2e/common.go index f02a1857fb..b9972b98a7 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -49,6 +49,7 @@ const ( ironicImageDir = "/opt/metal3-dev-env/ironic/html/images" osTypeCentos = "centos" osTypeUbuntu = "ubuntu" + ironicSuffix = "-ironic" ) func Byf(format string, a ...interface{}) { @@ -651,7 +652,7 @@ func runCommand(logFolder, filename, machineIP, user, command string) error { Auth: []ssh.AuthMethod{ ssh.PublicKeys(signer), }, - HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil }, + HostKeyCallback: func(_ string, _ net.Addr, _ ssh.PublicKey) error { return nil }, Timeout: 60 * time.Second, } client, err := ssh.Dial("tcp", fmt.Sprintf("%s:22", machineIP), cfg) diff --git a/test/e2e/pivoting.go b/test/e2e/pivoting.go index 2489faf9a6..e0e513d67c 100644 --- a/test/e2e/pivoting.go +++ b/test/e2e/pivoting.go @@ -318,7 +318,7 @@ func installIronicBMO(ctx context.Context, inputGetter func() installIronicBMOIn Expect(er).ToNot(HaveOccurred(), "Failed to deploy Ironic") deploymentNameList := []string{} if input.deployIronic { - deploymentNameList = append(deploymentNameList, "-ironic") + deploymentNameList = append(deploymentNameList, ironicSuffix) } if input.deployBMO { deploymentNameList = append(deploymentNameList, "-controller-manager") @@ -345,7 +345,7 @@ type RemoveIronicInput struct { func removeIronic(ctx context.Context, inputGetter func() RemoveIronicInput) { input := inputGetter() if input.IsDeployment { - deploymentName := input.NamePrefix + "-ironic" + deploymentName := input.NamePrefix + ironicSuffix RemoveDeployment(ctx, func() RemoveDeploymentInput { return RemoveDeploymentInput{ ManagementCluster: input.ManagementCluster, diff --git a/test/e2e/upgrade_clusterctl_test.go b/test/e2e/upgrade_clusterctl_test.go index 2871faebd4..9afdad88ac 100644 --- a/test/e2e/upgrade_clusterctl_test.go +++ b/test/e2e/upgrade_clusterctl_test.go @@ -152,7 +152,7 @@ func preWaitForCluster(clusterProxy framework.ClusterProxy, clusterNamespace str } // Create the BMHs needed in the hosting namespace. - createBMH := func(clusterProxy framework.ClusterProxy, clusterNamespace string, clusterName string) { + createBMH := func(clusterProxy framework.ClusterProxy, clusterNamespace string, _ string) { installSplitYAML() splitFiles := splitYAMLFile("bmhosts_crs.yaml", workDir) // Check which from which cluster creation this call is coming diff --git a/test/e2e/upgrade_ironic.go b/test/e2e/upgrade_ironic.go index 34f54de0e7..99cc7b777c 100644 --- a/test/e2e/upgrade_ironic.go +++ b/test/e2e/upgrade_ironic.go @@ -24,7 +24,7 @@ func upgradeIronic(ctx context.Context, inputGetter func() upgradeIronicInput) { clientSet = input.ManagementCluster.GetClientSet() namePrefix = input.E2EConfig.GetVariable("NAMEPREFIX") ironicNamespace = input.E2EConfig.GetVariable("IRONIC_NAMESPACE") - ironicDeployName = namePrefix + "-ironic" + ironicDeployName = namePrefix + ironicSuffix containerRegistry = input.E2EConfig.GetVariable("CONTAINER_REGISTRY") ironicImageTag = input.E2EConfig.GetVariable("IRONIC_IMAGE_TAG") )