From 9e4025370494759accb1997c81f79f7a05451a09 Mon Sep 17 00:00:00 2001 From: Nikhil-Ladha Date: Wed, 13 Dec 2023 11:19:36 +0530 Subject: [PATCH 1/2] update golangci-lint to 1.54.2 Updated golangci-lint to 1.54.2 Signed-off-by: Nikhil-Ladha --- .github/workflows/ocs-operator-ci.yaml | 7 ++----- hack/common.sh | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ocs-operator-ci.yaml b/.github/workflows/ocs-operator-ci.yaml index 8c62a52500..05c7f9e690 100644 --- a/.github/workflows/ocs-operator-ci.yaml +++ b/.github/workflows/ocs-operator-ci.yaml @@ -37,11 +37,8 @@ jobs: - uses: golangci/golangci-lint-action@v3 with: - version: v1.51.2 - - # The weird NO_FUTURE thing is a workaround suggested here: - # # https://github.com/golangci/golangci-lint-action/issues/119#issuecomment-981090648 - args: "--out-${NO_FUTURE}format=colored-line-number --timeout=6m ./..." + version: v1.54.2 + args: "--out-format=colored-line-number --timeout=6m ./..." go-test: name: go test diff --git a/hack/common.sh b/hack/common.sh index 7ec1991004..9c888db6b8 100644 --- a/hack/common.sh +++ b/hack/common.sh @@ -25,7 +25,7 @@ OPERATOR_SDK="${LOCALBIN}/operator-sdk-${OPERATOR_SDK_VERSION}" OPM_VERSION="v1.28.0" OPM="${LOCALBIN}/opm-${OPM_VERSION}" GINKGO="${LOCALBIN}/ginkgo" -GOLANGCI_LINT_VERSION="v1.51.1" +GOLANGCI_LINT_VERSION="v1.54.2" GOLANGCI_LINT="${LOCALBIN}/golangci-lint" SHELLCHECK_VERSION="v0.9.0" SHELLCHECK="${LOCALBIN}/shellcheck" From 7d5c9fc970d25857b2029d0128120afd4ea0cce8 Mon Sep 17 00:00:00 2001 From: Nikhil-Ladha Date: Wed, 13 Dec 2023 13:05:48 +0530 Subject: [PATCH 2/2] fix errors reported by golangci-lint Fixed errors reported by golangci-lint after upgrading to 1.54.2 Signed-off-by: Nikhil-Ladha --- .../storagecluster/backingstorageclasses.go | 2 +- .../storagecluster/cephblockpools_test.go | 2 +- controllers/storagecluster/cephcluster.go | 14 ++++++------ .../storagecluster/cephcluster_test.go | 22 +++++++++---------- controllers/storagecluster/cephconfig.go | 2 +- controllers/storagecluster/cephfilesystem.go | 15 ++++++------- .../storagecluster/cephfilesystem_test.go | 4 ++-- controllers/storagecluster/cephnfs_test.go | 2 +- .../storagecluster/cephobjectstores_test.go | 2 +- .../cephobjectstoreusers_test.go | 2 +- .../storagecluster/cephrbdmirrors_test.go | 4 ++-- controllers/storagecluster/exporter.go | 5 ++--- .../storagecluster/external_resources.go | 6 ++--- controllers/storagecluster/generate.go | 6 ----- .../initialization_reconciler_test.go | 2 +- controllers/storagecluster/job_templates.go | 2 +- .../operator_conditions_test.go | 2 +- controllers/storagecluster/reconcile.go | 21 +++++++++--------- controllers/storagecluster/routes_test.go | 2 +- controllers/storagecluster/storageclasses.go | 2 +- .../storagecluster_controller_test.go | 2 +- controllers/storagecluster/topology.go | 2 +- .../storagecluster/uninstall_reconciler.go | 14 ++++++------ .../uninstall_reconciler_test.go | 12 +++++----- .../volumesnapshotterclasses.go | 6 ++--- .../volumesnapshotterclasses_test.go | 7 +++--- .../storageconsumer_controller.go | 1 + metrics/internal/cache/ceph-blocklist.go | 10 ++++----- metrics/internal/cache/pv.go | 4 ++-- metrics/internal/cache/rbd-mirror.go | 4 ++-- .../collectors/cluster-advance-feature-use.go | 12 +++++----- metrics/internal/collectors/rbd-mirror.go | 3 +-- metrics/internal/collectors/registry.go | 2 +- .../internal/collectors/storageconsumer.go | 4 ++-- pkg/deploy-manager/storagecluster.go | 12 +++++----- services/provider/server/server.go | 2 +- services/provider/server/server_test.go | 6 ++--- .../provider/server/storageclassrequest.go | 2 +- 38 files changed, 106 insertions(+), 118 deletions(-) diff --git a/controllers/storagecluster/backingstorageclasses.go b/controllers/storagecluster/backingstorageclasses.go index 5042c8e895..76be292d1a 100644 --- a/controllers/storagecluster/backingstorageclasses.go +++ b/controllers/storagecluster/backingstorageclasses.go @@ -133,7 +133,7 @@ func createOrUpdateBackingStorageclass(r *StorageClusterReconciler, bsc *ocsv1.B } // ensureDeleted deletes the backing storageclasses -func (obj *backingStorageClasses) ensureDeleted(r *StorageClusterReconciler, sc *ocsv1.StorageCluster) (reconcile.Result, error) { +func (obj *backingStorageClasses) ensureDeleted(r *StorageClusterReconciler, _ *ocsv1.StorageCluster) (reconcile.Result, error) { existingBackingStorageClasses := &v1.StorageClassList{} err := r.Client.List( r.ctx, diff --git a/controllers/storagecluster/cephblockpools_test.go b/controllers/storagecluster/cephblockpools_test.go index 7d7125f203..e621c4a46a 100644 --- a/controllers/storagecluster/cephblockpools_test.go +++ b/controllers/storagecluster/cephblockpools_test.go @@ -39,7 +39,7 @@ func TestCephBlockPools(t *testing.T) { t, reconciler, cr, request := initStorageClusterResourceCreateUpdateTestWithPlatform( t, cp, objects, nil) if c.createRuntimeObjects { - objects = createUpdateRuntimeObjects(t, cp, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime + objects = createUpdateRuntimeObjects(t, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime } assertCephBlockPools(t, reconciler, cr, request, false, false) assertCephNFSBlockPool(t, reconciler, cr, request) diff --git a/controllers/storagecluster/cephcluster.go b/controllers/storagecluster/cephcluster.go index 389f48edd1..35945d8b5d 100644 --- a/controllers/storagecluster/cephcluster.go +++ b/controllers/storagecluster/cephcluster.go @@ -165,7 +165,7 @@ func (obj *ocsCephCluster) ensureCreated(r *StorageClusterReconciler, sc *ocsv1. return reconcile.Result{}, err } r.Log.Info("Monitoring Information found. Monitoring will be enabled on the external cluster.", "CephCluster", klog.KRef(sc.Namespace, sc.Name)) - cephCluster = newExternalCephCluster(sc, r.images.Ceph, monitoringIP, monitoringPort) + cephCluster = newExternalCephCluster(sc, monitoringIP, monitoringPort) } else { // Add KMS details to CephCluster spec, only if // cluster-wide encryption is enabled @@ -190,12 +190,12 @@ func (obj *ocsCephCluster) ensureCreated(r *StorageClusterReconciler, sc *ocsv1. return reconcile.Result{}, err } } - cephCluster, err = newCephCluster(sc, r.images.Ceph, r.nodeCount, r.serverVersion, kmsConfigMap, r.Log) + cephCluster, err = newCephCluster(sc, r.images.Ceph, r.serverVersion, kmsConfigMap, r.Log) if err != nil { return reconcile.Result{}, err } } else { - cephCluster, err = newCephCluster(sc, r.images.Ceph, r.nodeCount, r.serverVersion, nil, r.Log) + cephCluster, err = newCephCluster(sc, r.images.Ceph, r.serverVersion, nil, r.Log) if err != nil { return reconcile.Result{}, err } @@ -397,7 +397,7 @@ func getCephClusterMonitoringLabels(sc ocsv1.StorageCluster) map[string]string { } // newCephCluster returns a CephCluster object. -func newCephCluster(sc *ocsv1.StorageCluster, cephImage string, nodeCount int, serverVersion *version.Info, kmsConfigMap *corev1.ConfigMap, reqLogger logr.Logger) (*rookCephv1.CephCluster, error) { +func newCephCluster(sc *ocsv1.StorageCluster, cephImage string, serverVersion *version.Info, kmsConfigMap *corev1.ConfigMap, reqLogger logr.Logger) (*rookCephv1.CephCluster, error) { labels := map[string]string{ "app": sc.Name, } @@ -585,7 +585,7 @@ func getNetworkSpec(sc ocsv1.StorageCluster) rookCephv1.NetworkSpec { return networkSpec } -func newExternalCephCluster(sc *ocsv1.StorageCluster, cephImage, monitoringIP, monitoringPort string) *rookCephv1.CephCluster { +func newExternalCephCluster(sc *ocsv1.StorageCluster, monitoringIP, monitoringPort string) *rookCephv1.CephCluster { labels := map[string]string{ "app": sc.Name, } @@ -1131,7 +1131,7 @@ func createPrometheusRules(r *StorageClusterReconciler, sc *ocsv1.StorageCluster changePromRuleExpr(prometheusRule, replaceTokens) } - if err := createOrUpdatePrometheusRule(r, sc, prometheusRule); err != nil { + if err := createOrUpdatePrometheusRule(r, prometheusRule); err != nil { r.Log.Error(err, "Prometheus rules could not be created.", "CephCluster", klog.KRef(cluster.Namespace, cluster.Name)) return err } @@ -1199,7 +1199,7 @@ func parsePrometheusRule(rules string) (*monitoringv1.PrometheusRule, error) { } // createOrUpdatePrometheusRule creates a prometheusRule object or an error -func createOrUpdatePrometheusRule(r *StorageClusterReconciler, sc *ocsv1.StorageCluster, prometheusRule *monitoringv1.PrometheusRule) error { +func createOrUpdatePrometheusRule(r *StorageClusterReconciler, prometheusRule *monitoringv1.PrometheusRule) error { name := prometheusRule.GetName() namespace := prometheusRule.GetNamespace() client, err := getMonitoringClient() diff --git a/controllers/storagecluster/cephcluster_test.go b/controllers/storagecluster/cephcluster_test.go index 1650f74468..f72e67bfcb 100644 --- a/controllers/storagecluster/cephcluster_test.go +++ b/controllers/storagecluster/cephcluster_test.go @@ -92,7 +92,7 @@ func TestEnsureCephCluster(t *testing.T) { reconciler := createFakeStorageClusterReconciler(t, networkConfig) - expected, err := newCephCluster(mockStorageCluster.DeepCopy(), "", 3, reconciler.serverVersion, nil, log) + expected, err := newCephCluster(mockStorageCluster.DeepCopy(), "", reconciler.serverVersion, nil, log) assert.NilError(t, err) expected.Status.State = c.cephClusterState @@ -210,7 +210,7 @@ func TestCephClusterMonTimeout(t *testing.T) { _, err := obj.ensureCreated(&reconciler, sc) assert.NilError(t, err) - cc, err := newCephCluster(sc, "", 3, reconciler.serverVersion, nil, log) + cc, err := newCephCluster(sc, "", reconciler.serverVersion, nil, log) assert.NilError(t, err) err = reconciler.Client.Get(context.TODO(), mockCephClusterNamespacedName, cc) assert.NilError(t, err) @@ -276,7 +276,7 @@ func TestNewCephClusterMonData(t *testing.T) { c.sc.Spec.MonDataDirHostPath = c.monDataPath c.sc.Status.Images.Ceph = &api.ComponentImageStatus{} - actual, err := newCephCluster(c.sc, "", 3, serverVersion, nil, log) + actual, err := newCephCluster(c.sc, "", serverVersion, nil, log) assert.NilError(t, err) assert.Equal(t, generateNameForCephCluster(c.sc), actual.Name) assert.Equal(t, c.sc.Namespace, actual.Namespace) @@ -1323,13 +1323,13 @@ func TestLogCollector(t *testing.T) { sc.Spec.LogCollector = &defaultLogCollector r := createFakeStorageClusterReconciler(t) - actual, err := newCephCluster(sc, "", 3, r.serverVersion, nil, log) + actual, err := newCephCluster(sc, "", r.serverVersion, nil, log) assert.NilError(t, err) assert.DeepEqual(t, actual.Spec.LogCollector, defaultLogCollector) // when disabled in storageCluster sc.Spec.LogCollector = &cephv1.LogCollectorSpec{} - actual, err = newCephCluster(sc, "", 3, r.serverVersion, nil, log) + actual, err = newCephCluster(sc, "", r.serverVersion, nil, log) assert.NilError(t, err) assert.DeepEqual(t, actual.Spec.LogCollector, defaultLogCollector) @@ -1337,7 +1337,7 @@ func TestLogCollector(t *testing.T) { assert.NilError(t, err) sc.Spec.LogCollector.MaxLogSize = &maxLogSize - actual, err = newCephCluster(sc, "", 3, r.serverVersion, nil, log) + actual, err = newCephCluster(sc, "", r.serverVersion, nil, log) assert.NilError(t, err) assert.DeepEqual(t, actual.Spec.LogCollector.MaxLogSize, &maxLogSize) } @@ -1466,7 +1466,7 @@ func TestCephClusterNetworkConnectionsSpec(t *testing.T) { mockStorageCluster.DeepCopyInto(sc) sc.Spec.Network = testCase.scSpec.Network sc.Spec.ExternalStorage.Enable = true - cc := newExternalCephCluster(sc, "", "", "") + cc := newExternalCephCluster(sc, "", "") assert.DeepEqual(t, cc.Spec.Network.Connections, testCase.ccSpec.Network.Connections) } // Test for internal mode @@ -1478,7 +1478,7 @@ func TestCephClusterNetworkConnectionsSpec(t *testing.T) { sc.Spec.Network = testCase.scSpec.Network reconciler := createFakeStorageClusterReconciler(t) testCase.ccSpec.Network.Connections.RequireMsgr2 = true - cc, _ := newCephCluster(sc, "", 3, reconciler.serverVersion, nil, log) + cc, _ := newCephCluster(sc, "", reconciler.serverVersion, nil, log) assert.DeepEqual(t, cc.Spec.Network.Connections, testCase.ccSpec.Network.Connections) } } @@ -1552,7 +1552,7 @@ func TestCephClusterStoreType(t *testing.T) { r := createFakeStorageClusterReconciler(t) t.Run("ensure no bluestore optimization", func(t *testing.T) { - actual, err := newCephCluster(sc, "", 3, r.serverVersion, nil, log) + actual, err := newCephCluster(sc, "", r.serverVersion, nil, log) assert.NilError(t, err) assert.Equal(t, "", actual.Spec.Storage.Store.Type) }) @@ -1562,14 +1562,14 @@ func TestCephClusterStoreType(t *testing.T) { DisasterRecoveryTargetAnnotation: "true", } sc.Annotations = annotations - actual, err := newCephCluster(sc, "", 3, r.serverVersion, nil, log) + actual, err := newCephCluster(sc, "", r.serverVersion, nil, log) assert.NilError(t, err) assert.Equal(t, "bluestore-rdr", actual.Spec.Storage.Store.Type) }) t.Run("ensure no bluestore optimization for external clusters", func(t *testing.T) { sc.Spec.ExternalStorage.Enable = true - actual, err := newCephCluster(sc, "", 3, r.serverVersion, nil, log) + actual, err := newCephCluster(sc, "", r.serverVersion, nil, log) assert.NilError(t, err) assert.Equal(t, "", actual.Spec.Storage.Store.Type) }) diff --git a/controllers/storagecluster/cephconfig.go b/controllers/storagecluster/cephconfig.go index 383ee655f6..26e2a06b9f 100644 --- a/controllers/storagecluster/cephconfig.go +++ b/controllers/storagecluster/cephconfig.go @@ -103,7 +103,7 @@ func (obj *ocsCephConfig) ensureCreated(r *StorageClusterReconciler, sc *ocsv1.S } // ensureDeleted is dummy func for the ocsCephConfig -func (obj *ocsCephConfig) ensureDeleted(r *StorageClusterReconciler, instance *ocsv1.StorageCluster) (reconcile.Result, error) { +func (obj *ocsCephConfig) ensureDeleted(_ *StorageClusterReconciler, _ *ocsv1.StorageCluster) (reconcile.Result, error) { return reconcile.Result{}, nil } diff --git a/controllers/storagecluster/cephfilesystem.go b/controllers/storagecluster/cephfilesystem.go index 7ff1daae97..ebe6a3eaed 100644 --- a/controllers/storagecluster/cephfilesystem.go +++ b/controllers/storagecluster/cephfilesystem.go @@ -80,12 +80,11 @@ func (r *StorageClusterReconciler) newCephFilesystemInstances(initStorageCluster return nil, updateErr } continue - } else { - storageProfile.Status.Phase = "" - if updateErr := r.Client.Status().Update(r.ctx, &storageProfile); updateErr != nil { - r.Log.Error(updateErr, "Could not update StorageProfile.", "StorageProfile", klog.KRef(storageProfile.Namespace, storageProfile.Name)) - return nil, updateErr - } + } + storageProfile.Status.Phase = "" + if updateErr := r.Client.Status().Update(r.ctx, &storageProfile); updateErr != nil { + r.Log.Error(updateErr, "Could not update StorageProfile.", "StorageProfile", klog.KRef(storageProfile.Namespace, storageProfile.Name)) + return nil, updateErr } parameters := spSpec.SharedFilesystemConfiguration.Parameters ret.Spec.DataPools = append(ret.Spec.DataPools, cephv1.NamedPoolSpec{ @@ -203,7 +202,7 @@ func (r *StorageClusterReconciler) createDefaultSubvolumeGroup(filesystemName, f return nil } -func (r *StorageClusterReconciler) deleteDefaultSubvolumeGroup(filesystemName, filesystemNamespace string, ownerReferences []metav1.OwnerReference) error { +func (r *StorageClusterReconciler) deleteDefaultSubvolumeGroup(filesystemName, filesystemNamespace string) error { existingsvg := &cephv1.CephFilesystemSubVolumeGroup{} svgName := generateNameForCephSubvolumeGroup(filesystemName) err := r.Client.Get(r.ctx, types.NamespacedName{Name: svgName, Namespace: filesystemNamespace}, existingsvg) @@ -259,7 +258,7 @@ func (obj *ocsCephFilesystems) ensureDeleted(r *StorageClusterReconciler, sc *oc // skip for the ocs provider mode if !sc.Spec.AllowRemoteStorageConsumers { cephSVGName := generateNameForCephSubvolumeGroup(cephFilesystem.Name) - err = r.deleteDefaultSubvolumeGroup(cephFilesystem.Name, cephFilesystem.Namespace, cephFilesystem.ObjectMeta.OwnerReferences) + err = r.deleteDefaultSubvolumeGroup(cephFilesystem.Name, cephFilesystem.Namespace) if err != nil { r.Log.Error(err, "Uninstall: unable to delete subvolumegroup", "subvolumegroup", klog.KRef(cephFilesystem.Namespace, cephSVGName)) return reconcile.Result{}, err diff --git a/controllers/storagecluster/cephfilesystem_test.go b/controllers/storagecluster/cephfilesystem_test.go index 28dfdc32dd..e8999ba223 100644 --- a/controllers/storagecluster/cephfilesystem_test.go +++ b/controllers/storagecluster/cephfilesystem_test.go @@ -33,7 +33,7 @@ func TestCephFileSystem(t *testing.T) { t, reconciler, cr, request := initStorageClusterResourceCreateUpdateTestWithPlatform( t, cp, objects, nil) if c.createRuntimeObjects { - objects = createUpdateRuntimeObjects(t, cp, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime + objects = createUpdateRuntimeObjects(t, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime } assertCephFileSystem(t, reconciler, cr, request) } @@ -83,7 +83,7 @@ func TestDeleteDefaultSubvolumeGroup(t *testing.T) { filesystem, err := reconciler.newCephFilesystemInstances(cr) assert.NoError(t, err) - err = reconciler.deleteDefaultSubvolumeGroup(filesystem[0].Name, filesystem[0].Namespace, filesystem[0].OwnerReferences) + err = reconciler.deleteDefaultSubvolumeGroup(filesystem[0].Name, filesystem[0].Namespace) assert.NoError(t, err) svg := &cephv1.CephFilesystemSubVolumeGroup{} diff --git a/controllers/storagecluster/cephnfs_test.go b/controllers/storagecluster/cephnfs_test.go index d765144e57..66c451e348 100644 --- a/controllers/storagecluster/cephnfs_test.go +++ b/controllers/storagecluster/cephnfs_test.go @@ -31,7 +31,7 @@ func TestCephNFS(t *testing.T) { t, reconciler, cr, request := initStorageClusterResourceCreateUpdateTestWithPlatform( t, cp, objects, nil) if c.createRuntimeObjects { - objects = createUpdateRuntimeObjects(t, cp, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime + objects = createUpdateRuntimeObjects(t, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime } assertCephNFS(t, reconciler, cr, request) assertCephNFSService(t, reconciler, cr, request) diff --git a/controllers/storagecluster/cephobjectstores_test.go b/controllers/storagecluster/cephobjectstores_test.go index c4c56a1570..379f827d44 100644 --- a/controllers/storagecluster/cephobjectstores_test.go +++ b/controllers/storagecluster/cephobjectstores_test.go @@ -30,7 +30,7 @@ func TestCephObjectStores(t *testing.T) { t, reconciler, cr, request := initStorageClusterResourceCreateUpdateTestWithPlatform( t, cp, objects, nil) if c.createRuntimeObjects { - objects = createUpdateRuntimeObjects(t, cp, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime + objects = createUpdateRuntimeObjects(t, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime } assertCephObjectStores(t, reconciler, cr, request) } diff --git a/controllers/storagecluster/cephobjectstoreusers_test.go b/controllers/storagecluster/cephobjectstoreusers_test.go index 3f3785e8ae..51c44f1d46 100644 --- a/controllers/storagecluster/cephobjectstoreusers_test.go +++ b/controllers/storagecluster/cephobjectstoreusers_test.go @@ -29,7 +29,7 @@ func TestCephObjectStoreUsers(t *testing.T) { t, reconciler, cr, request := initStorageClusterResourceCreateUpdateTestWithPlatform( t, cp, objects, nil) if c.createRuntimeObjects { - objects = createUpdateRuntimeObjects(t, cp, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime + objects = createUpdateRuntimeObjects(t, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime } assertCephObjectStoreUsers(t, reconciler, cr, request) } diff --git a/controllers/storagecluster/cephrbdmirrors_test.go b/controllers/storagecluster/cephrbdmirrors_test.go index 170ffbb016..c948ee9de4 100644 --- a/controllers/storagecluster/cephrbdmirrors_test.go +++ b/controllers/storagecluster/cephrbdmirrors_test.go @@ -58,7 +58,7 @@ func TestCephRbdMirror(t *testing.T) { case "create-ceph-rbd-mirror": assertCephRbdMirrorCreation(t, reconciler, cr, request) case "delete-ceph-rbd-mirror": - assertCephRbdMirrorDeletion(t, reconciler, cr, request) + assertCephRbdMirrorDeletion(t, reconciler, request) } } } @@ -83,7 +83,7 @@ func assertCephRbdMirrorCreation(t *testing.T, reconciler StorageClusterReconcil assert.Equal(t, expectedCrm[0].Spec, actualCrm.Spec) } -func assertCephRbdMirrorDeletion(t *testing.T, reconciler StorageClusterReconciler, cr *api.StorageCluster, request reconcile.Request) { +func assertCephRbdMirrorDeletion(t *testing.T, reconciler StorageClusterReconciler, request reconcile.Request) { actualCrm := &cephv1.CephRBDMirror{ ObjectMeta: metav1.ObjectMeta{ Name: "ocsinit-cephrbdmirror", diff --git a/controllers/storagecluster/exporter.go b/controllers/storagecluster/exporter.go index 311c486ef5..8bc613d9c7 100644 --- a/controllers/storagecluster/exporter.go +++ b/controllers/storagecluster/exporter.go @@ -49,7 +49,7 @@ func (r *StorageClusterReconciler) enableMetricsExporter( } // create/update clusterrole for metrics exporter - if err := updateMetricsExporterClusterRoles(ctx, r, instance); err != nil { + if err := updateMetricsExporterClusterRoles(ctx, r); err != nil { r.Log.Error(err, "unable to update clusterroles for metrics exporter") return err } @@ -548,8 +548,7 @@ const metricsExporterClusterRoleJSON = ` ] }` -func updateMetricsExporterClusterRoles(ctx context.Context, - r *StorageClusterReconciler, instance *ocsv1.StorageCluster) error { +func updateMetricsExporterClusterRoles(ctx context.Context, r *StorageClusterReconciler) error { currentClusterRole := new(rbacv1.ClusterRole) var expectedClusterRole = new(rbacv1.ClusterRole) err := json.Unmarshal([]byte(metricsExporterClusterRoleJSON), expectedClusterRole) diff --git a/controllers/storagecluster/external_resources.go b/controllers/storagecluster/external_resources.go index b48cc44fd0..f8bdddc176 100644 --- a/controllers/storagecluster/external_resources.go +++ b/controllers/storagecluster/external_resources.go @@ -150,7 +150,7 @@ func (r *StorageClusterReconciler) retrieveSecret(secretName string, instance *o } // deleteSecret function delete the secret object with the specified name -func (r *StorageClusterReconciler) deleteSecret(secretName string, instance *ocsv1.StorageCluster) error { +func (r *StorageClusterReconciler) deleteSecret(instance *ocsv1.StorageCluster) error { found, err := r.retrieveSecret(externalClusterDetailsSecret, instance) if errors.IsNotFound(err) { r.Log.Info("External rhcs mode secret already deleted.") @@ -275,7 +275,7 @@ func (obj *ocsExternalResources) ensureCreated(r *StorageClusterReconciler, inst } // ensureDeleted is dummy func for the ocsExternalResources -func (obj *ocsExternalResources) ensureDeleted(r *StorageClusterReconciler, instance *ocsv1.StorageCluster) (reconcile.Result, error) { +func (obj *ocsExternalResources) ensureDeleted(_ *StorageClusterReconciler, _ *ocsv1.StorageCluster) (reconcile.Result, error) { return reconcile.Result{}, nil } @@ -511,7 +511,7 @@ func (r *StorageClusterReconciler) deleteExternalSecret(sc *ocsv1.StorageCluster if !sc.Spec.ExternalStorage.Enable { return nil } - err = r.deleteSecret(externalClusterDetailsSecret, sc) + err = r.deleteSecret(sc) if err != nil { r.Log.Error(err, "Error while deleting external rhcs mode secret.") } diff --git a/controllers/storagecluster/generate.go b/controllers/storagecluster/generate.go index e718b3be91..8f041b0112 100644 --- a/controllers/storagecluster/generate.go +++ b/controllers/storagecluster/generate.go @@ -2,11 +2,9 @@ package storagecluster import ( "fmt" - "os" "strings" ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" - "github.com/red-hat-storage/ocs-operator/v4/controllers/util" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" ) @@ -111,10 +109,6 @@ func generateNameForCephNetworkFilesystemSC(initData *ocsv1.StorageCluster) stri return fmt.Sprintf("%s-ceph-nfs", initData.Name) } -func generateNameForNFSCSIProvisioner(initData *ocsv1.StorageCluster) string { - return fmt.Sprintf("%s.nfs.csi.ceph.com", os.Getenv(util.OperatorNamespaceEnvVar)) -} - // generateNameForSnapshotClass function generates 'SnapshotClass' name. // 'snapshotType' can be: 'rbdSnapshotter' or 'cephfsSnapshotter' or 'nfsSnapshotter' func generateNameForSnapshotClass(initData *ocsv1.StorageCluster, snapshotType SnapshotterType) string { diff --git a/controllers/storagecluster/initialization_reconciler_test.go b/controllers/storagecluster/initialization_reconciler_test.go index 36473c59bd..03a1e2ada4 100644 --- a/controllers/storagecluster/initialization_reconciler_test.go +++ b/controllers/storagecluster/initialization_reconciler_test.go @@ -61,7 +61,7 @@ func createStorageCluster(scName, failureDomainName string, return cr } -func createUpdateRuntimeObjects(t *testing.T, cp *Platform, r StorageClusterReconciler) []client.Object { +func createUpdateRuntimeObjects(t *testing.T, r StorageClusterReconciler) []client.Object { csfs := &storagev1.StorageClass{ ObjectMeta: metav1.ObjectMeta{ Name: "ocsinit-cephfs", diff --git a/controllers/storagecluster/job_templates.go b/controllers/storagecluster/job_templates.go index 7b60d834ed..c13eef4f1c 100644 --- a/controllers/storagecluster/job_templates.go +++ b/controllers/storagecluster/job_templates.go @@ -63,7 +63,7 @@ func (obj *ocsJobTemplates) ensureCreated(r *StorageClusterReconciler, sc *ocsv1 } // ensureDeleted is dummy func for the ocsJobTemplates -func (obj *ocsJobTemplates) ensureDeleted(r *StorageClusterReconciler, sc *ocsv1.StorageCluster) (reconcile.Result, error) { +func (obj *ocsJobTemplates) ensureDeleted(_ *StorageClusterReconciler, _ *ocsv1.StorageCluster) (reconcile.Result, error) { return reconcile.Result{}, nil } diff --git a/controllers/storagecluster/operator_conditions_test.go b/controllers/storagecluster/operator_conditions_test.go index a2c29141c7..5fc6c7796c 100644 --- a/controllers/storagecluster/operator_conditions_test.go +++ b/controllers/storagecluster/operator_conditions_test.go @@ -21,6 +21,6 @@ func (stubCondition) Get(_ context.Context) (*metav1.Condition, error) { } -func (stubCondition) Set(_ context.Context, status metav1.ConditionStatus, option ...conditions.Option) error { +func (stubCondition) Set(_ context.Context, _ metav1.ConditionStatus, _ ...conditions.Option) error { return nil } diff --git a/controllers/storagecluster/reconcile.go b/controllers/storagecluster/reconcile.go index 74a50be637..24a8c1278f 100644 --- a/controllers/storagecluster/reconcile.go +++ b/controllers/storagecluster/reconcile.go @@ -158,7 +158,7 @@ func (r *StorageClusterReconciler) Reconcile(ctx context.Context, request reconc return reconcile.Result{}, err } - if err := r.validateStorageClusterSpec(sc, request); err != nil { + if err := r.validateStorageClusterSpec(sc); err != nil { return reconcile.Result{}, err } @@ -174,7 +174,7 @@ func (r *StorageClusterReconciler) Reconcile(ctx context.Context, request reconc r.IsMultipleStorageClusters = len(r.clusters.GetStorageClusters()) > 1 // Reconcile changes to the cluster - result, reconcileError := r.reconcilePhases(ctx, sc, request) + result, reconcileError := r.reconcilePhases(ctx, sc) // Ensure that cephtoolbox is deployed as instructed by the user err = r.ensureToolsDeployment(sc) @@ -218,7 +218,7 @@ func (r *StorageClusterReconciler) initializeImagesStatus(sc *ocsv1.StorageClust } // validateStorageClusterSpec must be called before reconciling. Any syntactic and semantic errors in the CR must be caught here. -func (r *StorageClusterReconciler) validateStorageClusterSpec(instance *ocsv1.StorageCluster, request reconcile.Request) error { +func (r *StorageClusterReconciler) validateStorageClusterSpec(instance *ocsv1.StorageCluster) error { if err := versionCheck(instance, r.Log); err != nil { r.Log.Error(err, "Failed to validate StorageCluster version.", "StorageCluster", klog.KRef(instance.Namespace, instance.Name)) r.recorder.ReportIfNotPresent(instance, corev1.EventTypeWarning, statusutil.EventReasonValidationFailed, err.Error()) @@ -250,7 +250,7 @@ func (r *StorageClusterReconciler) validateStorageClusterSpec(instance *ocsv1.St } } - if err := validateArbiterSpec(instance, r.Log); err != nil { + if err := validateArbiterSpec(instance); err != nil { r.Log.Error(err, "Failed to validate ArbiterSpec.", "StorageCluster", klog.KRef(instance.Namespace, instance.Name)) r.recorder.ReportIfNotPresent(instance, corev1.EventTypeWarning, statusutil.EventReasonValidationFailed, err.Error()) instance.Status.Phase = statusutil.PhaseError @@ -261,7 +261,7 @@ func (r *StorageClusterReconciler) validateStorageClusterSpec(instance *ocsv1.St return err } - if err := validateOverprovisionControlSpec(instance, r.Log); err != nil { + if err := validateOverprovisionControlSpec(instance); err != nil { r.Log.Error(err, "Failed to validate OverprovisionControlSpec.", "StorageCluster", klog.KRef(instance.Namespace, instance.Name)) r.recorder.ReportIfNotPresent(instance, corev1.EventTypeWarning, statusutil.EventReasonValidationFailed, err.Error()) instance.Status.Phase = statusutil.PhaseError @@ -272,7 +272,7 @@ func (r *StorageClusterReconciler) validateStorageClusterSpec(instance *ocsv1.St return err } - if err := validateCustomStorageClassNames(instance, r.Log); err != nil { + if err := validateCustomStorageClassNames(instance); err != nil { r.Log.Error(err, "Failed to validate custom StorageClassNames.", "StorageCluster", klog.KRef(instance.Namespace, instance.Name)) r.recorder.ReportIfNotPresent(instance, corev1.EventTypeWarning, statusutil.EventReasonValidationFailed, err.Error()) instance.Status.Phase = statusutil.PhaseError @@ -288,8 +288,7 @@ func (r *StorageClusterReconciler) validateStorageClusterSpec(instance *ocsv1.St func (r *StorageClusterReconciler) reconcilePhases( ctx context.Context, - instance *ocsv1.StorageCluster, - request reconcile.Request) (reconcile.Result, error) { + instance *ocsv1.StorageCluster) (reconcile.Result, error) { if instance.Spec.ExternalStorage.Enable { r.Log.Info("Reconciling external StorageCluster.", "StorageCluster", klog.KRef(instance.Namespace, instance.Name)) @@ -762,7 +761,7 @@ func remove(slice []string, s string) (result []string) { return } -func validateArbiterSpec(sc *ocsv1.StorageCluster, reqLogger logr.Logger) error { +func validateArbiterSpec(sc *ocsv1.StorageCluster) error { if sc.Spec.Arbiter.Enable && sc.Spec.FlexibleScaling { return fmt.Errorf("arbiter and flexibleScaling both can't be enabled") @@ -773,7 +772,7 @@ func validateArbiterSpec(sc *ocsv1.StorageCluster, reqLogger logr.Logger) error return nil } -func validateOverprovisionControlSpec(sc *ocsv1.StorageCluster, reqLogger logr.Logger) error { +func validateOverprovisionControlSpec(sc *ocsv1.StorageCluster) error { for _, opc := range sc.Spec.OverprovisionControl { val, ok := opc.Capacity.AsInt64() if !ok { @@ -792,7 +791,7 @@ func validateOverprovisionControlSpec(sc *ocsv1.StorageCluster, reqLogger logr.L return nil } -func validateCustomStorageClassNames(sc *ocsv1.StorageCluster, reqLogger logr.Logger) error { +func validateCustomStorageClassNames(sc *ocsv1.StorageCluster) error { scMap := make(map[string]bool) duplicateNames := []string{} if sc.Spec.ManagedResources.CephBlockPools.StorageClassName != "" { diff --git a/controllers/storagecluster/routes_test.go b/controllers/storagecluster/routes_test.go index d17309db3d..8261611af9 100644 --- a/controllers/storagecluster/routes_test.go +++ b/controllers/storagecluster/routes_test.go @@ -31,7 +31,7 @@ func TestCephRGWRoutes(t *testing.T) { t, reconciler, cr, request := initStorageClusterResourceCreateUpdateTestWithPlatform( t, cp, objects, nil) if c.createRuntimeObjects { - objects = createUpdateRuntimeObjects(t, cp, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime + objects = createUpdateRuntimeObjects(t, reconciler) //nolint:staticcheck //no need to use objects as they update in runtime } assertCephRGWRoutes(t, reconciler, cr, request) } diff --git a/controllers/storagecluster/storageclasses.go b/controllers/storagecluster/storageclasses.go index 7963281d63..ca0eca2236 100644 --- a/controllers/storagecluster/storageclasses.go +++ b/controllers/storagecluster/storageclasses.go @@ -374,7 +374,7 @@ func newCephNFSStorageClassConfiguration(initData *ocsv1.StorageCluster) Storage "description": "Provides RWO and RWX Filesystem volumes", }, }, - Provisioner: generateNameForNFSCSIProvisioner(initData), + Provisioner: fmt.Sprintf("%s.nfs.csi.ceph.com", os.Getenv(util.OperatorNamespaceEnvVar)), ReclaimPolicy: &persistentVolumeReclaimDelete, AllowVolumeExpansion: &allowVolumeExpansion, Parameters: map[string]string{ diff --git a/controllers/storagecluster/storagecluster_controller_test.go b/controllers/storagecluster/storagecluster_controller_test.go index 2fcb9f4522..050842ad28 100644 --- a/controllers/storagecluster/storagecluster_controller_test.go +++ b/controllers/storagecluster/storagecluster_controller_test.go @@ -1187,7 +1187,7 @@ func TestStorageClusterOnMultus(t *testing.T) { func assertCephClusterNetwork(t assert.TestingT, reconciler StorageClusterReconciler, cr *api.StorageCluster, request reconcile.Request) { serverVersion := &k8sVersion.Info{} request.Name = "ocsinit-cephcluster" - cephCluster, err := newCephCluster(cr, "", 3, serverVersion, nil, log) + cephCluster, err := newCephCluster(cr, "", serverVersion, nil, log) assert.NoError(t, err) err = reconciler.Client.Get(context.TODO(), request.NamespacedName, cephCluster) assert.NoError(t, err) diff --git a/controllers/storagecluster/topology.go b/controllers/storagecluster/topology.go index 570ad54f76..565356c79b 100644 --- a/controllers/storagecluster/topology.go +++ b/controllers/storagecluster/topology.go @@ -34,7 +34,7 @@ func (obj *ocsTopologyMap) ensureCreated(r *StorageClusterReconciler, instance * } // ensureDeleted is dummy func for the ocsTopologyMap -func (obj *ocsTopologyMap) ensureDeleted(r *StorageClusterReconciler, instance *ocsv1.StorageCluster) (reconcile.Result, error) { +func (obj *ocsTopologyMap) ensureDeleted(_ *StorageClusterReconciler, _ *ocsv1.StorageCluster) (reconcile.Result, error) { return reconcile.Result{}, nil } diff --git a/controllers/storagecluster/uninstall_reconciler.go b/controllers/storagecluster/uninstall_reconciler.go index aa39984e11..5827b6fa18 100644 --- a/controllers/storagecluster/uninstall_reconciler.go +++ b/controllers/storagecluster/uninstall_reconciler.go @@ -56,8 +56,8 @@ func (r *StorageClusterReconciler) deleteNodeAffinityKeyFromNodes(sc *ocsv1.Stor } for _, node := range nodes.Items { r.Log.Info("Uninstall: Deleting OCS label from Node.", "Node", node.Name) - new := node.DeepCopy() - delete(new.ObjectMeta.Labels, defaults.NodeAffinityKey) + updatedNode := node.DeepCopy() + delete(updatedNode.ObjectMeta.Labels, defaults.NodeAffinityKey) oldJSON, err := json.Marshal(node) if err != nil { @@ -65,7 +65,7 @@ func (r *StorageClusterReconciler) deleteNodeAffinityKeyFromNodes(sc *ocsv1.Stor continue } - newJSON, err := json.Marshal(new) + newJSON, err := json.Marshal(updatedNode) if err != nil { r.Log.Error(err, "Uninstall: Unable to remove the NodeAffinityKey from the Node.", "Node", node.Name) continue @@ -99,13 +99,13 @@ func (r *StorageClusterReconciler) deleteNodeTaint(sc *ocsv1.StorageCluster) (er } for _, node := range nodes.Items { r.Log.Info("Uninstall: Deleting OCS NodeTolerationKey from the Node.", "Node", node.Name) - new := node.DeepCopy() - new.Spec.Taints = make([]corev1.Taint, 0) + updatedNode := node.DeepCopy() + updatedNode.Spec.Taints = make([]corev1.Taint, 0) for _, taint := range node.Spec.Taints { if defaults.NodeTolerationKey == taint.Key { continue } - new.Spec.Taints = append(new.Spec.Taints, taint) + updatedNode.Spec.Taints = append(updatedNode.Spec.Taints, taint) } oldJSON, err := json.Marshal(node) @@ -114,7 +114,7 @@ func (r *StorageClusterReconciler) deleteNodeTaint(sc *ocsv1.StorageCluster) (er continue } - newJSON, err := json.Marshal(new) + newJSON, err := json.Marshal(updatedNode) if err != nil { r.Log.Error(err, "Uninstall: Unable to remove the NodeTolerationKey from the Node.", "Node", node.Name) continue diff --git a/controllers/storagecluster/uninstall_reconciler_test.go b/controllers/storagecluster/uninstall_reconciler_test.go index f7173e69cf..778b6bc2e2 100644 --- a/controllers/storagecluster/uninstall_reconciler_test.go +++ b/controllers/storagecluster/uninstall_reconciler_test.go @@ -310,13 +310,13 @@ func addFakeNodeAffinityKeyOnNodesAndSC(t *testing.T, reconciler StorageClusterR // Add labels on nodes for _, node := range nodes.Items { - new := node.DeepCopy() - new.ObjectMeta.Labels[fakeKey] = fakeVal + updatedNode := node.DeepCopy() + updatedNode.ObjectMeta.Labels[fakeKey] = fakeVal oldJSON, err := json.Marshal(node) assert.NoError(t, err) - newJSON, err := json.Marshal(new) + newJSON, err := json.Marshal(updatedNode) assert.NoError(t, err) patch, err := strategicpatch.CreateTwoWayMergePatch(oldJSON, newJSON, node) @@ -383,13 +383,13 @@ func addDefaultNodeTaintOnNodes(t *testing.T, reconciler StorageClusterReconcile assert.NotEqual(t, 0, len(nodes.Items)) for _, node := range nodes.Items { - new := node.DeepCopy() - new.Spec.Taints = append(new.Spec.Taints, corev1.Taint{Key: defaults.NodeTolerationKey, Effect: corev1.TaintEffectNoSchedule}) + updatedNode := node.DeepCopy() + updatedNode.Spec.Taints = append(updatedNode.Spec.Taints, corev1.Taint{Key: defaults.NodeTolerationKey, Effect: corev1.TaintEffectNoSchedule}) oldJSON, err := json.Marshal(node) assert.NoError(t, err) - newJSON, err := json.Marshal(new) + newJSON, err := json.Marshal(updatedNode) assert.NoError(t, err) patch, err := strategicpatch.CreateTwoWayMergePatch(oldJSON, newJSON, node) diff --git a/controllers/storagecluster/volumesnapshotterclasses.go b/controllers/storagecluster/volumesnapshotterclasses.go index 173ecc5f65..6368e12df8 100644 --- a/controllers/storagecluster/volumesnapshotterclasses.go +++ b/controllers/storagecluster/volumesnapshotterclasses.go @@ -112,10 +112,10 @@ func (r *StorageClusterReconciler) createSnapshotClasses(vsccs []SnapshotClassCo } // no error, continue with the next iteration continue - } else { - r.Log.Error(err, "Failed to 'Get' SnapshotClass.", "SnapshotClass", klog.KRef(vsc.Namespace, vsc.Name)) - return err } + + r.Log.Error(err, "Failed to 'Get' SnapshotClass.", "SnapshotClass", klog.KRef(vsc.Namespace, vsc.Name)) + return err } if vscc.reconcileStrategy == ReconcileStrategyInit { return nil diff --git a/controllers/storagecluster/volumesnapshotterclasses_test.go b/controllers/storagecluster/volumesnapshotterclasses_test.go index 830530cfc3..65b3186b31 100644 --- a/controllers/storagecluster/volumesnapshotterclasses_test.go +++ b/controllers/storagecluster/volumesnapshotterclasses_test.go @@ -5,7 +5,6 @@ import ( "testing" snapapi "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1" - api "github.com/red-hat-storage/ocs-operator/api/v4/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/stretchr/testify/assert" @@ -15,13 +14,13 @@ import ( func TestVolumeSnapshotterClasses(t *testing.T) { for _, eachPlatform := range allPlatforms { cp := &Platform{platform: eachPlatform} - t, reconciler, cr, request := initStorageClusterResourceCreateUpdateTestWithPlatform(t, cp, nil, nil) - assertVolumeSnapshotterClasses(t, reconciler, cr, request) + t, reconciler, _, request := initStorageClusterResourceCreateUpdateTestWithPlatform(t, cp, nil, nil) + assertVolumeSnapshotterClasses(t, reconciler, request) } } func assertVolumeSnapshotterClasses(t *testing.T, reconciler StorageClusterReconciler, - cr *api.StorageCluster, request reconcile.Request) { + request reconcile.Request) { rbdVSCName := "ocsinit-rbdplugin-snapclass" cephfsVSCName := "ocsinit-cephfsplugin-snapclass" cephnfsVSCName := "ocsinit-nfsplugin-snapclass" diff --git a/controllers/storageconsumer/storageconsumer_controller.go b/controllers/storageconsumer/storageconsumer_controller.go index 641dca126c..8a26b2788d 100644 --- a/controllers/storageconsumer/storageconsumer_controller.go +++ b/controllers/storageconsumer/storageconsumer_controller.go @@ -76,6 +76,7 @@ func (r *StorageConsumerReconciler) Reconcile(ctx context.Context, request recon prevLogger := r.Log defer func() { r.Log = prevLogger }() r.Log = r.Log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) + r.ctx = ctx r.Log.Info("Reconciling StorageConsumer.", "StorageConsumer", klog.KRef(request.Namespace, request.Name)) diff --git a/metrics/internal/cache/ceph-blocklist.go b/metrics/internal/cache/ceph-blocklist.go index 3ecb171a41..3c3c58e093 100644 --- a/metrics/internal/cache/ceph-blocklist.go +++ b/metrics/internal/cache/ceph-blocklist.go @@ -70,11 +70,11 @@ func NewCephBlocklistStore(opts *options.Options) *CephBlocklistStore { } } -func (c *CephBlocklistStore) Add(obj interface{}) error { +func (c *CephBlocklistStore) Add(_ interface{}) error { return c.Resync() } -func (c *CephBlocklistStore) Get(obj interface{}) (item interface{}, exists bool, err error) { +func (c *CephBlocklistStore) Get(_ interface{}) (item interface{}, exists bool, err error) { return nil, false, nil } @@ -94,11 +94,11 @@ func (c *CephBlocklistStore) ListKeys() []string { return nil } -func (c *CephBlocklistStore) Replace(list []interface{}, _ string) error { +func (c *CephBlocklistStore) Replace(_ []interface{}, _ string) error { return nil } -func (c *CephBlocklistStore) GetByKey(key string) (item interface{}, exists bool, err error) { +func (c *CephBlocklistStore) GetByKey(_ string) (item interface{}, exists bool, err error) { return nil, false, nil } @@ -135,7 +135,7 @@ func (c *CephBlocklistStore) Resync() error { return nil } -func (c *CephBlocklistStore) Delete(obj interface{}) error { +func (c *CephBlocklistStore) Delete(_ interface{}) error { return nil } diff --git a/metrics/internal/cache/pv.go b/metrics/internal/cache/pv.go index fe25d42cee..a9cbc6fd59 100644 --- a/metrics/internal/cache/pv.go +++ b/metrics/internal/cache/pv.go @@ -213,12 +213,12 @@ func (p *PersistentVolumeStore) ListKeys() []string { } // Get implements the Get method of the store interface. -func (p *PersistentVolumeStore) Get(obj interface{}) (item interface{}, exists bool, err error) { +func (p *PersistentVolumeStore) Get(_ interface{}) (item interface{}, exists bool, err error) { return nil, false, nil } // GetByKey implements the GetByKey method of the store interface. -func (p *PersistentVolumeStore) GetByKey(key string) (item interface{}, exists bool, err error) { +func (p *PersistentVolumeStore) GetByKey(_ string) (item interface{}, exists bool, err error) { return nil, false, nil } diff --git a/metrics/internal/cache/rbd-mirror.go b/metrics/internal/cache/rbd-mirror.go index b664955aa5..788a8aab42 100644 --- a/metrics/internal/cache/rbd-mirror.go +++ b/metrics/internal/cache/rbd-mirror.go @@ -269,11 +269,11 @@ func (s *RBDMirrorStore) ListKeys() []string { return nil } -func (s *RBDMirrorStore) Get(obj interface{}) (item interface{}, exists bool, err error) { +func (s *RBDMirrorStore) Get(_ interface{}) (item interface{}, exists bool, err error) { return nil, false, nil } -func (s *RBDMirrorStore) GetByKey(key string) (item interface{}, exists bool, err error) { +func (s *RBDMirrorStore) GetByKey(_ string) (item interface{}, exists bool, err error) { return nil, false, nil } diff --git a/metrics/internal/collectors/cluster-advance-feature-use.go b/metrics/internal/collectors/cluster-advance-feature-use.go index c79584df58..bd1b6047f1 100644 --- a/metrics/internal/collectors/cluster-advance-feature-use.go +++ b/metrics/internal/collectors/cluster-advance-feature-use.go @@ -76,9 +76,9 @@ type StorageClassAdvancedFeatureProvider struct { cache.SharedIndexInformer } -func (s *StorageClassAdvancedFeatureProvider) AdvancedFeature(namespaces ...string) int { +func (s *StorageClassAdvancedFeatureProvider) AdvancedFeature(_ ...string) int { storageClassLister := storagev1listers.NewStorageClassLister(s.GetIndexer()) - storageClasses := getAllStorageClasses(storageClassLister, namespaces) + storageClasses := getAllStorageClasses(storageClassLister) for _, storageClass := range storageClasses { if storageClass.Parameters["encrypted"] == "true" { return 1 @@ -87,7 +87,7 @@ func (s *StorageClassAdvancedFeatureProvider) AdvancedFeature(namespaces ...stri return 0 } -func NewStorageClassAdvancedFeatureProvider(opts *options.Options, client *kubernetes.Clientset) AdvancedFeatureProvider { +func NewStorageClassAdvancedFeatureProvider(client *kubernetes.Clientset) AdvancedFeatureProvider { storageclassClient := client.StorageV1() // for any cluster-scoped resource, // pass a 'nil' option to 'searchInNamespace()' function to get 'NamespaceAll' @@ -148,7 +148,7 @@ func NewClusterAdvancedFeatureCollector(opts *options.Options) *ClusterAdvanceFe if k8Client, err := kubernetes.NewForConfig(opts.Kubeconfig); err == nil { advFeatureProviders = append( - advFeatureProviders, NewStorageClassAdvancedFeatureProvider(opts, k8Client)) + advFeatureProviders, NewStorageClassAdvancedFeatureProvider(k8Client)) } else { // logging any error occurred klog.Errorf("unable to get K8 Client, no StorageClass information available: %v", err) } @@ -202,9 +202,7 @@ func (c *ClusterAdvanceFeatureCollector) collectAdvancedFeatureUse(ch chan<- pro ) } -func getAllStorageClasses( - lister storagev1listers.StorageClassLister, - namespaces []string) []*storagev1.StorageClass { +func getAllStorageClasses(lister storagev1listers.StorageClassLister) []*storagev1.StorageClass { var err error allSCs, err := lister.List(labels.Everything()) if err != nil { diff --git a/metrics/internal/collectors/rbd-mirror.go b/metrics/internal/collectors/rbd-mirror.go index d4ca2f2f08..61f886dfd8 100644 --- a/metrics/internal/collectors/rbd-mirror.go +++ b/metrics/internal/collectors/rbd-mirror.go @@ -6,7 +6,6 @@ import ( "github.com/prometheus/client_golang/prometheus" internalcache "github.com/red-hat-storage/ocs-operator/v4/metrics/internal/cache" - "github.com/red-hat-storage/ocs-operator/v4/metrics/internal/options" "k8s.io/klog/v2" ) @@ -38,7 +37,7 @@ type RBDMirrorCollector struct { ImageSnapshotBytes *prometheus.Desc } -func NewRBDMirrorCollector(mirrorStore *internalcache.RBDMirrorStore, pvStore *internalcache.PersistentVolumeStore, opts *options.Options) *RBDMirrorCollector { +func NewRBDMirrorCollector(mirrorStore *internalcache.RBDMirrorStore, pvStore *internalcache.PersistentVolumeStore) *RBDMirrorCollector { commonRBDMirrorLabels := []string{"image", "pool_name", "site_name"} return &RBDMirrorCollector{ RBDMirrorStore: mirrorStore, diff --git a/metrics/internal/collectors/registry.go b/metrics/internal/collectors/registry.go index 9341db5acc..f524801605 100644 --- a/metrics/internal/collectors/registry.go +++ b/metrics/internal/collectors/registry.go @@ -113,7 +113,7 @@ func RegisterRBDMirrorCollector(registry *prometheus.Registry, opts *options.Opt if !rbdMirrorStoreEnabled { enableRBDMirrorStore(opts) } - rbdMirrorCollector := NewRBDMirrorCollector(rbdMirrorStore, pvStore, opts) + rbdMirrorCollector := NewRBDMirrorCollector(rbdMirrorStore, pvStore) registry.MustRegister(rbdMirrorCollector) } diff --git a/metrics/internal/collectors/storageconsumer.go b/metrics/internal/collectors/storageconsumer.go index d2fbedfe51..220e658eef 100644 --- a/metrics/internal/collectors/storageconsumer.go +++ b/metrics/internal/collectors/storageconsumer.go @@ -66,7 +66,7 @@ func NewStorageConsumerCollector(opts *options.Options) *StorageConsumerCollecto func (c *StorageConsumerCollector) Collect(ch chan<- prometheus.Metric) { storageConsumerLister := NewStorageConsumerLister(c.Informer.GetIndexer()) - storageConsumers := getAllStorageConsumers(storageConsumerLister, c.AllowedNamespace) + storageConsumers := getAllStorageConsumers(storageConsumerLister) if len(storageConsumers) > 0 { c.collectStorageConsumersMetadata(storageConsumers, ch) } @@ -140,7 +140,7 @@ func (c *StorageConsumerCollector) collectStorageConsumersMetadata(storageConsum } } -func getAllStorageConsumers(lister StorageConsumerLister, namespace string) (storageConsumers []*ocsv1alpha1.StorageConsumer) { +func getAllStorageConsumers(lister StorageConsumerLister) (storageConsumers []*ocsv1alpha1.StorageConsumer) { storageConsumers, err := lister.List(labels.Everything()) if err != nil { klog.Errorf("couldn't list StorageConsumer. %v", err) diff --git a/pkg/deploy-manager/storagecluster.go b/pkg/deploy-manager/storagecluster.go index 8846f4c862..c2e88b45a1 100644 --- a/pkg/deploy-manager/storagecluster.go +++ b/pkg/deploy-manager/storagecluster.go @@ -368,30 +368,30 @@ func (t *DeployManager) labelWorkerNodes() error { } for _, node := range nodes.Items { - old, err := json.Marshal(node) + currentNode, err := json.Marshal(node) if err != nil { return err } - new := node.DeepCopy() + updatedNode := node.DeepCopy() if t.ArbiterEnabled() && node.GetLabels()[corev1.LabelZoneFailureDomainStable] == arbiterZone { // don't label the nodes in the arbiter zone arbiterNodeCount++ continue } - new.Labels["cluster.ocs.openshift.io/openshift-storage"] = "" + updatedNode.Labels["cluster.ocs.openshift.io/openshift-storage"] = "" - newJSON, err := json.Marshal(new) + newJSON, err := json.Marshal(updatedNode) if err != nil { return err } - patch, err := strategicpatch.CreateTwoWayMergePatch(old, newJSON, node) + patch, err := strategicpatch.CreateTwoWayMergePatch(currentNode, newJSON, node) if err != nil { return err } - err = t.Client.Patch(context.TODO(), new, client.RawPatch(types.StrategicMergePatchType, patch)) + err = t.Client.Patch(context.TODO(), updatedNode, client.RawPatch(types.StrategicMergePatchType, patch)) if err != nil { return err } diff --git a/services/provider/server/server.go b/services/provider/server/server.go index c028b066f5..6d257c930b 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -77,7 +77,7 @@ func NewOCSProviderServer(ctx context.Context, namespace string) (*OCSProviderSe return nil, fmt.Errorf("failed to create new OCSConumer instance. %v", err) } - storageClassRequestManager, err := newStorageClassRequestManager(ctx, client, namespace) + storageClassRequestManager, err := newStorageClassRequestManager(client, namespace) if err != nil { return nil, fmt.Errorf("failed to create new StorageClassRequest instance. %v", err) } diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index f8ecc786fa..c48752f75b 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -396,7 +396,7 @@ func TestOCSProviderServerStorageClassRequest(t *testing.T) { consumerManager, err := newConsumerManager(ctx, client, serverNamespace) assert.NoError(t, err) - storageClassRequestManager, err := newStorageClassRequestManager(ctx, client, serverNamespace) + storageClassRequestManager, err := newStorageClassRequestManager(client, serverNamespace) assert.NoError(t, err) server := &OCSProviderServer{ @@ -462,7 +462,7 @@ func TestOCSProviderServerRevokeStorageClassClaim(t *testing.T) { consumerManager, err := newConsumerManager(ctx, client, serverNamespace) assert.NoError(t, err) - storageRequestManager, err := newStorageClassRequestManager(ctx, client, serverNamespace) + storageRequestManager, err := newStorageClassRequestManager(client, serverNamespace) assert.NoError(t, err) server := &OCSProviderServer{ @@ -684,7 +684,7 @@ func TestOCSProviderServerGetStorageClassClaimConfig(t *testing.T) { consumerManager, err := newConsumerManager(ctx, client, serverNamespace) assert.NoError(t, err) - storageClassRequestManager, err := newStorageClassRequestManager(ctx, client, serverNamespace) + storageClassRequestManager, err := newStorageClassRequestManager(client, serverNamespace) assert.NoError(t, err) server := &OCSProviderServer{ diff --git a/services/provider/server/storageclassrequest.go b/services/provider/server/storageclassrequest.go index d5f129e186..07c55a4a77 100644 --- a/services/provider/server/storageclassrequest.go +++ b/services/provider/server/storageclassrequest.go @@ -25,7 +25,7 @@ type storageClassRequestManager struct { namespace string } -func newStorageClassRequestManager(ctx context.Context, cl client.Client, namespace string) (*storageClassRequestManager, error) { +func newStorageClassRequestManager(cl client.Client, namespace string) (*storageClassRequestManager, error) { return &storageClassRequestManager{ client: cl, namespace: namespace,