Skip to content

Commit

Permalink
Enable bool-literal-in-expr revive flag
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Gershkovich <elenage@il.ibm.com>
  • Loading branch information
ELENAGER committed Jan 25, 2024
1 parent 0e6b5b3 commit 186d645
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion controllers/drcluster_mmode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var _ = Describe("DRClusterMModeTests", Ordered, func() {
},
}

if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster == true {
if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster {
namespaceDeletionSupported = true
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/drpc_predicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ var _ = Describe("DRPCPredicateDRCluster", func() {
},
}

if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster == true {
if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster {
namespaceDeletionSupported = true
}

Expand Down
18 changes: 9 additions & 9 deletions controllers/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -2064,7 +2064,7 @@ func getApplicationDestinationNamespace(
}

func selectVRGNamespace(
client client.Client,
cli client.Client,
log logr.Logger,
drpc *rmn.DRPlacementControl,
placementObj client.Object,
Expand All @@ -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
}
Expand Down Expand Up @@ -2119,22 +2119,22 @@ 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{
Type: rmn.ConditionPeerReady,
Reason: string(rmn.Initiating),
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
LastTransitionTime: time,
LastTransitionTime: timestamp,
Message: message,
})
}
Expand Down
10 changes: 5 additions & 5 deletions controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,38 +79,38 @@ 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{
Type: VRGConditionTypeDataProtected,
Reason: VRGConditionReasonInitializing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionUnknown,
LastTransitionTime: time,
LastTransitionTime: timestamp,
Message: message,
})
setStatusConditionIfNotFound(conditions, metav1.Condition{
Type: VRGConditionTypeClusterDataReady,
Reason: VRGConditionReasonInitializing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionUnknown,
LastTransitionTime: time,
LastTransitionTime: timestamp,
Message: message,
})
setStatusConditionIfNotFound(conditions, metav1.Condition{
Type: VRGConditionTypeClusterDataProtected,
Reason: VRGConditionReasonInitializing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionUnknown,
LastTransitionTime: time,
LastTransitionTime: timestamp,
Message: message,
})
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var _ = BeforeSuite(func() {
},
}

if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster == true {
if testEnv.UseExistingCluster != nil && *testEnv.UseExistingCluster {
namespaceDeletionSupported = true
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/util/drpolicy_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/util/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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())
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions controllers/util/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (
)

func OwnsAcrossNamespaces(
builder *builder.Builder,
blder *builder.Builder,
scheme *runtime.Scheme,
object client.Object,
opts ...builder.WatchesOption,
) *builder.Builder {
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()
Expand Down
4 changes: 2 additions & 2 deletions controllers/volsync/vshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions controllers/volumereplicationgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions controllers/vrg_pvc_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit 186d645

Please sign in to comment.