diff --git a/.golangci.yaml b/.golangci.yaml index addfa1d50a..4c05feeecb 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -75,9 +75,9 @@ linters-settings: - name: unused-receiver - name: unused-parameter # - name: confusing-naming - # - name: import-shadowing + - name: import-shadowing - name: confusing-results - # - name: bool-literal-in-expr + - name: bool-literal-in-expr issues: exclude-rules: diff --git a/controllers/drcluster_mmode_test.go b/controllers/drcluster_mmode_test.go index 011e35d207..c5d2751423 100644 --- a/controllers/drcluster_mmode_test.go +++ b/controllers/drcluster_mmode_test.go @@ -62,7 +62,7 @@ var _ = Describe("DRClusterMModeTests", Ordered, func() { }, } - if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster == true { + if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster { namespaceDeletionSupported = true } diff --git a/controllers/drpc_predicate_test.go b/controllers/drpc_predicate_test.go index 00f78bd2c7..0f3ab8eaac 100644 --- a/controllers/drpc_predicate_test.go +++ b/controllers/drpc_predicate_test.go @@ -239,7 +239,7 @@ var _ = Describe("DRPCPredicateDRCluster", func() { }, } - if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster == true { + if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster { namespaceDeletionSupported = true } diff --git a/controllers/drplacementcontrol_controller.go b/controllers/drplacementcontrol_controller.go index 32a695706f..d8099955b7 100644 --- a/controllers/drplacementcontrol_controller.go +++ b/controllers/drplacementcontrol_controller.go @@ -1060,13 +1060,13 @@ func (r DRPlacementControlReconciler) updateObjectMetadata(ctx context.Context, return nil } -func getDRClusters(ctx context.Context, client client.Client, drPolicy *rmn.DRPolicy) ([]rmn.DRCluster, error) { +func getDRClusters(ctx context.Context, cli client.Client, drPolicy *rmn.DRPolicy) ([]rmn.DRCluster, error) { drClusters := []rmn.DRCluster{} for _, managedCluster := range rmnutil.DrpolicyClusterNames(drPolicy) { drCluster := &rmn.DRCluster{} - err := client.Get(ctx, types.NamespacedName{Name: managedCluster}, drCluster) + err := cli.Get(ctx, types.NamespacedName{Name: managedCluster}, drCluster) if err != nil { return nil, fmt.Errorf("failed to get DRCluster (%s) %w", managedCluster, err) } @@ -2021,12 +2021,12 @@ func (r *DRPlacementControlReconciler) createPlacementDecision(ctx context.Conte } func getApplicationDestinationNamespace( - client client.Client, + cli client.Client, log logr.Logger, placement client.Object, ) (string, error) { appSetList := argocdv1alpha1hack.ApplicationSetList{} - if err := client.List(context.TODO(), &appSetList); err != nil { + if err := cli.List(context.TODO(), &appSetList); err != nil { // If ApplicationSet CRD is not found in the API server, // default to Subscription behavior, and return the placement namespace as the target VRG namespace if meta.IsNoMatchError(err) { @@ -2064,7 +2064,7 @@ func getApplicationDestinationNamespace( } func selectVRGNamespace( - client client.Client, + cli client.Client, log logr.Logger, drpc *rmn.DRPlacementControl, placementObj client.Object, @@ -2075,7 +2075,7 @@ func selectVRGNamespace( switch placementObj.(type) { case *clrapiv1beta1.Placement: - vrgNamespace, err := getApplicationDestinationNamespace(client, log, placementObj) + vrgNamespace, err := getApplicationDestinationNamespace(cli, log, placementObj) if err != nil { return "", err } @@ -2119,14 +2119,14 @@ func ensureDRPCConditionsInited(conditions *[]metav1.Condition, observedGenerati return } - time := metav1.NewTime(time.Now()) + timestamp := metav1.NewTime(time.Now()) setStatusConditionIfNotFound(conditions, metav1.Condition{ Type: rmn.ConditionAvailable, Reason: string(rmn.Initiating), ObservedGeneration: observedGeneration, Status: metav1.ConditionTrue, - LastTransitionTime: time, + LastTransitionTime: timestamp, Message: message, }) setStatusConditionIfNotFound(conditions, metav1.Condition{ @@ -2134,7 +2134,7 @@ func ensureDRPCConditionsInited(conditions *[]metav1.Condition, observedGenerati Reason: string(rmn.Initiating), ObservedGeneration: observedGeneration, Status: metav1.ConditionTrue, - LastTransitionTime: time, + LastTransitionTime: timestamp, Message: message, }) } diff --git a/controllers/status.go b/controllers/status.go index 07bafb6b08..442fc04292 100644 --- a/controllers/status.go +++ b/controllers/status.go @@ -79,14 +79,14 @@ func setVRGInitialCondition(conditions *[]metav1.Condition, observedGeneration i return } - time := metav1.NewTime(time.Now()) + timestamp := metav1.NewTime(time.Now()) setStatusConditionIfNotFound(conditions, metav1.Condition{ Type: VRGConditionTypeDataReady, Reason: VRGConditionReasonInitializing, ObservedGeneration: observedGeneration, Status: metav1.ConditionUnknown, - LastTransitionTime: time, + LastTransitionTime: timestamp, Message: message, }) setStatusConditionIfNotFound(conditions, metav1.Condition{ @@ -94,7 +94,7 @@ func setVRGInitialCondition(conditions *[]metav1.Condition, observedGeneration i Reason: VRGConditionReasonInitializing, ObservedGeneration: observedGeneration, Status: metav1.ConditionUnknown, - LastTransitionTime: time, + LastTransitionTime: timestamp, Message: message, }) setStatusConditionIfNotFound(conditions, metav1.Condition{ @@ -102,7 +102,7 @@ func setVRGInitialCondition(conditions *[]metav1.Condition, observedGeneration i Reason: VRGConditionReasonInitializing, ObservedGeneration: observedGeneration, Status: metav1.ConditionUnknown, - LastTransitionTime: time, + LastTransitionTime: timestamp, Message: message, }) setStatusConditionIfNotFound(conditions, metav1.Condition{ @@ -110,7 +110,7 @@ func setVRGInitialCondition(conditions *[]metav1.Condition, observedGeneration i Reason: VRGConditionReasonInitializing, ObservedGeneration: observedGeneration, Status: metav1.ConditionUnknown, - LastTransitionTime: time, + LastTransitionTime: timestamp, Message: message, }) } diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 6cb25be4f0..cf383c0555 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -147,7 +147,7 @@ var _ = BeforeSuite(func() { }, } - if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster == true { + if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster { namespaceDeletionSupported = true } diff --git a/controllers/util/drpolicy_util.go b/controllers/util/drpolicy_util.go index 021138a0b2..1d2256850a 100644 --- a/controllers/util/drpolicy_util.go +++ b/controllers/util/drpolicy_util.go @@ -58,10 +58,10 @@ func DrpolicyValidated(drpolicy *rmn.DRPolicy) error { return errors.New(`validated condition absent`) } -func GetAllDRPolicies(ctx context.Context, client client.Reader) (rmn.DRPolicyList, error) { +func GetAllDRPolicies(ctx context.Context, cli client.Reader) (rmn.DRPolicyList, error) { drpolicies := rmn.DRPolicyList{} - if err := client.List(ctx, &drpolicies); err != nil { + if err := cli.List(ctx, &drpolicies); err != nil { return drpolicies, fmt.Errorf("unable to fetch drpolicies: %w", err) } diff --git a/controllers/util/misc.go b/controllers/util/misc.go index 255c8b1d7c..c948447e2e 100644 --- a/controllers/util/misc.go +++ b/controllers/util/misc.go @@ -20,7 +20,7 @@ func GenericAddLabelsAndFinalizers( ctx context.Context, object client.Object, finalizerName string, - client client.Client, + cli client.Client, log logr.Logger, ) error { labelAdded := AddLabel(object, OCMBackupLabelKey, OCMBackupLabelValue) @@ -29,7 +29,7 @@ func GenericAddLabelsAndFinalizers( if finalizerAdded || labelAdded { log.Info("finalizer or label add") - return client.Update(ctx, object) + return cli.Update(ctx, object) } return nil @@ -39,7 +39,7 @@ func GenericFinalizerRemove( ctx context.Context, object client.Object, finalizerName string, - client client.Client, + cli client.Client, log logr.Logger, ) error { finalizerCount := len(object.GetFinalizers()) @@ -48,7 +48,7 @@ func GenericFinalizerRemove( if len(object.GetFinalizers()) != finalizerCount { log.Info("finalizer remove") - return client.Update(ctx, object) + return cli.Update(ctx, object) } return nil diff --git a/controllers/util/owner.go b/controllers/util/owner.go index 7d71876364..39c82826e5 100644 --- a/controllers/util/owner.go +++ b/controllers/util/owner.go @@ -16,7 +16,7 @@ import ( ) func OwnsAcrossNamespaces( - builder *builder.Builder, + blder *builder.Builder, scheme *runtime.Scheme, object client.Object, opts ...builder.WatchesOption, @@ -24,7 +24,7 @@ func OwnsAcrossNamespaces( groupVersionKinds, _, _ := scheme.ObjectKinds(object) //nolint:errcheck log := ctrl.Log.WithValues("gvks", groupVersionKinds) - return builder.Watches( + return blder.Watches( object, handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request { labels := o.GetLabels() diff --git a/controllers/volsync/vshandler.go b/controllers/volsync/vshandler.go index 18069022ff..bbea570687 100644 --- a/controllers/volsync/vshandler.go +++ b/controllers/volsync/vshandler.go @@ -73,12 +73,12 @@ type VSHandler struct { volumeSnapshotClassList *snapv1.VolumeSnapshotClassList } -func NewVSHandler(ctx context.Context, client client.Client, log logr.Logger, owner metav1.Object, +func NewVSHandler(ctx context.Context, cli client.Client, log logr.Logger, owner metav1.Object, asyncSpec *ramendrv1alpha1.VRGAsyncSpec, defaultCephFSCSIDriverName string, copyMethod string, ) *VSHandler { vsHandler := &VSHandler{ ctx: ctx, - client: client, + client: cli, log: log, owner: owner, defaultCephFSCSIDriverName: defaultCephFSCSIDriverName, diff --git a/controllers/volumereplicationgroup_controller.go b/controllers/volumereplicationgroup_controller.go index 6c1818f9b7..689fc4d7b7 100644 --- a/controllers/volumereplicationgroup_controller.go +++ b/controllers/volumereplicationgroup_controller.go @@ -69,7 +69,7 @@ func (r *VolumeReplicationGroupReconciler) SetupWithManager( &workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)}, ) objectToReconcileRequestsMapper := objectToReconcileRequestsMapper{reader: r.Client, log: ctrl.Log} - builder := ctrl.NewControllerManagedBy(mgr). + blder := ctrl.NewControllerManagedBy(mgr). WithOptions(ctrlcontroller.Options{ MaxConcurrentReconciles: getMaxConcurrentReconciles(r.Log), RateLimiter: rateLimiter, @@ -91,7 +91,7 @@ func (r *VolumeReplicationGroupReconciler) SetupWithManager( Owns(&volrep.VolumeReplication{}) if !ramenConfig.VolSync.Disabled { - builder.Owns(&volsyncv1alpha1.ReplicationDestination{}). + blder.Owns(&volsyncv1alpha1.ReplicationDestination{}). Owns(&volsyncv1alpha1.ReplicationSource{}) } else { r.Log.Info("VolSync disabled; don't own volsync resources") @@ -100,13 +100,13 @@ func (r *VolumeReplicationGroupReconciler) SetupWithManager( r.kubeObjects = velero.RequestsManager{} if !ramenConfig.KubeObjectProtection.Disabled { r.Log.Info("Kube object protection enabled; watch kube objects requests") - recipesWatch(builder, objectToReconcileRequestsMapper) - kubeObjectsRequestsWatch(builder, r.Scheme, r.kubeObjects) + recipesWatch(blder, objectToReconcileRequestsMapper) + kubeObjectsRequestsWatch(blder, r.Scheme, r.kubeObjects) } else { r.Log.Info("Kube object protection disabled; don't watch kube objects requests") } - return builder.Complete(r) + return blder.Complete(r) } type objectToReconcileRequestsMapper struct { diff --git a/controllers/vrg_pvc_selector.go b/controllers/vrg_pvc_selector.go index f56994dd0e..8aa8ef4dd7 100644 --- a/controllers/vrg_pvc_selector.go +++ b/controllers/vrg_pvc_selector.go @@ -22,19 +22,19 @@ func pvcSelectorDefault(vrg ramen.VolumeReplicationGroup) PvcSelector { return PvcSelector{vrg.Spec.PVCSelector, pvcNamespaceNamesDefault(vrg)} } -func pvcSelectorRecipeRefNonNil(recipe recipe.Recipe, vrg ramen.VolumeReplicationGroup) PvcSelector { - if recipe.Spec.Volumes == nil { +func pvcSelectorRecipeRefNonNil(rcp recipe.Recipe, vrg ramen.VolumeReplicationGroup) PvcSelector { + if rcp.Spec.Volumes == nil { return pvcSelectorDefault(vrg) } var selector PvcSelector - if recipe.Spec.Volumes.LabelSelector != nil { - selector.LabelSelector = *recipe.Spec.Volumes.LabelSelector + if rcp.Spec.Volumes.LabelSelector != nil { + selector.LabelSelector = *rcp.Spec.Volumes.LabelSelector } - if len(recipe.Spec.Volumes.IncludedNamespaces) > 0 { - selector.NamespaceNames = recipe.Spec.Volumes.IncludedNamespaces + if len(rcp.Spec.Volumes.IncludedNamespaces) > 0 { + selector.NamespaceNames = rcp.Spec.Volumes.IncludedNamespaces } else { selector.NamespaceNames = pvcNamespaceNamesDefault(vrg) } diff --git a/controllers/vrg_recipe.go b/controllers/vrg_recipe.go index 3fc0360a2c..43ae8314b7 100644 --- a/controllers/vrg_recipe.go +++ b/controllers/vrg_recipe.go @@ -91,30 +91,30 @@ func recipeVolumesAndOptionallyWorkflowsGet(ctx context.Context, reader client.R Name: vrg.Spec.KubeObjectProtection.RecipeRef.Name, } - recipe := recipe.Recipe{} - if err := reader.Get(ctx, recipeNamespacedName, &recipe); err != nil { + rcp := recipe.Recipe{} + if err := reader.Get(ctx, recipeNamespacedName, &rcp); err != nil { return fmt.Errorf("recipe %v get error: %w", recipeNamespacedName.String(), err) } - if err := RecipeParametersExpand(&recipe, vrg.Spec.KubeObjectProtection.RecipeParameters, log); err != nil { + if err := RecipeParametersExpand(&rcp, vrg.Spec.KubeObjectProtection.RecipeParameters, log); err != nil { return err } *recipeElements = RecipeElements{ - PvcSelector: pvcSelectorRecipeRefNonNil(recipe, vrg), + PvcSelector: pvcSelectorRecipeRefNonNil(rcp, vrg), } - if err := workflowsGet(recipe, recipeElements, vrg); err != nil { + if err := workflowsGet(rcp, recipeElements, vrg); err != nil { return err } return recipeNamespacesValidate(*recipeElements, vrg, ramenConfig) } -func RecipeParametersExpand(recipe *recipe.Recipe, parameters map[string][]string, +func RecipeParametersExpand(rcp *recipe.Recipe, parameters map[string][]string, log logr.Logger, ) error { - spec := &recipe.Spec + spec := &rcp.Spec log.V(1).Info("Recipe pre-expansion", "spec", *spec, "parameters", parameters) bytes, err := json.Marshal(*spec) @@ -142,22 +142,22 @@ func parametersExpand(s string, parameters map[string][]string) string { }) } -func recipeWorkflowsGet(recipe recipe.Recipe, recipeElements *RecipeElements, vrg ramen.VolumeReplicationGroup) error { +func recipeWorkflowsGet(rcp recipe.Recipe, recipeElements *RecipeElements, vrg ramen.VolumeReplicationGroup) error { var err error - if recipe.Spec.CaptureWorkflow == nil { + if rcp.Spec.CaptureWorkflow == nil { recipeElements.CaptureWorkflow = captureWorkflowDefault(vrg) } else { - recipeElements.CaptureWorkflow, err = getCaptureGroups(recipe) + recipeElements.CaptureWorkflow, err = getCaptureGroups(rcp) if err != nil { return fmt.Errorf("failed to get groups from capture workflow: %w", err) } } - if recipe.Spec.RecoverWorkflow == nil { + if rcp.Spec.RecoverWorkflow == nil { recipeElements.RecoverWorkflow = recoverWorkflowDefault() } else { - recipeElements.RecoverWorkflow, err = getRecoverGroups(recipe) + recipeElements.RecoverWorkflow, err = getRecoverGroups(rcp) if err != nil { return fmt.Errorf("failed to get groups from recovery workflow: %w", err) } @@ -220,19 +220,20 @@ func recipesWatch(b *builder.Builder, m objectToReconcileRequestsMapper) *builde } func (m objectToReconcileRequestsMapper) recipeToVrgReconcileRequestsMapper( +<<<<<<< HEAD _ context.Context, - recipe client.Object, + rcp client.Object, ) []reconcile.Request { recipeNamespacedName := types.NamespacedName{ - Namespace: recipe.GetNamespace(), - Name: recipe.GetName(), + Namespace: rcp.GetNamespace(), + Name: rcp.GetName(), } log := m.log.WithName("recipe").WithName("VolumeReplicationGroup").WithValues( "name", recipeNamespacedName.String(), - "creation", recipe.GetCreationTimestamp(), - "uid", recipe.GetUID(), - "generation", recipe.GetGeneration(), - "version", recipe.GetResourceVersion(), + "creation", rcp.GetCreationTimestamp(), + "uid", rcp.GetUID(), + "generation", rcp.GetGeneration(), + "version", rcp.GetResourceVersion(), ) vrgList := ramen.VolumeReplicationGroupList{} @@ -247,8 +248,8 @@ func (m objectToReconcileRequestsMapper) recipeToVrgReconcileRequestsMapper( for _, vrg := range vrgList.Items { if vrg.Spec.KubeObjectProtection == nil || vrg.Spec.KubeObjectProtection.RecipeRef == nil || - vrg.Spec.KubeObjectProtection.RecipeRef.Namespace != recipe.GetNamespace() || - vrg.Spec.KubeObjectProtection.RecipeRef.Name != recipe.GetName() { + vrg.Spec.KubeObjectProtection.RecipeRef.Namespace != rcp.GetNamespace() || + vrg.Spec.KubeObjectProtection.RecipeRef.Name != rcp.GetName() { continue } diff --git a/controllers/vrg_volrep_test.go b/controllers/vrg_volrep_test.go index 9c1b522db5..7ccfb9b499 100644 --- a/controllers/vrg_volrep_test.go +++ b/controllers/vrg_volrep_test.go @@ -1481,7 +1481,7 @@ func (v *vrgTest) verifyPVCBindingToPV(shouldBeBound bool) { Eventually(func() bool { pvc := getPVC(v.pvcNames[i]) - if shouldBeBound == true { + if shouldBeBound { return pvc.Status.Phase == corev1.ClaimBound } @@ -1543,7 +1543,7 @@ func (v *vrgTest) verifyVRGStatusExpectation(expectedStatus bool) { return false } - if expectedStatus == true { + if expectedStatus { // reasons for success can be different for Primary and // secondary. Validate that as well. switch vrg.Spec.ReplicationState {