diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index 874940235..618c46f7e 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -26,5 +26,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.53 + version: v1.54.2 skip-cache: true diff --git a/.golangci.yaml b/.golangci.yaml index 56f533245..603c01d4b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,6 +1,5 @@ run: timeout: 20m - issue-exit-code: 0 # we will change this later tests: true skip-dirs-use-default: true modules-download-mode: readonly diff --git a/api/v1/types.go b/api/v1/types.go index 940208f23..d68c6da77 100644 --- a/api/v1/types.go +++ b/api/v1/types.go @@ -63,7 +63,7 @@ const ( ReverseProxy ModuleType = "csireverseproxy" // ReverseProxyServer - placeholder for constant csipowermax-reverseproxy - ReverseProxyServer ModuleType = "csipowermax-reverseproxy" + ReverseProxyServer ModuleType = "csipowermax-reverseproxy" // #nosec G101 // ApplicationMobility - placeholder for constant application-mobility ApplicationMobility ModuleType = "application-mobility" @@ -353,15 +353,15 @@ type ContainerTemplate struct { // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Application Mobility Object Store Secret" ObjectStoreSecretName string `json:"objectStoreSecretName,omitempty" yaml:"objectStoreSecretName,omitempty"` - //UseSnapshot is to check whether volume snapshot is enabled under velero component + // UseSnapshot is to check whether volume snapshot is enabled under velero component // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="use-volume-snapshots for Application Mobilit- Velero" UseSnapshot bool `json:"useVolumeSnapshot,omitempty" yaml:"useVolumeSnapshot,omitempty"` - //ComponentCred is to store the velero credential contents + // ComponentCred is to store the velero credential contents // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="ComponentCred for velero component" ComponentCred []Credential `json:"credentials,omitempty" yaml:"credentials,omitempty"` - //DeployNodeAgent is to enable/disable node-agent services + // DeployNodeAgent is to enable/disable node-agent services // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Deploy node-agent for Application Mobility" DeployNodeAgent bool `json:"deployNodeAgent,omitempty" yaml:"deployNodeAgent,omitempty"` } diff --git a/controllers/acc_controller_test.go b/controllers/acc_controller_test.go index 8f43b4931..b19dd2174 100644 --- a/controllers/acc_controller_test.go +++ b/controllers/acc_controller_test.go @@ -418,7 +418,7 @@ func (suite *AccControllerTestSuite) runFakeAccManager(expectedErr string, recon } // call reconcile with different injection errors in k8s client -func (suite *AccControllerTestSuite) reconcileAccWithErrorInjection(reqName, expectedErr string) { +func (suite *AccControllerTestSuite) reconcileAccWithErrorInjection(_, expectedErr string) { reconciler := suite.createAccReconciler() // create would fail diff --git a/controllers/csm_controller.go b/controllers/csm_controller.go index d7c20377a..62ee0778d 100644 --- a/controllers/csm_controller.go +++ b/controllers/csm_controller.go @@ -17,6 +17,7 @@ import ( "encoding/json" "fmt" "strconv" + "sync" "sync/atomic" "time" @@ -54,9 +55,7 @@ import ( corev1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - //metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sync" + // metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // ContainerStorageModuleReconciler reconciles a ContainerStorageModule object @@ -377,7 +376,7 @@ func (r *ContainerStorageModuleReconciler) handleDeploymentUpdate(oldObj interfa ready := d.Status.ReadyReplicas numberUnavailable := d.Status.UnavailableReplicas - //Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable + // Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable log.Infow("deployment", "desired", desired) log.Infow("deployment", "numberReady", ready) @@ -393,7 +392,6 @@ func (r *ContainerStorageModuleReconciler) handleDeploymentUpdate(oldObj interfa csm := new(csmv1.ContainerStorageModule) err := r.Client.Get(ctx, namespacedName, csm) - if err != nil { log.Error("deployment get csm", "error", err.Error()) } @@ -414,7 +412,7 @@ func (r *ContainerStorageModuleReconciler) handleDeploymentUpdate(oldObj interfa } } -func (r *ContainerStorageModuleReconciler) handlePodsUpdate(oldObj interface{}, obj interface{}) { +func (r *ContainerStorageModuleReconciler) handlePodsUpdate(_ interface{}, obj interface{}) { dMutex.Lock() defer dMutex.Unlock() @@ -454,7 +452,6 @@ func (r *ContainerStorageModuleReconciler) handlePodsUpdate(oldObj interface{}, } else { r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "%s Driver pods running OK", stamp) } - } func (r *ContainerStorageModuleReconciler) handleDaemonsetUpdate(oldObj interface{}, obj interface{}) { @@ -505,12 +502,10 @@ func (r *ContainerStorageModuleReconciler) handleDaemonsetUpdate(oldObj interfac } else { r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "Driver daemonset running OK") } - } // ContentWatch - watch updates on deployment and deamonset func (r *ContainerStorageModuleReconciler) ContentWatch() error { - sharedInformerFactory := sinformer.NewSharedInformerFactory(r.K8sClient, time.Duration(time.Hour)) daemonsetInformer := sharedInformerFactory.Apps().V1().DaemonSets().Informer() @@ -543,7 +538,6 @@ func (r *ContainerStorageModuleReconciler) ContentWatch() error { // SetupWithManager sets up the controller with the Manager. func (r *ContainerStorageModuleReconciler) SetupWithManager(mgr ctrl.Manager, limiter ratelimiter.RateLimiter, maxReconcilers int) error { - go r.ContentWatch() return ctrl.NewControllerManagedBy(mgr). @@ -639,7 +633,7 @@ func (r *ContainerStorageModuleReconciler) oldStandAloneModuleCleanup(ctx contex } } - //check if application mobility needs to be uninstalled + // check if application mobility needs to be uninstalled oldApplicationmobilityEnabled, _ := utils.IsModuleEnabled(ctx, *oldCR, csmv1.ApplicationMobility) newApplicationmobilityEnabled, _ := utils.IsModuleEnabled(ctx, *newCR, csmv1.ApplicationMobility) @@ -695,7 +689,7 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1 } } - //Create/Update Reverseproxy Server + // Create/Update Reverseproxy Server if reverseProxyEnabled, _ := utils.IsModuleEnabled(ctx, cr, csmv1.ReverseProxy); reverseProxyEnabled { log.Infow("Trying Create/Update reverseproxy...") if err := r.reconcileReverseProxy(ctx, false, operatorConfig, cr, ctrlClient); err != nil { @@ -793,7 +787,6 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1 controller.Rbac.ClusterRole = *clusterRole } - } } @@ -1009,7 +1002,8 @@ func (r *ContainerStorageModuleReconciler) reconcileAppMobility(ctx context.Cont func getDriverConfig(ctx context.Context, cr csmv1.ContainerStorageModule, - operatorConfig utils.OperatorConfig) (*DriverConfig, error) { + operatorConfig utils.OperatorConfig, +) (*DriverConfig, error) { var ( err error driver *storagev1.CSIDriver @@ -1019,7 +1013,7 @@ func getDriverConfig(ctx context.Context, log = logger.GetLogger(ctx) ) - //if no driver is specified, return nil + // if no driver is specified, return nil if cr.Spec.Driver.CSIDriverType == "" { log.Infof("No driver specified in manifest") return nil, nil @@ -1059,7 +1053,6 @@ func getDriverConfig(ctx context.Context, Node: node, Controller: controller, }, nil - } // reconcileReverseProxy - deploy reverse proxy server @@ -1223,7 +1216,6 @@ func (r *ContainerStorageModuleReconciler) removeModule(ctx context.Context, ins // PreChecks - validate input values func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig) error { - log := logger.GetLogger(ctx) var am bool // Check drivers @@ -1288,11 +1280,9 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs if m.Name == cr.Name { log.Infow("Owner reference is found and matches") break - } else { - return fmt.Errorf("required Owner reference not found. Please re-install driver ") } + return fmt.Errorf("required Owner reference not found. Please re-install driver ") } - } } @@ -1327,7 +1317,7 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs return fmt.Errorf("failed observability validation: %v", err) } case csmv1.ApplicationMobility: - //ApplicationMobility precheck + // ApplicationMobility precheck if err := modules.ApplicationMobilityPrecheck(ctx, operatorConfig, m, *cr, r); err != nil { return fmt.Errorf("failed Appmobility validation: %v", err) } @@ -1338,7 +1328,6 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs default: return fmt.Errorf("unsupported module type %s", m.Name) } - } } @@ -1367,7 +1356,7 @@ func checkUpgrade(ctx context.Context, cr *csmv1.ContainerStorageModule, operato log.Infow("proceeding with modification of driver install") return true, nil } - //if not equal, it is an upgrade/downgrade + // if not equal, it is an upgrade/downgrade // get minimum required version for upgrade minUpgradePath, err := drivers.GetUpgradeInfo(ctx, operatorConfig, driverType, oldVersion) if err != nil { @@ -1389,7 +1378,6 @@ func checkUpgrade(ctx context.Context, cr *csmv1.ContainerStorageModule, operato // TODO: refactor this func applyConfigVersionAnnotations(ctx context.Context, instance *csmv1.ContainerStorageModule) bool { - log := logger.GetLogger(ctx) // If driver has not been initialized yet, we first annotate the driver with the config version annotation diff --git a/controllers/csm_controller_test.go b/controllers/csm_controller_test.go index 5a7184f93..db629f386 100644 --- a/controllers/csm_controller_test.go +++ b/controllers/csm_controller_test.go @@ -204,7 +204,6 @@ func (suite *CSMControllerTestSuite) TestResiliencyReconcile() { } func (suite *CSMControllerTestSuite) TestResiliencyReconcileError() { - suite.makeFakeResiliencyCSM(csmName, suite.namespace, false, append(getResiliencyModule(), getResiliencyModule()...), "unsupported-driver") reconciler := suite.createReconciler() res, err := reconciler.Reconcile(ctx, req) @@ -259,7 +258,6 @@ func (suite *CSMControllerTestSuite) TestErrorInjection() { } func (suite *CSMControllerTestSuite) TestPowerScaleAnnotation() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.PowerScale @@ -275,11 +273,9 @@ func (suite *CSMControllerTestSuite) TestPowerScaleAnnotation() { _, err := reconciler.Reconcile(ctx, req) assert.Error(suite.T(), err) updateCSMError = false - } func (suite *CSMControllerTestSuite) TestPowerFlexAnnotation() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.PowerFlex @@ -295,11 +291,9 @@ func (suite *CSMControllerTestSuite) TestPowerFlexAnnotation() { _, err := reconciler.Reconcile(ctx, req) assert.Error(suite.T(), err) updateCSMError = false - } func (suite *CSMControllerTestSuite) TestPowerStoreAnnotation() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.PowerStore @@ -315,11 +309,9 @@ func (suite *CSMControllerTestSuite) TestPowerStoreAnnotation() { _, err := reconciler.Reconcile(ctx, req) assert.Error(suite.T(), err) updateCSMError = false - } func (suite *CSMControllerTestSuite) TestUnityAnnotation() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.Unity @@ -335,11 +327,9 @@ func (suite *CSMControllerTestSuite) TestUnityAnnotation() { _, err := reconciler.Reconcile(ctx, req) assert.Error(suite.T(), err) updateCSMError = false - } func (suite *CSMControllerTestSuite) TestPowermaxAnnotation() { - csm := shared.MakeCSM(csmName, suite.namespace, shared.PmaxConfigVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.PowerMax @@ -355,11 +345,9 @@ func (suite *CSMControllerTestSuite) TestPowermaxAnnotation() { _, err := reconciler.Reconcile(ctx, req) assert.Error(suite.T(), err) updateCSMError = false - } func (suite *CSMControllerTestSuite) TestCsmUpgrade() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.PowerScale @@ -382,11 +370,9 @@ func (suite *CSMControllerTestSuite) TestCsmUpgrade() { reconciler := suite.createReconciler() _, err := reconciler.Reconcile(ctx, req) assert.Nil(suite.T(), err) - } func (suite *CSMControllerTestSuite) TestCsmUpgradeVersionTooOld() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.PowerScale @@ -409,11 +395,9 @@ func (suite *CSMControllerTestSuite) TestCsmUpgradeVersionTooOld() { reconciler := suite.createReconciler() _, err := reconciler.Reconcile(ctx, req) assert.Error(suite.T(), err) - } func (suite *CSMControllerTestSuite) TestCsmUpgradeSkipVersion() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.PowerScale @@ -436,11 +420,9 @@ func (suite *CSMControllerTestSuite) TestCsmUpgradeSkipVersion() { reconciler := suite.createReconciler() _, err := reconciler.Reconcile(ctx, req) assert.Error(suite.T(), err) - } func (suite *CSMControllerTestSuite) TestCsmUpgradePathInvalid() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.Common.Image = "image" csm.Spec.Driver.CSIDriverType = csmv1.PowerScale @@ -463,11 +445,9 @@ func (suite *CSMControllerTestSuite) TestCsmUpgradePathInvalid() { reconciler := suite.createReconciler() _, err := reconciler.Reconcile(ctx, req) assert.Error(suite.T(), err) - } func (suite *CSMControllerTestSuite) TestCsmFinalizerError() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.ObjectMeta.Finalizers = []string{"foo"} csm.Spec.Driver.CSIDriverType = csmv1.PowerScale @@ -514,7 +494,6 @@ func (suite *CSMControllerTestSuite) TestRemoveDriver() { for _, tt := range removeDriverTests { suite.T().Run(tt.name, func(t *testing.T) { - if tt.errorInjector != nil { // need to create all objs before running removeDriver to hit unknown error suite.makeFakeCSM(csmName, suite.namespace, true, append(getAuthModule(), getObservabilityModule()...)) @@ -536,7 +515,6 @@ func (suite *CSMControllerTestSuite) TestRemoveDriver() { } }) } - } // Test all edge cases in SyncCSM @@ -577,7 +555,6 @@ func (suite *CSMControllerTestSuite) TestSyncCSM() { } }) } - } func (suite *CSMControllerTestSuite) TestRemoveModule() { @@ -692,7 +669,6 @@ func (suite *CSMControllerTestSuite) TestOldStandAloneModuleCleanup() { } func (suite *CSMControllerTestSuite) TestCsmPreCheckVersionError() { - // set bad version error configVersion = "v0" csm := shared.MakeCSM(csmName, suite.namespace, configVersion) @@ -719,7 +695,6 @@ func (suite *CSMControllerTestSuite) TestCsmPreCheckVersionError() { } func (suite *CSMControllerTestSuite) TestCsmPreCheckTypeError() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.CSIDriverType = csmv1.PowerStore csm.Spec.Driver.Common.Image = "image" @@ -744,7 +719,6 @@ func (suite *CSMControllerTestSuite) TestCsmPreCheckTypeError() { } func (suite *CSMControllerTestSuite) TestCsmPreCheckModuleError() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.CSIDriverType = csmv1.PowerScale csm.Spec.Driver.Common.Image = "image" @@ -803,7 +777,6 @@ func (suite *CSMControllerTestSuite) TestCsmPreCheckModuleError() { } func (suite *CSMControllerTestSuite) TestCsmPreCheckModuleUnsupportedVersion() { - csm := shared.MakeCSM(csmName, suite.namespace, configVersion) csm.Spec.Driver.CSIDriverType = csmv1.PowerScale csm.Spec.Driver.Common.Image = "image" @@ -900,7 +873,6 @@ func (suite *CSMControllerTestSuite) TestContentWatch() { } func (suite *CSMControllerTestSuite) createReconciler() (reconciler *ContainerStorageModuleReconciler) { - logType := logger.DevelopmentLogLevel logger.SetLoggerLevel(logType) _, log := logger.GetNewContextWithLogger("0") @@ -986,7 +958,7 @@ func (suite *CSMControllerTestSuite) runFakeAuthCSMManager(expectedErr string, r } // call reconcile with different injection errors in k8s client -func (suite *CSMControllerTestSuite) reconcileWithErrorInjection(reqName, expectedErr string) { +func (suite *CSMControllerTestSuite) reconcileWithErrorInjection(_, expectedErr string) { reconciler := suite.createReconciler() // create would fail @@ -1121,7 +1093,7 @@ func (suite *CSMControllerTestSuite) handleDeploymentTest(r *ContainerStorageMod r.handleDeploymentUpdate(deployment, deployment) - //Make Pod and set pod status + // Make Pod and set pod status pod := shared.MakePod(name, suite.namespace) pod.Labels["csm"] = csmName pod.Status.Phase = corev1.PodPending @@ -1239,6 +1211,7 @@ func getReplicaModule() []csmv1.Module { }, } } + func getResiliencyModule() []csmv1.Module { return []csmv1.Module{ { @@ -1253,6 +1226,7 @@ func getResiliencyModule() []csmv1.Module { }, } } + func getAuthModule() []csmv1.Module { return []csmv1.Module{ { @@ -1528,7 +1502,6 @@ func (suite *CSMControllerTestSuite) TestReconcileAppMob() { // helper method to create k8s objects func (suite *CSMControllerTestSuite) makeFakeCSM(name, ns string, withFinalizer bool, modules []csmv1.Module) { - // make pre-requisite secrets sec := shared.MakeSecret(name+"-creds", ns, configVersion) err := suite.fakeClient.Create(ctx, sec) @@ -1603,7 +1576,6 @@ func (suite *CSMControllerTestSuite) makeFakeCSM(name, ns string, withFinalizer } func (suite *CSMControllerTestSuite) makeFakeResiliencyCSM(name, ns string, withFinalizer bool, modules []csmv1.Module, driverType string) { - sec := shared.MakeSecret(name+"-config", ns, configVersion) err := suite.fakeClient.Create(ctx, sec) assert.Nil(suite.T(), err) @@ -1638,8 +1610,7 @@ func (suite *CSMControllerTestSuite) makeFakeResiliencyCSM(name, ns string, with } // helper method to create k8s objects -func (suite *CSMControllerTestSuite) makeFakeAppMobCSM(name, ns string, modules []csmv1.Module) { - +func (suite *CSMControllerTestSuite) makeFakeAppMobCSM(name, ns string, _ []csmv1.Module) { // this secret required by application-mobility module sec := shared.MakeSecret("cloud-creds", ns, configVersion) err := suite.fakeClient.Create(ctx, sec) @@ -1674,8 +1645,7 @@ func (suite *CSMControllerTestSuite) makeFakeAppMobCSM(name, ns string, modules assert.Nil(suite.T(), err) } -func (suite *CSMControllerTestSuite) makeFakeAuthServerCSM(name, ns string, modules []csmv1.Module) { - +func (suite *CSMControllerTestSuite) makeFakeAuthServerCSM(name, ns string, _ []csmv1.Module) { // this secret required by authorization module sec := shared.MakeSecret("karavi-config-secret", ns, configVersion) err := suite.fakeClient.Create(ctx, sec) diff --git a/main.go b/main.go index 9804a0d3d..547e584a3 100644 --- a/main.go +++ b/main.go @@ -81,7 +81,6 @@ func init() { utilruntime.Must(certmanagerv1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme - } func printVersion(log *zap.SugaredLogger) { @@ -107,7 +106,7 @@ func getOperatorConfig(log *zap.SugaredLogger) utils.OperatorConfig { if err != nil { log.Info(fmt.Sprintf("kubeVersion err %s", kubeAPIServerVersion)) } - //format the required k8s version + // format the required k8s version majorVersion := kubeAPIServerVersion.Major minorVersion := strings.TrimSuffix(kubeAPIServerVersion.Minor, "+") kubeVersion := fmt.Sprintf("%s.%s", majorVersion, minorVersion) diff --git a/pkg/drivers/common_test.go b/pkg/drivers/common_test.go index 54a1c8ada..a42329f0d 100644 --- a/pkg/drivers/common_test.go +++ b/pkg/drivers/common_test.go @@ -29,8 +29,8 @@ var ( pflexCredsName = pflexCSMName + "-config" pFlexNS = "pflex-test" - trueBool bool = true - falseBool bool = false + trueBool = true + falseBool = false ) // makes a csm object with tolerations @@ -117,28 +117,28 @@ func csmForPowerFlex(customCSMName string) csmv1.ContainerStorageModule { res := shared.MakeCSM(customCSMName, pFlexNS, shared.PFlexConfigVersion) // Add sdc initcontainer - res.Spec.Driver.InitContainers = []csmv1.ContainerTemplate{csmv1.ContainerTemplate{ + res.Spec.Driver.InitContainers = []csmv1.ContainerTemplate{{ Name: "sdc", Enabled: &trueBool, Image: "image", ImagePullPolicy: "IfNotPresent", Args: []string{}, - Envs: []corev1.EnvVar{corev1.EnvVar{Name: "MDM"}}, + Envs: []corev1.EnvVar{{Name: "MDM"}}, Tolerations: []corev1.Toleration{}, }} // Add sdc-monitor Sidecar - res.Spec.Driver.SideCars = []csmv1.ContainerTemplate{csmv1.ContainerTemplate{ + res.Spec.Driver.SideCars = []csmv1.ContainerTemplate{{ Name: "sdc-monitor", Enabled: &falseBool, Image: "image", ImagePullPolicy: "IfNotPresent", Args: []string{}, - Envs: []corev1.EnvVar{corev1.EnvVar{Name: "MDM"}}, + Envs: []corev1.EnvVar{{Name: "MDM"}}, Tolerations: []corev1.Toleration{}, }} - //res.Spec.Driver.CSIDriverSpec.FSGroupPolicy == "ReadWriteOnceWithFSType" + // res.Spec.Driver.CSIDriverSpec.FSGroupPolicy == "ReadWriteOnceWithFSType" // Add pflex driver version res.Spec.Driver.ConfigVersion = shared.PFlexConfigVersion diff --git a/pkg/drivers/commonconfig.go b/pkg/drivers/commonconfig.go index 9300b33c0..8d5a3fdb6 100644 --- a/pkg/drivers/commonconfig.go +++ b/pkg/drivers/commonconfig.go @@ -168,7 +168,6 @@ func GetController(ctx context.Context, cr csmv1.ContainerStorageModule, operato } return &controllerYAML, nil - } // GetNode get node yaml @@ -300,7 +299,6 @@ func GetNode(ctx context.Context, cr csmv1.ContainerStorageModule, operatorConfi } return &nodeYaml, nil - } // GetUpgradeInfo - @@ -325,7 +323,6 @@ func GetUpgradeInfo(ctx context.Context, operatorConfig utils.OperatorConfig, dr // Example return value: "v2.2.0" return upgradePath.MinUpgradePath, nil - } // GetConfigMap get configmap @@ -360,7 +357,6 @@ func GetConfigMap(ctx context.Context, cr csmv1.ContainerStorageModule, operator configMap.Data = ModifyUnityConfigMap(ctx, cr) } return &configMap, nil - } // GetCSIDriver get driver diff --git a/pkg/drivers/powerflex.go b/pkg/drivers/powerflex.go index 4e6026fac..296e89863 100644 --- a/pkg/drivers/powerflex.go +++ b/pkg/drivers/powerflex.go @@ -55,7 +55,6 @@ const ( // PrecheckPowerFlex do input validation func PrecheckPowerFlex(ctx context.Context, cr *csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig, ct client.Client) error { - log := logger.GetLogger(ctx) // Check if driver version is supported by doing a stat on a config file @@ -109,7 +108,6 @@ func PrecheckPowerFlex(ctx context.Context, cr *csmv1.ContainerStorageModule, op // GetMDMFromSecret - Get MDM value from secret func GetMDMFromSecret(ctx context.Context, cr *csmv1.ContainerStorageModule, ct client.Client) (string, error) { - log := logger.GetLogger(ctx) secretName := cr.Name + "-config" credSecret, err := utils.GetSecret(ctx, secretName, cr.GetNamespace(), ct) @@ -191,7 +189,6 @@ func GetMDMFromSecret(ctx context.Context, cr *csmv1.ContainerStorageModule, ct return "", fmt.Errorf("Arrays details are not provided in vxflexos-config secret") } return mdmVal, nil - } // ValidateIPAddress validates that a proper set of IPs has been provided @@ -213,9 +210,7 @@ func ValidateIPAddress(ipAdd string) (string, bool) { return newIP, true } -var ( - ipRegex, _ = regexp.Compile(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`) -) +var ipRegex, _ = regexp.Compile(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`) // IsIpv4Regex - Matches Ipaddress with regex and returns error if the Ip Address doesn't match regex func IsIpv4Regex(ipAddress string) bool { @@ -224,7 +219,6 @@ func IsIpv4Regex(ipAddress string) bool { // ModifyPowerflexCR - Set environment variables provided in CR func ModifyPowerflexCR(yamlString string, cr csmv1.ContainerStorageModule, fileType string) string { - approveSdcEnabled := "" renameSdcEnabled := "" renameSdcPrefix := "" @@ -235,6 +229,7 @@ func ModifyPowerflexCR(yamlString string, cr csmv1.ContainerStorageModule, fileT healthMonitorController := "" healthMonitorNode := "" + // nolint:gosec switch fileType { case "Controller": for _, env := range cr.Spec.Driver.Controller.Envs { diff --git a/pkg/drivers/powerflex_test.go b/pkg/drivers/powerflex_test.go index 11777325c..0b64703c8 100644 --- a/pkg/drivers/powerflex_test.go +++ b/pkg/drivers/powerflex_test.go @@ -73,7 +73,7 @@ func TestPowerFlexGo(t *testing.T) { ctx := context.Background() for _, tt := range powerFlexTests { tt.ct.Create(ctx, tt.sec) - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckPowerFlex(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) diff --git a/pkg/drivers/powermax.go b/pkg/drivers/powermax.go index 599e361c7..99e2af213 100644 --- a/pkg/drivers/powermax.go +++ b/pkg/drivers/powermax.go @@ -120,6 +120,7 @@ func ModifyPowermaxCR(yamlString string, cr csmv1.ContainerStorageModule, fileTy storageCapacity := "true" maxVolumesPerNode := "" + // #nosec G101 - False positives switch fileType { case "Node": for _, env := range cr.Spec.Driver.Common.Envs { diff --git a/pkg/drivers/powermax_test.go b/pkg/drivers/powermax_test.go index e7beaeaf9..863693f61 100644 --- a/pkg/drivers/powermax_test.go +++ b/pkg/drivers/powermax_test.go @@ -68,7 +68,7 @@ var ( func TestPrecheckPowerMax(t *testing.T) { ctx := context.Background() for _, tt := range preCheckpowerMaxTest { - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckPowerMax(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) @@ -80,7 +80,7 @@ func TestPrecheckPowerMax(t *testing.T) { for _, tt := range powerMaxTests { tt.ct.Create(ctx, tt.sec) - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckPowerMax(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) diff --git a/pkg/drivers/powerscale.go b/pkg/drivers/powerscale.go index 74faa0505..be75271bf 100644 --- a/pkg/drivers/powerscale.go +++ b/pkg/drivers/powerscale.go @@ -35,7 +35,7 @@ const ( PowerScalePluginIdentifier = "powerscale" // PowerScaleConfigParamsVolumeMount - - PowerScaleConfigParamsVolumeMount = "csi-isilon-config-params" + PowerScaleConfigParamsVolumeMount = "csi-isilon-config-params" // #nosec G101 ) // PrecheckPowerScale do input validation diff --git a/pkg/drivers/powerscale_test.go b/pkg/drivers/powerscale_test.go index 5b15cc52d..13fa3d7e4 100644 --- a/pkg/drivers/powerscale_test.go +++ b/pkg/drivers/powerscale_test.go @@ -90,7 +90,7 @@ func TestGetApplyCertVolume(t *testing.T) { func TestPrecheckPowerScale(t *testing.T) { ctx := context.Background() for _, tt := range preCheckPowerScaleTest { - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckPowerScale(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) @@ -102,7 +102,7 @@ func TestPrecheckPowerScale(t *testing.T) { for _, tt := range powerScaleTests { tt.ct.Create(ctx, tt.sec) - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckPowerScale(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) diff --git a/pkg/drivers/powerstore_test.go b/pkg/drivers/powerstore_test.go index d8d26941a..7acf93edc 100644 --- a/pkg/drivers/powerstore_test.go +++ b/pkg/drivers/powerstore_test.go @@ -45,7 +45,6 @@ var ( // expected error expectedErr string }{ - {"happy path", powerStoreCSM, powerStoreClient, powerStoreSecret, ""}, {"bad version", powerStoreCSMBadVersion, powerStoreClient, powerStoreSecret, "not supported"}, } @@ -69,7 +68,7 @@ var ( func TestPrecheckPowerStore(t *testing.T) { ctx := context.Background() for _, tt := range powerStorePrecheckTests { - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckPowerStore(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) @@ -81,7 +80,7 @@ func TestPrecheckPowerStore(t *testing.T) { for _, tt := range powerStoreTests { tt.ct.Create(ctx, tt.sec) - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckPowerStore(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) diff --git a/pkg/drivers/unity.go b/pkg/drivers/unity.go index 5d705097a..14b043738 100644 --- a/pkg/drivers/unity.go +++ b/pkg/drivers/unity.go @@ -116,7 +116,6 @@ func ModifyUnityCR(yamlString string, cr csmv1.ContainerStorageModule, fileType switch fileType { case "Node": for _, env := range cr.Spec.Driver.Node.Envs { - if env.Name == "X_CSI_HEALTH_MONITOR_ENABLED" { healthMonitorNode = env.Value } @@ -124,7 +123,6 @@ func ModifyUnityCR(yamlString string, cr csmv1.ContainerStorageModule, fileType yamlString = strings.ReplaceAll(yamlString, CsiHealthMonitorEnabled, healthMonitorNode) case "Controller": for _, env := range cr.Spec.Driver.Controller.Envs { - if env.Name == "X_CSI_HEALTH_MONITOR_ENABLED" { healthMonitorController = env.Value } @@ -141,14 +139,13 @@ func ModifyUnityCR(yamlString string, cr csmv1.ContainerStorageModule, fileType } // ModifyUnityConfigMap - Modify the Configmap parameters -func ModifyUnityConfigMap(ctx context.Context, cr csmv1.ContainerStorageModule) map[string]string { +func ModifyUnityConfigMap(_ context.Context, cr csmv1.ContainerStorageModule) map[string]string { keyValue := "" var configMapData map[string]string for _, env := range cr.Spec.Driver.Common.Envs { if env.Name == "X_CSI_UNITY_ALLOW_MULTI_POD_ACCESS" { keyValue += fmt.Sprintf("\n %s: %s", "ALLOW_MULTI_POD_ACCESS", env.Value) - } if env.Name == "MAX_UNITY_VOLUMES_PER_NODE" { keyValue += fmt.Sprintf("\n %s: %s", env.Name, env.Value) @@ -168,7 +165,6 @@ func ModifyUnityConfigMap(ctx context.Context, cr csmv1.ContainerStorageModule) } return configMapData - } func getApplyCertVolumeUnity(cr csmv1.ContainerStorageModule) (*acorev1.VolumeApplyConfiguration, error) { diff --git a/pkg/drivers/unity_test.go b/pkg/drivers/unity_test.go index 1987bfcd0..8552bdc43 100644 --- a/pkg/drivers/unity_test.go +++ b/pkg/drivers/unity_test.go @@ -48,7 +48,6 @@ var ( // expected error expectedErr string }{ - {"happy path", csmUnity, unityClient, unitySecret, ""}, {"bad version", unityCSMBadVersion, unityClient, unitySecret, "not supported"}, {"invalid value for skip cert validation", unityCSMBadSkipCert, unityClient, unitySecret, "is an invalid value for X_CSI_UNITY_SKIP_CERTIFICATE_VALIDATION"}, @@ -75,7 +74,7 @@ var ( func TestPrecheckUnity(t *testing.T) { ctx := context.Background() for _, tt := range unityPrecheckTests { - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckUnity(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) @@ -87,7 +86,7 @@ func TestPrecheckUnity(t *testing.T) { for _, tt := range unityTests { tt.ct.Create(ctx, tt.sec) - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { // #nosec G601 - Run waits for the call to complete. err := PrecheckUnity(ctx, &tt.csm, config, tt.ct) if tt.expectedErr == "" { assert.Nil(t, err) diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index e4a020dfa..517402804 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -14,9 +14,10 @@ package logger import ( "context" + "os" + "go.uber.org/zap" "go.uber.org/zap/zapcore" - "os" ) // LogLevel represents the level for the log. diff --git a/pkg/modules/application_mobility.go b/pkg/modules/application_mobility.go index 9248a48e9..fe93f0bc2 100644 --- a/pkg/modules/application_mobility.go +++ b/pkg/modules/application_mobility.go @@ -43,9 +43,9 @@ const ( VeleroManifest = "velero-deployment.yaml" // AppMobCertManagerManifest - filename of Cert-manager manifest for app-mobility AppMobCertManagerManifest = "cert-manager.yaml" - //UseVolSnapshotManifest - filename of use volume snapshot manifest for velero + // UseVolSnapshotManifest - filename of use volume snapshot manifest for velero UseVolSnapshotManifest = "velero-volumesnapshotlocation.yaml" - //BackupStorageLoc - filename of backupstoragelocation manifest for velero + // BackupStorageLoc - filename of backupstoragelocation manifest for velero BackupStorageLoc = "velero-backupstoragelocation.yaml" // CleanupCrdManifest - filename of Cleanup Crds manifest for app-mobility CleanupCrdManifest = "cleanupcrds.yaml" @@ -55,10 +55,10 @@ const ( VeleroAccessManifest = "velero-secret.yaml" // CertManagerIssuerCertManifest - filename of the issuer and cert for app-mobility CertManagerIssuerCertManifest = "certificate.yaml" - //NodeAgentCrdManifest - filename of node-agent manifest for app-mobility + // NodeAgentCrdManifest - filename of node-agent manifest for app-mobility NodeAgentCrdManifest = "node-agent.yaml" - //ControllerImg - image for app-mobility-controller + // ControllerImg - image for app-mobility-controller ControllerImg = "" // ControllerImagePullPolicy - default image pull policy in yamls ControllerImagePullPolicy = "" @@ -68,13 +68,13 @@ const ( AppMobReplicaCount = "" // AppMobObjStoreSecretName - Secret name for object store AppMobObjStoreSecretName = "" - //BackupStorageLocation - name for Backup Storage Location + // BackupStorageLocation - name for Backup Storage Location BackupStorageLocation = "" - //VeleroBucketName - name for the used velero bucket + // VeleroBucketName - name for the used velero bucket VeleroBucketName = "" - //VolSnapshotlocation - name for Volume Snapshot location + // VolSnapshotlocation - name for Volume Snapshot location VolSnapshotlocation = "" - //BackupStorageURL - cloud url for backup storage location + // BackupStorageURL - cloud url for backup storage location BackupStorageURL = "" // ConfigProvider - configurations provider ConfigProvider = "" @@ -84,19 +84,19 @@ const ( VeleroImagePullPolicy = "" // VeleroAccess - Secret name for velero VeleroAccess = "" - //AWSInitContainerName - Name of init container for velero - aws + // AWSInitContainerName - Name of init container for velero - aws AWSInitContainerName = "" - //AWSInitContainerImage - Image of init container for velero -aws + // AWSInitContainerImage - Image of init container for velero -aws AWSInitContainerImage = "" - //DELLInitContainerName - Name of init container for velero - dell + // DELLInitContainerName - Name of init container for velero - dell DELLInitContainerName = "" - //DELLInitContainerImage - Image of init container for velero - dell + // DELLInitContainerImage - Image of init container for velero - dell DELLInitContainerImage = "" - //AccessContents - contents of the object store secret + // AccessContents - contents of the object store secret AccessContents = "" - //AKeyID - contains the aws access key id + // AKeyID - contains the aws access key id AKeyID = "" - //AKey - contains the aws access key + // AKey - contains the aws access key AKey = "" // AppMobCtrlMgrComponent - component name in cr for app-mobility controller-manager @@ -141,7 +141,6 @@ func getVeleroCrdDeploy(op utils.OperatorConfig, cr csmv1.ContainerStorageModule // VeleroCrdDeploy - apply and delete Velero crds deployment func VeleroCrdDeploy(ctx context.Context, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) error { - yamlString, err := getVeleroCrdDeploy(op, cr) if err != nil { return err @@ -185,7 +184,6 @@ func getAppMobCrdDeploy(op utils.OperatorConfig, cr csmv1.ContainerStorageModule // AppMobCrdDeploy - apply and delete Velero crds deployment func AppMobCrdDeploy(ctx context.Context, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) error { - yamlString, err := getAppMobCrdDeploy(op, cr) if err != nil { return err @@ -207,7 +205,6 @@ func AppMobCrdDeploy(ctx context.Context, op utils.OperatorConfig, cr csmv1.Cont // getAppMobilityModuleDeployment - updates deployment manifest with app mobility CRD values func getAppMobilityModuleDeployment(op utils.OperatorConfig, cr csmv1.ContainerStorageModule) (string, error) { - yamlString := "" appMob, err := getAppMobilityModule(cr) if err != nil { @@ -263,7 +260,6 @@ func getAppMobilityModuleDeployment(op utils.OperatorConfig, cr csmv1.ContainerS // AppMobilityDeployment - apply and delete controller manager deployment func AppMobilityDeployment(ctx context.Context, isDeleting bool, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) error { - yamlString, err := getAppMobilityModuleDeployment(op, cr) if err != nil { return err @@ -384,7 +380,7 @@ func IssuerCertService(ctx context.Context, isDeleting bool, op utils.OperatorCo } // ApplicationMobilityPrecheck - runs precheck for CSM Application Mobility -func ApplicationMobilityPrecheck(ctx context.Context, op utils.OperatorConfig, appMob csmv1.Module, cr csmv1.ContainerStorageModule, r utils.ReconcileCSM) error { +func ApplicationMobilityPrecheck(ctx context.Context, op utils.OperatorConfig, appMob csmv1.Module, _ csmv1.ContainerStorageModule, r utils.ReconcileCSM) error { log := logger.GetLogger(ctx) // check if provided version is supported @@ -414,7 +410,6 @@ func ApplicationMobilityPrecheck(ctx context.Context, op utils.OperatorConfig, a // AppMobilityCertManager - Install/Delete cert-manager func AppMobilityCertManager(ctx context.Context, isDeleting bool, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) error { - yamlString, err := getCertManager(op, cr) if err != nil { return err @@ -430,7 +425,6 @@ func AppMobilityCertManager(ctx context.Context, isDeleting bool, op utils.Opera // CreateVeleroAccess - Install/Delete velero-secret yaml from operator config func CreateVeleroAccess(ctx context.Context, isDeleting bool, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) error { - yamlString, err := getCreateVeleroAccess(op, cr) if err != nil { return err @@ -446,7 +440,6 @@ func CreateVeleroAccess(ctx context.Context, isDeleting bool, op utils.OperatorC // getCreateVeleroAccess - gets the velero-secret manifest from operatorconfig func getCreateVeleroAccess(op utils.OperatorConfig, cr csmv1.ContainerStorageModule) (string, error) { - yamlString := "" appMob, err := getAppMobilityModule(cr) @@ -496,7 +489,6 @@ func getCreateVeleroAccess(op utils.OperatorConfig, cr csmv1.ContainerStorageMod // AppMobilityVelero - Install/Delete velero along with its features - use volume snapshot location and cleanup crds func AppMobilityVelero(ctx context.Context, isDeleting bool, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) error { - var useSnap bool var nodeAgent bool envCredName := "" @@ -529,12 +521,12 @@ func AppMobilityVelero(ctx context.Context, isDeleting bool, op utils.OperatorCo } } for _, cred := range c.ComponentCred { - //if createWithInstall is enabled then create a secret + // if createWithInstall is enabled then create a secret if cred.CreateWithInstall { compCredName = string(cred.Name) foundCred, _ := utils.GetSecret(ctx, compCredName, cr.Namespace, ctrlClient) if foundCred == nil { - //creation of a secret + // creation of a secret err := CreateVeleroAccess(ctx, isDeleting, op, cr, ctrlClient) if err != nil { return fmt.Errorf("\n Unable to deploy velero-secret for Application Mobility: %v", err) @@ -553,7 +545,7 @@ func AppMobilityVelero(ctx context.Context, isDeleting bool, op utils.OperatorCo } } - //create volume snapshot location + // create volume snapshot location if useSnap { vsName, yamlString2, err := getUseVolumeSnapshot(ctx, op, cr, ctrlClient) @@ -580,7 +572,7 @@ func AppMobilityVelero(ctx context.Context, isDeleting bool, op utils.OperatorCo } } - //enable node agent + // enable node agent if nodeAgent { yamlString4, err := getNodeAgent(op, cr) if err != nil { @@ -631,7 +623,6 @@ func getVelero(op utils.OperatorConfig, cr csmv1.ContainerStorageModule) (string if strings.Contains(AppMobObjStoreSecretName, env.Name) { objectSecretName = env.Value } - } for _, cred := range component.ComponentCred { if cred.CreateWithInstall { @@ -668,8 +659,7 @@ func getVelero(op utils.OperatorConfig, cr csmv1.ContainerStorageModule) (string } // getUseVolumeSnapshot - gets the velero - volume snapshot location manifest -func getUseVolumeSnapshot(ctx context.Context, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) (string, string, error) { - +func getUseVolumeSnapshot(_ context.Context, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, _ crclient.Client) (string, string, error) { yamlString := "" appMob, err := getAppMobilityModule(cr) @@ -707,7 +697,7 @@ func getUseVolumeSnapshot(ctx context.Context, op utils.OperatorConfig, cr csmv1 } // getBackupStorageLoc - gets the velero Backup Storage Location manifest -func getBackupStorageLoc(ctx context.Context, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) (string, string, error) { +func getBackupStorageLoc(_ context.Context, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, _ crclient.Client) (string, string, error) { yamlString := "" appMob, err := getAppMobilityModule(cr) @@ -756,7 +746,6 @@ func getBackupStorageLoc(ctx context.Context, op utils.OperatorConfig, cr csmv1. // UseBackupStorageLoc - Apply/Delete velero-backupstoragelocation yaml from operator config func UseBackupStorageLoc(ctx context.Context, isDeleting bool, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) error { - log := logger.GetLogger(ctx) bslName, yamlString, err := getBackupStorageLoc(ctx, op, cr, ctrlClient) if err != nil { @@ -815,7 +804,6 @@ func getNodeAgent(op utils.OperatorConfig, cr csmv1.ContainerStorageModule) (str if strings.Contains(AppMobObjStoreSecretName, env.Name) { objectSecretName = env.Value } - } for _, cred := range component.ComponentCred { if cred.CreateWithInstall { @@ -835,7 +823,6 @@ func getNodeAgent(op utils.OperatorConfig, cr csmv1.ContainerStorageModule) (str // applyDeleteObjects - Applies/Deletes the object based on boolean value func applyDeleteObjects(ctx context.Context, ctrlClient crclient.Client, yamlString string, isDeleting bool) error { - ctrlObjects, err := utils.GetModuleComponentObj([]byte(yamlString)) if err != nil { return err @@ -854,5 +841,4 @@ func applyDeleteObjects(ctx context.Context, ctrlClient crclient.Client, yamlStr } return nil - } diff --git a/pkg/modules/application_mobility_test.go b/pkg/modules/application_mobility_test.go index 6a2c87d39..bb0a79ba2 100644 --- a/pkg/modules/application_mobility_test.go +++ b/pkg/modules/application_mobility_test.go @@ -98,7 +98,6 @@ func TestAppMobilityModuleDeployment(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := AppMobilityDeployment(context.TODO(), isDeleting, op, cr, sourceClient) @@ -107,10 +106,10 @@ func TestAppMobilityModuleDeployment(t *testing.T) { } else { assert.Error(t, err) } - }) } } + func TestAppMobilityWebhookService(t *testing.T) { tests := map[string]func(t *testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig){ "success - deleting": func(*testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig) { @@ -182,20 +181,18 @@ func TestAppMobilityWebhookService(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := AppMobilityWebhookService(context.TODO(), isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } + func TestControllerManagerMetricService(t *testing.T) { tests := map[string]func(t *testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig){ "success - deleting": func(*testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig) { @@ -268,17 +265,14 @@ func TestControllerManagerMetricService(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := ControllerManagerMetricService(context.TODO(), isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -372,10 +366,10 @@ func TestApplicationMobilityIssuerCertService(t *testing.T) { } else { assert.Error(t, err) } - }) } } + func TestApplicationMobilityPrecheck(t *testing.T) { type fakeControllerRuntimeClientWrapper func(clusterConfigData []byte) (ctrlClient.Client, error) @@ -479,14 +473,13 @@ func TestApplicationMobilityPrecheck(t *testing.T) { err := ApplicationMobilityPrecheck(context.TODO(), operatorConfig, appMobility, tmpCR, &fakeReconcile) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } + func TestAppMobilityVelero(t *testing.T) { tests := map[string]func(t *testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig){ "success - deleting": func(*testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig) { @@ -576,10 +569,10 @@ func TestAppMobilityVelero(t *testing.T) { } else { assert.Error(t, err) } - }) } } + func TestAppMobilityCertManager(t *testing.T) { tests := map[string]func(t *testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig){ "success - deleting": func(*testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig) { @@ -640,20 +633,18 @@ func TestAppMobilityCertManager(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := AppMobilityCertManager(ctx, isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } + func TestVeleroCrdDeploy(t *testing.T) { tests := map[string]func(t *testing.T) (bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig){ "success - deleting": func(*testing.T) (bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig) { @@ -726,20 +717,18 @@ func TestVeleroCrdDeploy(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, cr, sourceClient, op := tc(t) err := VeleroCrdDeploy(ctx, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } + func TestAppMobCrdDeploy(t *testing.T) { tests := map[string]func(t *testing.T) (bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig){ "success - deleting": func(*testing.T) (bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig) { @@ -812,20 +801,18 @@ func TestAppMobCrdDeploy(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, cr, sourceClient, op := tc(t) err := AppMobCrdDeploy(ctx, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } + func TestBackupStorageLoc(t *testing.T) { tests := map[string]func(t *testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig){ "success - deleting": func(*testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig) { @@ -910,11 +897,9 @@ func TestBackupStorageLoc(t *testing.T) { err := UseBackupStorageLoc(ctx, isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } diff --git a/pkg/modules/authorization.go b/pkg/modules/authorization.go index 5f118f7f1..7b0d0c78b 100644 --- a/pkg/modules/authorization.go +++ b/pkg/modules/authorization.go @@ -157,7 +157,6 @@ func CheckAnnotationAuth(annotation map[string]string) error { return nil } return errors.New("annotation is nil") - } // CheckApplyVolumesAuth -- @@ -215,7 +214,6 @@ func CheckApplyContainersAuth(containers []acorev1.ContainerApplyConfiguration, } return nil } - } return errors.New("karavi-authorization-proxy container was not injected into driver") } @@ -270,7 +268,6 @@ func getAuthApplyCR(cr csmv1.ContainerStorageModule, op utils.OperatorConfig) (* container.VolumeMounts[i] = container.VolumeMounts[len(container.VolumeMounts)-1] container.VolumeMounts = container.VolumeMounts[:len(container.VolumeMounts)-1] } - } } else { for i, e := range container.Env { @@ -278,7 +275,6 @@ func getAuthApplyCR(cr csmv1.ContainerStorageModule, op utils.OperatorConfig) (* value := strconv.FormatBool(skipCertValid) container.Env[i].Value = &value } - } } @@ -288,11 +284,9 @@ func getAuthApplyCR(cr csmv1.ContainerStorageModule, op utils.OperatorConfig) (* container.VolumeMounts[i].Name = &newName break } - } return &authModule, &container, nil - } func getAuthApplyVolumes(cr csmv1.ContainerStorageModule, op utils.OperatorConfig, auth csmv1.ContainerTemplate) ([]acorev1.VolumeApplyConfiguration, error) { @@ -328,9 +322,7 @@ func getAuthApplyVolumes(cr csmv1.ContainerStorageModule, op utils.OperatorConfi return vols[:len(vols)-1], nil } - } - } return vols, nil } @@ -389,7 +381,6 @@ func AuthInjectDeployment(dp applyv1.DeploymentApplyConfiguration, cr csmv1.Cont dp.Spec.Template.Spec.Volumes = append(dp.Spec.Template.Spec.Volumes, vols...) return &dp, nil - } // AuthorizationPrecheck - runs precheck for CSM Authorization @@ -425,13 +416,14 @@ func AuthorizationPrecheck(ctx context.Context, op utils.OperatorConfig, auth cs secrets := []string{"karavi-authorization-config", "proxy-authz-tokens"} if !skipCertValid { secrets = append(secrets, "proxy-server-root-certificate") - } for _, name := range secrets { found := &corev1.Secret{} - err := ctrlClient.Get(ctx, types.NamespacedName{Name: name, - Namespace: cr.GetNamespace()}, found) + err := ctrlClient.Get(ctx, types.NamespacedName{ + Name: name, + Namespace: cr.GetNamespace(), + }, found) if err != nil { if k8serrors.IsNotFound(err) { return fmt.Errorf("failed to find secret %s and certificate validation is requested", name) diff --git a/pkg/modules/authorization_test.go b/pkg/modules/authorization_test.go index 1bd6e92da..3d2542dd6 100644 --- a/pkg/modules/authorization_test.go +++ b/pkg/modules/authorization_test.go @@ -185,7 +185,6 @@ func TestAuthInjectDaemonset(t *testing.T) { } else { assert.Error(t, err) } - }) } } @@ -281,11 +280,10 @@ func TestAuthInjectDeployment(t *testing.T) { } else { assert.Error(t, err) } - }) } - } + func TestAuthorizationPreCheck(t *testing.T) { tests := map[string]func(t *testing.T) (bool, csmv1.Module, csmv1.ContainerStorageModule, ctrlClient.Client){ "success": func(*testing.T) (bool, csmv1.Module, csmv1.ContainerStorageModule, ctrlClient.Client) { @@ -414,11 +412,9 @@ func TestAuthorizationPreCheck(t *testing.T) { err := AuthorizationPrecheck(context.TODO(), operatorConfig, auth, tmpCR, client) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -427,7 +423,6 @@ func TestAuthorizationServerPreCheck(t *testing.T) { type fakeControllerRuntimeClientWrapper func(clusterConfigData []byte) (ctrlClient.Client, error) tests := map[string]func(t *testing.T) (bool, csmv1.Module, csmv1.ContainerStorageModule, ctrlClient.Client, fakeControllerRuntimeClientWrapper){ - "success": func(*testing.T) (bool, csmv1.Module, csmv1.ContainerStorageModule, ctrlClient.Client, fakeControllerRuntimeClientWrapper) { customResource, err := getCustomResource("./testdata/cr_auth_proxy.yaml") if err != nil { @@ -535,11 +530,9 @@ func TestAuthorizationServerPreCheck(t *testing.T) { err := AuthorizationServerPrecheck(context.TODO(), operatorConfig, auth, tmpCR, &fakeReconcile) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -606,7 +599,6 @@ func TestAuthorizationServerDeployment(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := AuthorizationServerDeployment(context.TODO(), isDeleting, op, cr, sourceClient) @@ -615,7 +607,6 @@ func TestAuthorizationServerDeployment(t *testing.T) { } else { assert.Error(t, err) } - }) } } @@ -784,7 +775,6 @@ func TestAuthorizationIngress(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) fakeReconcile := utils.FakeReconcileCSM{ Client: sourceClient, @@ -796,7 +786,6 @@ func TestAuthorizationIngress(t *testing.T) { } else { assert.Error(t, err) } - }) } } @@ -852,7 +841,6 @@ func TestInstallPolicies(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := InstallPolicies(context.TODO(), isDeleting, op, cr, sourceClient) @@ -861,7 +849,6 @@ func TestInstallPolicies(t *testing.T) { } else { assert.Error(t, err) } - }) } } @@ -915,17 +902,14 @@ func TestNginxIngressController(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := NginxIngressController(context.TODO(), isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } diff --git a/pkg/modules/commonconfig_test.go b/pkg/modules/commonconfig_test.go index f79208761..02904fa15 100644 --- a/pkg/modules/commonconfig_test.go +++ b/pkg/modules/commonconfig_test.go @@ -10,11 +10,10 @@ package modules import ( "context" - "os" - "testing" - "fmt" "log" + "os" + "testing" csmv1 "github.com/dell/csm-operator/api/v1" utils "github.com/dell/csm-operator/pkg/utils" @@ -53,7 +52,6 @@ func getCustomResource(path string) (csmv1.ContainerStorageModule, error) { b, err := os.ReadFile(path) if err != nil { log.Fatalf("failed to read testdata: %v", err) - } customResource := csmv1.ContainerStorageModule{} err = yaml.Unmarshal(b, &customResource) @@ -62,7 +60,6 @@ func getCustomResource(path string) (csmv1.ContainerStorageModule, error) { } return customResource, nil - } func getSecret(namespace, secretName string) *corev1.Secret { @@ -97,6 +94,7 @@ func getConfigMap(namespace, configmapName string) *corev1.ConfigMap { }, } } + func TestCommonCertManager(t *testing.T) { tests := map[string]func(t *testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig){ "success - deleting": func(*testing.T) (bool, bool, csmv1.ContainerStorageModule, ctrlClient.Client, utils.OperatorConfig) { @@ -146,17 +144,14 @@ func TestCommonCertManager(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := CommonCertManager(context.TODO(), isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } diff --git a/pkg/modules/observability.go b/pkg/modules/observability.go index d85f0ea74..8ff632a54 100644 --- a/pkg/modules/observability.go +++ b/pkg/modules/observability.go @@ -214,7 +214,7 @@ var defaultSecretsName = map[csmv1.DriverType]string{ var defaultAuthSecretsName = []string{"karavi-authorization-config", "proxy-authz-tokens", "proxy-server-root-certificate"} // ObservabilityPrecheck - runs precheck for CSM Observability -func ObservabilityPrecheck(ctx context.Context, op utils.OperatorConfig, obs csmv1.Module, cr csmv1.ContainerStorageModule, r utils.ReconcileCSM) error { +func ObservabilityPrecheck(ctx context.Context, op utils.OperatorConfig, obs csmv1.Module, cr csmv1.ContainerStorageModule, _ utils.ReconcileCSM) error { log := logger.GetLogger(ctx) if _, ok := ObservabilitySupportedDrivers[string(cr.Spec.Driver.CSIDriverType)]; !ok { @@ -375,7 +375,7 @@ func PowerScaleMetrics(ctx context.Context, isDeleting bool, op utils.OperatorCo return err } - //update secret volume and inject authorization to deployment + // update secret volume and inject authorization to deployment var dpApply *confv1.DeploymentApplyConfiguration foundDp := false for i, obj := range powerscaleMetricsObjects { @@ -723,14 +723,13 @@ func getObservabilityModule(cr csmv1.ContainerStorageModule) (csmv1.Module, erro for _, m := range cr.Spec.Modules { if m.Name == csmv1.Observability { return m, nil - } } return csmv1.Module{}, fmt.Errorf("could not find observability module") } // appendObservabilitySecrets - append secrets from driver namespace including auth secrets, change their namespace to Observability Namespace -func appendObservabilitySecrets(ctx context.Context, cr csmv1.ContainerStorageModule, objects []client.Object, ctrlClient client.Client, k8sClient kubernetes.Interface) ([]client.Object, error) { +func appendObservabilitySecrets(ctx context.Context, cr csmv1.ContainerStorageModule, objects []client.Object, ctrlClient client.Client, _ kubernetes.Interface) ([]client.Object, error) { driverSecretName := strings.ReplaceAll(defaultSecretsName[cr.GetDriverType()], DriverDefaultReleaseName, cr.Name) if cr.Spec.Driver.AuthSecret != "" { diff --git a/pkg/modules/observability_test.go b/pkg/modules/observability_test.go index 2e23110b6..198dbaf5f 100644 --- a/pkg/modules/observability_test.go +++ b/pkg/modules/observability_test.go @@ -227,11 +227,9 @@ func TestObservabilityPrecheck(t *testing.T) { err := ObservabilityPrecheck(ctx, operatorConfig, observability, tmpCR, &fakeReconcile) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -289,17 +287,14 @@ func TestObservabilityTopologyController(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := ObservabilityTopology(ctx, isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -371,7 +366,7 @@ func TestPowerScaleMetrics(t *testing.T) { sourceClient := ctrlClientFake.NewClientBuilder().WithObjects(isilonCreds, karaviAuthconfig, proxyAuthzTokens).Build() k8sClient := clientgoclient.NewFakeClient(sourceClient) - //pre-run to generate objects + // pre-run to generate objects err = PowerScaleMetrics(ctx, false, operatorConfig, tmpCR, sourceClient, k8sClient) if err != nil { panic(err) @@ -425,7 +420,7 @@ func TestPowerScaleMetrics(t *testing.T) { fakeClient.Create(ctx, karaviAuthconfig) fakeClient.Create(ctx, proxyAuthzTokens) k8sClient := clientgoclient.NewFakeClient(fakeClient) - //pre-run to generate objects + // pre-run to generate objects err = PowerScaleMetrics(ctx, false, operatorConfig, customResource, fakeClient, k8sClient) if err != nil { panic(err) @@ -507,17 +502,14 @@ func TestPowerScaleMetrics(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) k8sClient := clientgoclient.NewFakeClient(sourceClient) err := PowerScaleMetrics(ctx, isDeleting, op, cr, sourceClient, k8sClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -574,17 +566,14 @@ func TestOtelCollector(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := OtelCollector(ctx, isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -656,7 +645,7 @@ func TestPowerFlexMetrics(t *testing.T) { sourceClient := ctrlClientFake.NewClientBuilder().WithObjects(vxflexosCreds, karaviAuthconfig, proxyAuthzTokens).Build() k8sClient := clientgoclient.NewFakeClient(sourceClient) - //pre-run to generate objects + // pre-run to generate objects err = PowerFlexMetrics(ctx, false, operatorConfig, tmpCR, sourceClient, k8sClient) if err != nil { panic(err) @@ -710,7 +699,7 @@ func TestPowerFlexMetrics(t *testing.T) { fakeClient.Create(ctx, karaviAuthconfig) fakeClient.Create(ctx, proxyAuthzTokens) k8sClient := clientgoclient.NewFakeClient(fakeClient) - //pre-run to generate objects + // pre-run to generate objects err = PowerFlexMetrics(ctx, false, operatorConfig, customResource, fakeClient, k8sClient) if err != nil { panic(err) @@ -769,17 +758,14 @@ func TestPowerFlexMetrics(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) k8sClient := clientgoclient.NewFakeClient(sourceClient) err := PowerFlexMetrics(ctx, isDeleting, op, cr, sourceClient, k8sClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -851,7 +837,7 @@ func TestPowerMaxMetrics(t *testing.T) { sourceClient := ctrlClientFake.NewClientBuilder().WithObjects(pmaxCreds, karaviAuthconfig, proxyAuthzTokens).Build() k8sClient := clientgoclient.NewFakeClient(sourceClient) - //pre-run to generate objects + // pre-run to generate objects err = PowerMaxMetrics(ctx, false, operatorConfig, tmpCR, sourceClient, k8sClient) if err != nil { panic(err) @@ -905,7 +891,7 @@ func TestPowerMaxMetrics(t *testing.T) { fakeClient.Create(ctx, karaviAuthconfig) fakeClient.Create(ctx, proxyAuthzTokens) k8sClient := clientgoclient.NewFakeClient(fakeClient) - //pre-run to generate objects + // pre-run to generate objects err = PowerMaxMetrics(ctx, false, operatorConfig, customResource, fakeClient, k8sClient) if err != nil { panic(err) @@ -968,17 +954,14 @@ func TestPowerMaxMetrics(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) k8sClient := clientgoclient.NewFakeClient(sourceClient) err := PowerMaxMetrics(ctx, isDeleting, op, cr, sourceClient, k8sClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } diff --git a/pkg/modules/replication.go b/pkg/modules/replication.go index de6349636..5eb19c0c0 100644 --- a/pkg/modules/replication.go +++ b/pkg/modules/replication.go @@ -58,7 +58,7 @@ var ( // XCSIReplicaCTXPrefix - XCSIReplicaCTXPrefix = "X_CSI_REPLICATION_CONTEXT_PREFIX" // XCSIReplicaPrefix - - XCSIReplicaPrefix = "X_CSI_REPLICATION_PREFIX" + XCSIReplicaPrefix = "X_CSI_REPLICATION_PREFIX" // #nosec G101 ) // ReplicationSupportedDrivers is a map containing the CSI Drivers supported by CSM Replication. The key is driver name and the value is the driver plugin identifier diff --git a/pkg/modules/replication_test.go b/pkg/modules/replication_test.go index 3e901b65e..8e3c7f513 100644 --- a/pkg/modules/replication_test.go +++ b/pkg/modules/replication_test.go @@ -27,12 +27,10 @@ import ( ctrlClientFake "sigs.k8s.io/controller-runtime/pkg/client/fake" ) -var ( - // where to find all the yaml files - config = utils.OperatorConfig{ - ConfigDirectory: "../../tests/config", - } -) +// where to find all the yaml files +var config = utils.OperatorConfig{ + ConfigDirectory: "../../tests/config", +} func TestReplicationInjectDeployment(t *testing.T) { ctx := context.Background() @@ -90,7 +88,6 @@ func TestReplicationInjectDeployment(t *testing.T) { } else { assert.Error(t, err) } - }) } } @@ -179,7 +176,7 @@ func TestReplicationPreCheck(t *testing.T) { cluster1ConfigSecret := getSecret(utils.ReplicationControllerNameSpace, "test-target-cluster-1") cluster2ConfigSecret := getSecret(utils.ReplicationControllerNameSpace, "test-target-cluster-2") - var configJSONFileGood = fmt.Sprintf("%s/driverconfig/%s/config.json", config.ConfigDirectory, csmv1.PowerFlex) + configJSONFileGood := fmt.Sprintf("%s/driverconfig/%s/config.json", config.ConfigDirectory, csmv1.PowerFlex) driverSecret1 := shared.MakeSecretWithJSON(customResource.Name+"-config", customResource.Namespace, configJSONFileGood) driverSecret2 := getSecret(customResource.Namespace, customResource.Name+"-certs-0") @@ -351,11 +348,9 @@ func TestReplicationPreCheck(t *testing.T) { err := ReplicationPrecheck(context.TODO(), operatorConfig, replica, tmpCR, &fakeReconcile) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -400,17 +395,14 @@ func TestReplicationManagerController(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - success, isDeleting, cr, sourceClient, op := tc(t) err := ReplicationManagerController(context.TODO(), isDeleting, op, cr, sourceClient) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } diff --git a/pkg/modules/resiliency.go b/pkg/modules/resiliency.go index 6ef4359b3..48300f418 100644 --- a/pkg/modules/resiliency.go +++ b/pkg/modules/resiliency.go @@ -62,7 +62,7 @@ var ResiliencySupportedDrivers = map[string]SupportedDriverParam{ } // ResiliencyPrecheck - Resiliency module precheck for supported versions -func ResiliencyPrecheck(ctx context.Context, op utils.OperatorConfig, resiliency csmv1.Module, cr csmv1.ContainerStorageModule, r utils.ReconcileCSM) error { +func ResiliencyPrecheck(ctx context.Context, op utils.OperatorConfig, resiliency csmv1.Module, cr csmv1.ContainerStorageModule, _ utils.ReconcileCSM) error { log := logger.GetLogger(ctx) if _, ok := ResiliencySupportedDrivers[string(cr.Spec.Driver.CSIDriverType)]; !ok { @@ -81,7 +81,6 @@ func ResiliencyPrecheck(ctx context.Context, op utils.OperatorConfig, resiliency log.Infof("\nperformed pre checks for: %s", resiliency.Name) return nil - } // ResiliencyInjectClusterRole - inject resiliency into clusterrole @@ -117,7 +116,7 @@ func getResiliencyModule(cr csmv1.ContainerStorageModule) (csmv1.Module, error) return csmv1.Module{}, fmt.Errorf("could not find resiliency module") } -func getResiliencyEnv(resiliencyModule csmv1.Module, driverType csmv1.DriverType) string { +func getResiliencyEnv(resiliencyModule csmv1.Module, _ csmv1.DriverType) string { for _, component := range resiliencyModule.Components { if component.Name == utils.PodmonNodeComponent { for _, env := range component.Envs { diff --git a/pkg/modules/resiliency_test.go b/pkg/modules/resiliency_test.go index b53cd77e5..e36c2dea1 100644 --- a/pkg/modules/resiliency_test.go +++ b/pkg/modules/resiliency_test.go @@ -166,6 +166,7 @@ func TestResiliencyInjectClusterRole(t *testing.T) { }) } } + func TestResiliencyPrecheck(t *testing.T) { type fakeControllerRuntimeClientWrapper func(clusterConfigData []byte) (ctrlClient.Client, error) @@ -267,11 +268,9 @@ func TestResiliencyPrecheck(t *testing.T) { err := ResiliencyPrecheck(context.TODO(), operatorConfig, replica, tmpCR, &fakeReconcile) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } diff --git a/pkg/modules/reverseproxy.go b/pkg/modules/reverseproxy.go index 6ab53a5c9..ecb52efed 100644 --- a/pkg/modules/reverseproxy.go +++ b/pkg/modules/reverseproxy.go @@ -31,7 +31,7 @@ import ( // Constants to be used in reverse proxy config files const ( - ReverseProxyServerComponent = "csipowermax-reverseproxy" + ReverseProxyServerComponent = "csipowermax-reverseproxy" // #nosec G101 ReverseProxyDeployement = "controller.yaml" ReverseProxyImage = "" ReverseProxyTLSSecret = "" // #nosec G101 @@ -127,6 +127,7 @@ func ReverseProxyServer(ctx context.Context, isDeleting bool, op utils.OperatorC return nil } + func getReverseProxyModule(cr csmv1.ContainerStorageModule) (csmv1.Module, error) { for _, m := range cr.Spec.Modules { if m.Name == csmv1.ReverseProxy { diff --git a/pkg/modules/reverseproxy_test.go b/pkg/modules/reverseproxy_test.go index 558302c7a..388f89c08 100644 --- a/pkg/modules/reverseproxy_test.go +++ b/pkg/modules/reverseproxy_test.go @@ -204,11 +204,9 @@ func TestReverseProxyPrecheck(t *testing.T) { err := ReverseProxyPrecheck(ctx, operatorConfig, reverseProxy, tmpCR, &fakeReconcile) if success { assert.NoError(t, err) - } else { assert.Error(t, err) } - }) } } @@ -260,7 +258,6 @@ func TestReverseProxyServer(t *testing.T) { } else { assert.Error(t, err) } - }) } } diff --git a/pkg/resources/deployment/deployment.go b/pkg/resources/deployment/deployment.go index 3dded68c8..e6c7021b3 100644 --- a/pkg/resources/deployment/deployment.go +++ b/pkg/resources/deployment/deployment.go @@ -14,15 +14,15 @@ package deployment import ( "context" + "time" + //"fmt" "github.com/dell/csm-operator/pkg/logger" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" appsv1 "k8s.io/client-go/applyconfigurations/apps/v1" "k8s.io/client-go/kubernetes" - //"reflect" - "time" ) // SleepTime - minimum time to sleep before checking the state of controller pod diff --git a/pkg/utils/status.go b/pkg/utils/status.go index 0a1560a16..30f0b5147 100644 --- a/pkg/utils/status.go +++ b/pkg/utils/status.go @@ -16,6 +16,8 @@ import ( "context" "errors" "fmt" + "strings" + "sync" "time" csmv1 "github.com/dell/csm-operator/api/v1" @@ -25,9 +27,7 @@ import ( corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" - //metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "strings" - "sync" + // metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" t1 "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" @@ -164,8 +164,10 @@ func getAccStatefulSetStatus(ctx context.Context, instance *csmv1.ApexConnectivi log.Infof("statefulSet status for cluster: %s", cluster.ClusterID) msg += fmt.Sprintf("error message for %s \n", cluster.ClusterID) - err = cluster.ClusterCTRLClient.Get(ctx, t1.NamespacedName{Name: instance.GetApexConnectivityClientName(), - Namespace: instance.GetNamespace()}, statefulSet) + err = cluster.ClusterCTRLClient.Get(ctx, t1.NamespacedName{ + Name: instance.GetApexConnectivityClientName(), + Namespace: instance.GetNamespace(), + }, statefulSet) if err != nil { return 0, csmv1.PodStatus{}, err } @@ -249,8 +251,10 @@ func getDaemonSetStatus(ctx context.Context, instance *csmv1.ContainerStorageMod nodeName := instance.GetNodeName() log.Infof("nodeName is %s", nodeName) - err := cluster.ClusterCTRLClient.Get(ctx, t1.NamespacedName{Name: nodeName, - Namespace: instance.GetNamespace()}, ds) + err := cluster.ClusterCTRLClient.Get(ctx, t1.NamespacedName{ + Name: nodeName, + Namespace: instance.GetNamespace(), + }, ds) if err != nil { return 0, csmv1.PodStatus{}, err } @@ -275,8 +279,8 @@ func getDaemonSetStatus(ctx context.Context, instance *csmv1.ContainerStorageMod failedCount++ for _, cs := range pod.Status.ContainerStatuses { if cs.State.Waiting != nil && cs.State.Waiting.Reason != constants.ContainerCreating { - //message: Back-off pulling image "dellec/csi-isilon:xxxx" - //reason: ImagePullBackOff + // message: Back-off pulling image "dellec/csi-isilon:xxxx" + // reason: ImagePullBackOff log.Infow("daemonset pod container", "message", cs.State.Waiting.Message, constants.Reason, cs.State.Waiting.Reason) shortMsg := strings.Replace(cs.State.Waiting.Message, constants.PodStatusRemoveString, "", 1) @@ -316,12 +320,12 @@ func getDaemonSetStatus(ctx context.Context, instance *csmv1.ContainerStorageMod func calculateState(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, newStatus *csmv1.ContainerStorageModuleStatus) (bool, error) { log := logger.GetLogger(ctx) running := false - //appEnabled := false - //var appRunning bool - //obsEnabled := false - //var obsRunning bool - //modrunning := false - var err error = nil + // appEnabled := false + // var appRunning bool + // obsEnabled := false + // var obsRunning bool + // modrunning := false + var err error // TODO: Currently commented this block of code as the API used to get the latest deployment status is not working as expected // TODO: Can be uncommented once this issues gets sorted out /* controllerReplicas, controllerStatus, controllerErr := getDeploymentStatus(ctx, instance, r) @@ -356,7 +360,6 @@ func calculateState(ctx context.Context, instance *csmv1.ContainerStorageModule, } else { newStatus.State = constants.Failed } - } else { running = false newStatus.State = constants.Failed @@ -401,8 +404,7 @@ func calculateAccState(ctx context.Context, instance *csmv1.ApexConnectivityClie } // SetStatus of csm -func SetStatus(ctx context.Context, r ReconcileCSM, instance *csmv1.ContainerStorageModule, newStatus *csmv1.ContainerStorageModuleStatus) { - +func SetStatus(ctx context.Context, _ ReconcileCSM, instance *csmv1.ContainerStorageModule, newStatus *csmv1.ContainerStorageModuleStatus) { log := logger.GetLogger(ctx) instance.GetCSMStatus().State = newStatus.State log.Infow("Driver State", "Controller", @@ -412,8 +414,7 @@ func SetStatus(ctx context.Context, r ReconcileCSM, instance *csmv1.ContainerSto } // SetAccStatus of csm -func SetAccStatus(ctx context.Context, r ReconcileCSM, instance *csmv1.ApexConnectivityClient, newStatus *csmv1.ApexConnectivityClientStatus) { - +func SetAccStatus(ctx context.Context, _ ReconcileCSM, instance *csmv1.ApexConnectivityClient, newStatus *csmv1.ApexConnectivityClientStatus) { log := logger.GetLogger(ctx) instance.GetApexConnectivityClientStatus().State = newStatus.State log.Infow("Apex Client State", "Client", @@ -440,8 +441,10 @@ func UpdateStatus(ctx context.Context, instance *csmv1.ContainerStorageModule, r log := logger.GetLogger(ctx) csm := new(csmv1.ContainerStorageModule) - err := r.GetClient().Get(ctx, t1.NamespacedName{Name: instance.Name, - Namespace: instance.GetNamespace()}, csm) + err := r.GetClient().Get(ctx, t1.NamespacedName{ + Name: instance.Name, + Namespace: instance.GetNamespace(), + }, csm) if err != nil { return err } @@ -484,8 +487,10 @@ func UpdateAccStatus(ctx context.Context, instance *csmv1.ApexConnectivityClient _, merr := calculateAccState(ctx, instance, r, newStatus) csm := new(csmv1.ApexConnectivityClient) - err := r.GetClient().Get(ctx, t1.NamespacedName{Name: instance.Name, - Namespace: instance.GetNamespace()}, csm) + err := r.GetClient().Get(ctx, t1.NamespacedName{ + Name: instance.Name, + Namespace: instance.GetNamespace(), + }, csm) if err != nil { return err } @@ -501,7 +506,8 @@ func UpdateAccStatus(ctx context.Context, instance *csmv1.ApexConnectivityClient // HandleValidationError for csm func HandleValidationError(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, - validationError error) (reconcile.Result, error) { + validationError error, +) (reconcile.Result, error) { dMutex.Lock() defer dMutex.Unlock() log := logger.GetLogger(ctx) @@ -520,7 +526,8 @@ func HandleValidationError(ctx context.Context, instance *csmv1.ContainerStorage // HandleAccValidationError for csm func HandleAccValidationError(ctx context.Context, instance *csmv1.ApexConnectivityClient, r ReconcileCSM, - validationError error) (reconcile.Result, error) { + validationError error, +) (reconcile.Result, error) { dMutex.Lock() defer dMutex.Unlock() log := logger.GetLogger(ctx) @@ -599,7 +606,8 @@ func GetNginxControllerStatus(ctx context.Context, instance csmv1.ContainerStora err := r.GetClient().Get(ctx, t1.NamespacedName{ Name: name, - Namespace: instance.GetNamespace()}, deployment) + Namespace: instance.GetNamespace(), + }, deployment) if err != nil { if k8serrors.IsNotFound(err) { return false, err @@ -637,8 +645,7 @@ func WaitForNginxController(ctx context.Context, instance csmv1.ContainerStorage } // statusForAppMob - calculate success state for application-mobility module -func appMobStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, newStatus *csmv1.ContainerStorageModuleStatus) (bool, error) { - +func appMobStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, _ *csmv1.ContainerStorageModuleStatus) (bool, error) { log := logger.GetLogger(ctx) veleroEnabled := false certEnabled := false @@ -665,15 +672,12 @@ func appMobStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModu } } - } - } namespace := instance.GetNamespace() opts := []client.ListOption{ client.InNamespace(namespace), - //client.MatchingLabels{labelKey: label}, } deploymentList := &appsv1.DeploymentList{} @@ -752,15 +756,14 @@ func appMobStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModu } return false, nil - } // observabilityStatusCheck - calculate success state for observability module -func observabilityStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, newStatus *csmv1.ContainerStorageModuleStatus) (bool, error) { - //log := logger.GetLogger(ctx) +func observabilityStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, _ *csmv1.ContainerStorageModuleStatus) (bool, error) { + // log := logger.GetLogger(ctx) // Observability launches three pods in the karavi namespace - //expectedObservabilityPods := 3 - //readyPods := 0 + // expectedObservabilityPods := 3 + // readyPods := 0 topologyEnabled := false otelEnabled := false certEnabled := false @@ -834,7 +837,6 @@ func observabilityStatusCheck(ctx context.Context, instance *csmv1.ContainerStor namespaceCert := instance.GetNamespace() opts = []client.ListOption{ client.InNamespace(namespaceCert), - //client.MatchingLabels{labelKey: label}, } deploymentCertList := &appsv1.DeploymentList{} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index cc32640ac..2644e090c 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -938,7 +938,7 @@ func getClusterK8SClient(ctx context.Context, clusterID string, ctrlClient crcli } // IsResiliencyModuleEnabled - check if resiliency module is enabled or not -func IsResiliencyModuleEnabled(ctx context.Context, instance csmv1.ContainerStorageModule, r ReconcileCSM) bool { +func IsResiliencyModuleEnabled(_ context.Context, instance csmv1.ContainerStorageModule, _ ReconcileCSM) bool { for _, m := range instance.Spec.Modules { if m.Name == csmv1.Resiliency && m.Enabled { return true @@ -994,7 +994,7 @@ func GetDefaultClusters(ctx context.Context, instance csmv1.ContainerStorageModu } // GetAccDefaultClusters - get default clusters -func GetAccDefaultClusters(ctx context.Context, instance csmv1.ApexConnectivityClient, r ReconcileCSM) (bool, []ReplicaCluster, error) { +func GetAccDefaultClusters(_ context.Context, _ csmv1.ApexConnectivityClient, r ReconcileCSM) (bool, []ReplicaCluster, error) { clusterClients := []ReplicaCluster{ { ClusterCTRLClient: r.GetClient(), @@ -1042,7 +1042,7 @@ func GetBackupStorageLocation(ctx context.Context, name, namespace string, ctrlC } // IsModuleEnabled - check if the module is enabled -func IsModuleEnabled(ctx context.Context, instance csmv1.ContainerStorageModule, mod csmv1.ModuleType) (bool, csmv1.Module) { +func IsModuleEnabled(_ context.Context, instance csmv1.ContainerStorageModule, mod csmv1.ModuleType) (bool, csmv1.Module) { for _, m := range instance.Spec.Modules { if m.Name == mod && m.Enabled { return true, m @@ -1069,7 +1069,7 @@ func IsModuleComponentEnabled(ctx context.Context, instance csmv1.ContainerStora } // IsAppMobilityComponentEnabled - check if Application Mobility componenets are enabled -func IsAppMobilityComponentEnabled(ctx context.Context, instance csmv1.ContainerStorageModule, r ReconcileCSM, mod csmv1.ModuleType, componentType string) bool { +func IsAppMobilityComponentEnabled(ctx context.Context, instance csmv1.ContainerStorageModule, _ ReconcileCSM, mod csmv1.ModuleType, componentType string) bool { appMobilityEnabled, appmobility := IsModuleEnabled(ctx, instance, mod) if !appMobilityEnabled { return false diff --git a/tests/shared/clientgoclient/fakeDaemonset.go b/tests/shared/clientgoclient/fakeDaemonset.go index 488238585..88454c941 100644 --- a/tests/shared/clientgoclient/fakeDaemonset.go +++ b/tests/shared/clientgoclient/fakeDaemonset.go @@ -32,7 +32,7 @@ type FakeDaemonSets struct { } // Apply takes the given apply declarative configuration, applies it and returns the applied daemonSet. -func (c *FakeDaemonSets) Apply(ctx context.Context, daemonSet *applyconfigurationsappsv1.DaemonSetApplyConfiguration, opts v1.ApplyOptions) (result *appsv1.DaemonSet, err error) { +func (c *FakeDaemonSets) Apply(ctx context.Context, daemonSet *applyconfigurationsappsv1.DaemonSetApplyConfiguration, _ v1.ApplyOptions) (result *appsv1.DaemonSet, err error) { result = new(appsv1.DaemonSet) data, err := json.Marshal(daemonSet) @@ -57,7 +57,7 @@ func (c *FakeDaemonSets) Apply(ctx context.Context, daemonSet *applyconfiguratio } // Get takes name of the daemonSet, and returns the corresponding daemonSet object, and an error if there is any. -func (c *FakeDaemonSets) Get(ctx context.Context, name string, options v1.GetOptions) (result *appsv1.DaemonSet, err error) { +func (c *FakeDaemonSets) Get(ctx context.Context, name string, _ v1.GetOptions) (result *appsv1.DaemonSet, err error) { result = new(appsv1.DaemonSet) k := types.NamespacedName{ @@ -70,49 +70,49 @@ func (c *FakeDaemonSets) Get(ctx context.Context, name string, options v1.GetOpt } // Create takes the representation of a daemonSet and creates it. Returns the server's representation of the daemonSet, and an error, if there is any. -func (c *FakeDaemonSets) Create(ctx context.Context, daemonSet *appsv1.DaemonSet, opts v1.CreateOptions) (result *appsv1.DaemonSet, err error) { +func (c *FakeDaemonSets) Create(ctx context.Context, daemonSet *appsv1.DaemonSet, _ v1.CreateOptions) (result *appsv1.DaemonSet, err error) { err = c.FakeClient.Create(ctx, daemonSet) return daemonSet, err } // List takes label and field selectors, and returns the list of DaemonSets that match those selectors. -func (c *FakeDaemonSets) List(ctx context.Context, opts v1.ListOptions) (result *appsv1.DaemonSetList, err error) { +func (c *FakeDaemonSets) List(_ context.Context, _ v1.ListOptions) (result *appsv1.DaemonSetList, err error) { panic("implement me") } // Watch returns a watch.Interface that watches the requested daemonSets. -func (c *FakeDaemonSets) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { +func (c *FakeDaemonSets) Watch(_ context.Context, _ v1.ListOptions) (watch.Interface, error) { panic("implement me") } // Update takes the representation of a daemonSet and updates it. Returns the server's representation of the daemonSet, and an error, if there is any. -func (c *FakeDaemonSets) Update(ctx context.Context, daemonSet *appsv1.DaemonSet, opts v1.UpdateOptions) (result *appsv1.DaemonSet, err error) { +func (c *FakeDaemonSets) Update(_ context.Context, _ *appsv1.DaemonSet, _ v1.UpdateOptions) (result *appsv1.DaemonSet, err error) { panic("implement me") } // UpdateStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeDaemonSets) UpdateStatus(ctx context.Context, daemonSet *appsv1.DaemonSet, opts v1.UpdateOptions) (*appsv1.DaemonSet, error) { +func (c *FakeDaemonSets) UpdateStatus(_ context.Context, _ *appsv1.DaemonSet, _ v1.UpdateOptions) (*appsv1.DaemonSet, error) { panic("implement me") } // Delete takes name of the daemonSet and deletes it. Returns an error if one occurs. -func (c *FakeDaemonSets) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { +func (c *FakeDaemonSets) Delete(_ context.Context, _ string, _ v1.DeleteOptions) error { panic("implement me") } // DeleteCollection deletes a collection of objects. -func (c *FakeDaemonSets) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { +func (c *FakeDaemonSets) DeleteCollection(_ context.Context, _ v1.DeleteOptions, _ v1.ListOptions) error { panic("implement me") } // Patch applies the patch and returns the patched daemonSet. -func (c *FakeDaemonSets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *appsv1.DaemonSet, err error) { +func (c *FakeDaemonSets) Patch(_ context.Context, _ string, _ types.PatchType, _ []byte, _ v1.PatchOptions, _ ...string) (result *appsv1.DaemonSet, err error) { panic("implement me") } // ApplyStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeDaemonSets) ApplyStatus(ctx context.Context, daemonSet *applyconfigurationsappsv1.DaemonSetApplyConfiguration, opts v1.ApplyOptions) (result *appsv1.DaemonSet, err error) { +func (c *FakeDaemonSets) ApplyStatus(_ context.Context, _ *applyconfigurationsappsv1.DaemonSetApplyConfiguration, _ v1.ApplyOptions) (result *appsv1.DaemonSet, err error) { panic("implement me") } diff --git a/tests/shared/clientgoclient/fakeDeployment.go b/tests/shared/clientgoclient/fakeDeployment.go index e9ff420a4..372e320cb 100644 --- a/tests/shared/clientgoclient/fakeDeployment.go +++ b/tests/shared/clientgoclient/fakeDeployment.go @@ -35,7 +35,7 @@ type FakeDeployments struct { } // Apply takes the given apply declarative configuration, applies it and returns the applied deployment. -func (c *FakeDeployments) Apply(ctx context.Context, deployment *applyconfigurationsappsv1.DeploymentApplyConfiguration, opts v1.ApplyOptions) (result *appsv1.Deployment, err error) { +func (c *FakeDeployments) Apply(ctx context.Context, deployment *applyconfigurationsappsv1.DeploymentApplyConfiguration, _ v1.ApplyOptions) (result *appsv1.Deployment, err error) { result = new(appsv1.Deployment) data, err := json.Marshal(deployment) @@ -60,7 +60,7 @@ func (c *FakeDeployments) Apply(ctx context.Context, deployment *applyconfigurat } // Get takes name of the deployment, and returns the corresponding deployment object, and an error if there is any. -func (c *FakeDeployments) Get(ctx context.Context, name string, options v1.GetOptions) (result *appsv1.Deployment, err error) { +func (c *FakeDeployments) Get(ctx context.Context, name string, _ v1.GetOptions) (result *appsv1.Deployment, err error) { result = new(appsv1.Deployment) k := types.NamespacedName{ @@ -73,71 +73,71 @@ func (c *FakeDeployments) Get(ctx context.Context, name string, options v1.GetOp } // Create takes the representation of a deployment and creates it. Returns the server's representation of the deployment, and an error, if there is any. -func (c *FakeDeployments) Create(ctx context.Context, deployment *appsv1.Deployment, opts v1.CreateOptions) (result *appsv1.Deployment, err error) { +func (c *FakeDeployments) Create(ctx context.Context, deployment *appsv1.Deployment, _ v1.CreateOptions) (result *appsv1.Deployment, err error) { err = c.FakeClient.Create(ctx, deployment) return deployment, err } // List takes label and field selectors, and returns the list of Deployments that match those selectors. -func (c *FakeDeployments) List(ctx context.Context, opts v1.ListOptions) (result *appsv1.DeploymentList, err error) { +func (c *FakeDeployments) List(_ context.Context, _ v1.ListOptions) (result *appsv1.DeploymentList, err error) { panic("implement me") } // Watch returns a watch.Interface that watches the requested deployments. -func (c *FakeDeployments) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { +func (c *FakeDeployments) Watch(_ context.Context, _ v1.ListOptions) (watch.Interface, error) { panic("implement me") } // Update takes the representation of a deployment and updates it. Returns the server's representation of the deployment, and an error, if there is any. -func (c *FakeDeployments) Update(ctx context.Context, deployment *appsv1.Deployment, opts v1.UpdateOptions) (result *appsv1.Deployment, err error) { +func (c *FakeDeployments) Update(_ context.Context, _ *appsv1.Deployment, _ v1.UpdateOptions) (result *appsv1.Deployment, err error) { panic("implement me") } // UpdateStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeDeployments) UpdateStatus(ctx context.Context, deployment *appsv1.Deployment, opts v1.UpdateOptions) (*appsv1.Deployment, error) { +func (c *FakeDeployments) UpdateStatus(_ context.Context, _ *appsv1.Deployment, _ v1.UpdateOptions) (*appsv1.Deployment, error) { panic("implement me") } // Delete takes name of the deployment and deletes it. Returns an error if one occurs. -func (c *FakeDeployments) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { +func (c *FakeDeployments) Delete(_ context.Context, _ string, _ v1.DeleteOptions) error { panic("implement me") } // DeleteCollection deletes a collection of objects. -func (c *FakeDeployments) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { +func (c *FakeDeployments) DeleteCollection(_ context.Context, _ v1.DeleteOptions, _ v1.ListOptions) error { panic("implement me") } // Patch applies the patch and returns the patched deployment. -func (c *FakeDeployments) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *appsv1.Deployment, err error) { +func (c *FakeDeployments) Patch(_ context.Context, _ string, _ types.PatchType, _ []byte, _ v1.PatchOptions, _ ...string) (result *appsv1.Deployment, err error) { panic("implement me") } // ApplyStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeDeployments) ApplyStatus(ctx context.Context, deployment *applyconfigurationsappsv1.DeploymentApplyConfiguration, opts v1.ApplyOptions) (result *appsv1.Deployment, err error) { +func (c *FakeDeployments) ApplyStatus(_ context.Context, _ *applyconfigurationsappsv1.DeploymentApplyConfiguration, _ v1.ApplyOptions) (result *appsv1.Deployment, err error) { panic("implement me") } // GetScale takes name of the deployment, and returns the corresponding scale object, and an error if there is any. -func (c *FakeDeployments) GetScale(ctx context.Context, deploymentName string, options v1.GetOptions) (result *autoscalingv1.Scale, err error) { +func (c *FakeDeployments) GetScale(_ context.Context, _ string, _ v1.GetOptions) (result *autoscalingv1.Scale, err error) { panic("implement me") } // UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. -func (c *FakeDeployments) UpdateScale(ctx context.Context, deploymentName string, scale *autoscalingv1.Scale, opts v1.UpdateOptions) (result *autoscalingv1.Scale, err error) { +func (c *FakeDeployments) UpdateScale(_ context.Context, _ string, _ *autoscalingv1.Scale, _ v1.UpdateOptions) (result *autoscalingv1.Scale, err error) { panic("implement me") } // ApplyScale takes top resource name and the apply declarative configuration for scale, // applies it and returns the applied scale, and an error, if there is any. -func (c *FakeDeployments) ApplyScale(ctx context.Context, deploymentName string, scale *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, opts v1.ApplyOptions) (result *autoscalingv1.Scale, err error) { +func (c *FakeDeployments) ApplyScale(_ context.Context, _ string, _ *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, _ v1.ApplyOptions) (result *autoscalingv1.Scale, err error) { panic("implement me") } // AutoscalingV2 takes top resource name and the apply declarative configuration for scale, // applies it and returns the applied scale, and an error, if there is any. -func (c *FakeDeployments) AutoscalingV2(ctx context.Context, deploymentName string, scale *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, opts v1.ApplyOptions) (result *autoscalingv1.Scale, err error) { +func (c *FakeDeployments) AutoscalingV2(_ context.Context, _ string, _ *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, _ v1.ApplyOptions) (result *autoscalingv1.Scale, err error) { panic("implement me") } diff --git a/tests/shared/clientgoclient/fakeappv1.go b/tests/shared/clientgoclient/fakeappv1.go index 8f1d66d03..db7d05696 100644 --- a/tests/shared/clientgoclient/fakeappv1.go +++ b/tests/shared/clientgoclient/fakeappv1.go @@ -47,16 +47,16 @@ func (c *FakeAppsV1) RESTClient() rest.Interface { } // ControllerRevisions takes a namespace and returns an ControllerRevisionInterface -func (c *FakeAppsV1) ControllerRevisions(namespace string) v1.ControllerRevisionInterface { +func (c *FakeAppsV1) ControllerRevisions(_ string) v1.ControllerRevisionInterface { panic("implement me") } // ReplicaSets takes a namespace and returns an ReplicaSetInterface -func (c *FakeAppsV1) ReplicaSets(namespace string) v1.ReplicaSetInterface { +func (c *FakeAppsV1) ReplicaSets(_ string) v1.ReplicaSetInterface { panic("implement me") } // StatefulSets takes a namespace and returns an StatefulSetInterface -func (c *FakeAppsV1) StatefulSets(namespace string) v1.StatefulSetInterface { +func (c *FakeAppsV1) StatefulSets(_ string) v1.StatefulSetInterface { panic("implement me") } diff --git a/tests/shared/common.go b/tests/shared/common.go index 0c6beba53..82477380c 100644 --- a/tests/shared/common.go +++ b/tests/shared/common.go @@ -127,7 +127,7 @@ func MakeModuleCSM(name, ns, configVersion string) csmv1.ContainerStorageModule } // MakeApexConnectivityClient returns a driver object from given params -func MakeApexConnectivityClient(configVersion, skipCertValid string) csmv1.Client { +func MakeApexConnectivityClient(configVersion, _ string) csmv1.Client { ApexConnectivityClientObj := csmv1.Client{ ConfigVersion: configVersion, } @@ -184,7 +184,7 @@ func MakeModule(configVersion string) csmv1.Module { } // MakeSecret returns a driver pre-req secret array-config -func MakeSecret(name, ns, configVersion string) *corev1.Secret { +func MakeSecret(name, ns, _ string) *corev1.Secret { data := map[string][]byte{ "config": []byte("csm"), } @@ -194,7 +194,7 @@ func MakeSecret(name, ns, configVersion string) *corev1.Secret { } // MakeConfigMap returns a driver pre-req configmap array-config -func MakeConfigMap(name, ns, configVersion string) *corev1.ConfigMap { +func MakeConfigMap(name, ns, _ string) *corev1.ConfigMap { return &corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ APIVersion: corev1.SchemeGroupVersion.String(), @@ -235,7 +235,7 @@ func MakePod(name, ns string) corev1.Pod { } // MakeReverseProxyModule returns a csireverseproxy object -func MakeReverseProxyModule(configVersion string) csmv1.Module { +func MakeReverseProxyModule(_ string) csmv1.Module { revproxy := csmv1.Module{ Name: csmv1.ReverseProxy, Enabled: true, diff --git a/tests/shared/crclient/client.go b/tests/shared/crclient/client.go index 4de5a71db..b3bba13cd 100644 --- a/tests/shared/crclient/client.go +++ b/tests/shared/crclient/client.go @@ -62,7 +62,7 @@ func NewFakeClientNoInjector(objectMap map[shared.StorageKey]runtime.Object) *Cl } // Get implements client.Client. -func (f Client) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { +func (f Client) Get(_ context.Context, key client.ObjectKey, obj client.Object, _ ...client.GetOption) error { if f.ErrorInjector != nil { if err := f.ErrorInjector.ShouldFail("Get", obj); err != nil { return err @@ -97,7 +97,7 @@ func (f Client) Get(ctx context.Context, key client.ObjectKey, obj client.Object } // List implements client.Client. -func (f Client) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { +func (f Client) List(ctx context.Context, list client.ObjectList, _ ...client.ListOption) error { if f.ErrorInjector != nil { if err := f.ErrorInjector.ShouldFail("List", list); err != nil { return err @@ -122,7 +122,7 @@ func (f Client) listPodList(list *corev1.PodList) error { return nil } -func (f Client) listDeploymentList(ctx context.Context, list *appsv1.DeploymentList) error { +func (f Client) listDeploymentList(_ context.Context, list *appsv1.DeploymentList) error { for k, v := range f.Objects { if k.Kind == "Deployment" { list.Items = append(list.Items, *v.(*appsv1.Deployment)) @@ -132,7 +132,7 @@ func (f Client) listDeploymentList(ctx context.Context, list *appsv1.DeploymentL } // Create implements client.Client. -func (f Client) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error { +func (f Client) Create(_ context.Context, obj client.Object, _ ...client.CreateOption) error { if f.ErrorInjector != nil { if err := f.ErrorInjector.ShouldFail("Create", obj); err != nil { return err @@ -159,7 +159,7 @@ func (f Client) Create(ctx context.Context, obj client.Object, opts ...client.Cr } // Delete implements client.Client. -func (f Client) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error { +func (f Client) Delete(_ context.Context, obj client.Object, opts ...client.DeleteOption) error { if f.ErrorInjector != nil { if err := f.ErrorInjector.ShouldFail("Delete", obj); err != nil { return err @@ -208,7 +208,7 @@ func (f Client) Clear() { } // SetDeletionTimeStamp so that reconcile can go into deletion part of code -func (f Client) SetDeletionTimeStamp(ctx context.Context, obj client.Object) error { +func (f Client) SetDeletionTimeStamp(_ context.Context, obj client.Object) error { k, err := shared.GetKey(obj) if err != nil { return err @@ -224,7 +224,7 @@ func (f Client) SetDeletionTimeStamp(ctx context.Context, obj client.Object) err } // Update implements client.StatusWriter. -func (f Client) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error { +func (f Client) Update(_ context.Context, obj client.Object, _ ...client.UpdateOption) error { if f.ErrorInjector != nil { if err := f.ErrorInjector.ShouldFail("Update", obj); err != nil { return err @@ -251,22 +251,22 @@ func (f Client) Update(ctx context.Context, obj client.Object, opts ...client.Up } // Patch implements client.Client. -func (f Client) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error { +func (f Client) Patch(_ context.Context, _ client.Object, _ client.Patch, _ ...client.PatchOption) error { panic("implement me") } // DeleteAllOf implements client.Client. -func (f Client) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error { +func (f Client) DeleteAllOf(_ context.Context, _ client.Object, _ ...client.DeleteAllOfOption) error { panic("implement me") } // GroupVersionKindFor returns the GroupVersionKind for the given object. -func (f Client) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error) { +func (f Client) GroupVersionKindFor(_ runtime.Object) (schema.GroupVersionKind, error) { panic("implement me") } // IsObjectNamespaced returns true if the GroupVersionKind of the object is namespaced. -func (f Client) IsObjectNamespaced(obj runtime.Object) (bool, error) { +func (f Client) IsObjectNamespaced(_ runtime.Object) (bool, error) { panic("implement me") } @@ -291,22 +291,22 @@ func (f Client) RESTMapper() meta.RESTMapper { } // Create implements client.SubResourceClient -func (sc *subResourceClient) Create(ctx context.Context, obj client.Object, subResource client.Object, opts ...client.SubResourceCreateOption) error { +func (sc *subResourceClient) Create(_ context.Context, _ client.Object, _ client.Object, _ ...client.SubResourceCreateOption) error { panic("implement me") } // Update implements client.SubResourceClient -func (sc *subResourceClient) Update(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error { +func (sc *subResourceClient) Update(ctx context.Context, obj client.Object, _ ...client.SubResourceUpdateOption) error { // We are currently not using options in update so they don't need to be passed return sc.client.Update(ctx, obj) } // Patch implements client.SubResourceWriter -func (sc *subResourceClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) error { +func (sc *subResourceClient) Patch(_ context.Context, _ client.Object, _ client.Patch, _ ...client.SubResourcePatchOption) error { panic("implement me") } // Get out of here -func (sc *subResourceClient) Get(ctx context.Context, obj client.Object, subResource client.Object, opts ...client.SubResourceGetOption) error { +func (sc *subResourceClient) Get(_ context.Context, _ client.Object, _ client.Object, _ ...client.SubResourceGetOption) error { panic("not implemented") }