Skip to content

Commit

Permalink
Enable staticcheck linter
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Gershkovich <[email protected]>
  • Loading branch information
ELENAGER committed Jan 22, 2024
1 parent 26cc165 commit ebc2060
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ linters:
# - goimports
# - wrapcheck
# - varnamelen
# - staticcheck
- staticcheck
# - nosnakecase
# - ireturn
# - nilnil
Expand Down
2 changes: 1 addition & 1 deletion controllers/drclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func drClusterUndeploy(
mcv util.ManagedClusterViewGetter,
log logr.Logger,
) error {
clusterNames := sets.String{}
clusterNames := sets.New[string]()
drpolicies := rmn.DRPolicyList{}

if err := mwu.Client.List(mwu.Ctx, &drpolicies); err != nil {
Expand Down
20 changes: 10 additions & 10 deletions controllers/drplacementcontrol_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func resetClusterDown() {
}

//nolint:funlen,cyclop,gocognit
func (FakeMCVGetter) GetVRGFromManagedCluster(_, _, managedCluster string,
func (FakeMCVGetter) GetVRGFromManagedCluster(_, resourceNamespace, managedCluster string,
_ map[string]string,
) (*rmn.VolumeReplicationGroup, error) {
conType := controllers.VRGConditionTypeDataReady
Expand Down Expand Up @@ -1161,7 +1161,7 @@ const (
UsePlacementWithAppSet = 3
)

func InitialDeploymentAsync(namespace, placementName string, plType PlacementType) (
func InitialDeploymentAsync(namespace, placementName, homeCluster string, plType PlacementType) (
client.Object, *rmn.DRPlacementControl,
) {
createNamespacesAsync(getNamespaceObj(namespace))
Expand Down Expand Up @@ -1194,7 +1194,7 @@ func CreatePlacementAndDRPC(namespace, placementName, homeCluster string, plType
return placementObj, createDRPC(placementName, DRPCCommonName, namespace, AsyncDRPolicyName, homeCluster)
}

func FollowOnDeploymentAsync(namespace, placementName string) (*plrv1.PlacementRule,
func FollowOnDeploymentAsync(namespace, placementName, homeCluster string) (*plrv1.PlacementRule,
*rmn.DRPlacementControl,
) {
createNamespace(appNamespace2)
Expand Down Expand Up @@ -1632,7 +1632,7 @@ func createNamespacesSync() {
createNamespace(appNamespace)
}

func InitialDeploymentSync(namespace, placementName string) (*plrv1.PlacementRule,
func InitialDeploymentSync(namespace, placementName, homeCluster string) (*plrv1.PlacementRule,
*rmn.DRPlacementControl,
) {
createNamespacesSync()
Expand Down Expand Up @@ -1863,7 +1863,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
By("Initial Deployment")
var placementObj client.Object
placementObj, drpc = InitialDeploymentAsync(
DefaultDRPCNamespace, UserPlacementRuleName, UsePlacementRule)
DefaultDRPCNamespace, UserPlacementRuleName, East1ManagedCluster, UsePlacementRule)
userPlacementRule = placementObj.(*plrv1.PlacementRule)
Expect(userPlacementRule).NotTo(BeNil())
verifyInitialDRPCDeployment(userPlacementRule, East1ManagedCluster)
Expand Down Expand Up @@ -1930,7 +1930,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
})
When("A DRPC is created referring to a deleted DRPolicy", func() {
It("Should fail DRPC reconciliaiton and not add a finalizer", func() {
_, drpc2 := FollowOnDeploymentAsync(DRPC2NamespaceName, UserPlacementRuleName)
_, drpc2 := FollowOnDeploymentAsync(DRPC2NamespaceName, UserPlacementRuleName, East1ManagedCluster)
checkIfDRPCFinalizerNotAdded(drpc2)
Expect(k8sClient.Delete(context.TODO(), drpc2)).Should(Succeed())
})
Expand Down Expand Up @@ -1975,7 +1975,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
By("Initial Deployment")
var placementObj client.Object
placementObj, drpc = InitialDeploymentAsync(
DefaultDRPCNamespace, UserPlacementName, UsePlacementWithSubscription)
DefaultDRPCNamespace, UserPlacementName, East1ManagedCluster, UsePlacementWithSubscription)
placement = placementObj.(*clrapiv1beta1.Placement)
Expect(placement).NotTo(BeNil())
verifyInitialDRPCDeployment(placement, East1ManagedCluster)
Expand Down Expand Up @@ -2051,7 +2051,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
getBaseVRG(DefaultDRPCNamespace).ObjectMeta.Namespace = ApplicationNamespace
var placementObj client.Object
placementObj, drpc = InitialDeploymentAsync(
DefaultDRPCNamespace, UserPlacementName, UsePlacementWithAppSet)
DefaultDRPCNamespace, UserPlacementName, East1ManagedCluster, UsePlacementWithAppSet)
placement = placementObj.(*clrapiv1beta1.Placement)
Expect(placement).NotTo(BeNil())
verifyInitialDRPCDeployment(placement, East1ManagedCluster)
Expand Down Expand Up @@ -2135,7 +2135,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
When("An Application is deployed for the first time", func() {
It("Should deploy to East1ManagedCluster", func() {
By("Initial Deployment")
userPlacementRule, _ = InitialDeploymentSync(DefaultDRPCNamespace, UserPlacementRuleName)
userPlacementRule, _ = InitialDeploymentSync(DefaultDRPCNamespace, UserPlacementRuleName, East1ManagedCluster)
verifyInitialDRPCDeployment(userPlacementRule, East1ManagedCluster)
verifyDRPCOwnedByPlacement(userPlacementRule, getLatestDRPC(DefaultDRPCNamespace))
})
Expand Down Expand Up @@ -2211,7 +2211,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
When("An Application is deployed for the first time", func() {
It("Should deploy to East1ManagedCluster", func() {
By("Initial Deployment")
userPlacementRule, _ = InitialDeploymentSync(DefaultDRPCNamespace, UserPlacementRuleName)
userPlacementRule, _ = InitialDeploymentSync(DefaultDRPCNamespace, UserPlacementRuleName, East1ManagedCluster)
verifyInitialDRPCDeployment(userPlacementRule, East1ManagedCluster)
verifyDRPCOwnedByPlacement(userPlacementRule, getLatestDRPC(DefaultDRPCNamespace))
})
Expand Down
18 changes: 9 additions & 9 deletions controllers/drpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func drClusterSecretsDeploy(
log.Info("Received partial list", "err", err)
}

for _, secretName := range drPolicySecrets.List() {
for secretName := range drPolicySecrets {
if err := secretsUtil.AddSecretToCluster(
secretName,
clusterName,
Expand Down Expand Up @@ -102,7 +102,7 @@ func drClustersUndeploySecrets(
return nil
}

mustHaveS3Secrets := map[string]sets.String{}
mustHaveS3Secrets := map[string]sets.Set[string]{}

// Determine S3 secrets that must continue to exist per cluster in the policy being deleted
for _, clusterName := range util.DrpolicyClusterNames(drpolicy) {
Expand All @@ -119,7 +119,7 @@ func drClustersUndeploySecrets(
// For each cluster in the must have S3 secrets list, check and delete
// S3Profiles that maybe deleted, iff absent in the must have list
for clusterName, mustHaveS3Secrets := range mustHaveS3Secrets {
for _, s3SecretToDelete := range mayDeleteS3Secrets.List() {
for s3SecretToDelete := range mayDeleteS3Secrets {
if mustHaveS3Secrets.Has(s3SecretToDelete) {
continue
}
Expand All @@ -144,8 +144,8 @@ func drClusterListMustHaveSecrets(
clusterName string,
ignorePolicy *rmn.DRPolicy,
ramenConfig *rmn.RamenConfig,
) sets.String {
mustHaveS3Secrets := sets.String{}
) sets.Set[string] {
mustHaveS3Secrets := sets.New[string]()

mustHaveS3Profiles := drClusterListMustHaveS3Profiles(drpolicies, drclusters, clusterName, ignorePolicy)

Expand All @@ -164,8 +164,8 @@ func drClusterListMustHaveS3Profiles(drpolicies rmn.DRPolicyList,
drclusters *rmn.DRClusterList,
clusterName string,
ignorePolicy *rmn.DRPolicy,
) sets.String {
mustHaveS3Profiles := sets.String{}
) sets.Set[string] {
mustHaveS3Profiles := sets.New[string]()

for idx := range drpolicies.Items {
// Skip the policy being ignored (used for delete)
Expand All @@ -192,8 +192,8 @@ func drClusterListMustHaveS3Profiles(drpolicies rmn.DRPolicyList,
func drPolicySecretNames(drpolicy *rmn.DRPolicy,
drclusters *rmn.DRClusterList,
rmnCfg *rmn.RamenConfig,
) (sets.String, error) {
secretNames := sets.String{}
) (sets.Set[string], error) {
secretNames := sets.New[string]()

var err error

Expand Down
3 changes: 1 addition & 2 deletions controllers/ramenconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package controllers
import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"

Expand Down Expand Up @@ -90,7 +89,7 @@ func ReadRamenConfigFile(log logr.Logger) (ramenConfig ramendrv1alpha1.RamenConf

log.Info("loading Ramen config file ", "name", cachedRamenConfigFileName)

fileContents, err := ioutil.ReadFile(cachedRamenConfigFileName)
fileContents, err := os.ReadFile(cachedRamenConfigFileName)
if err != nil {
err = fmt.Errorf("unable to load the config file %s: %w",
cachedRamenConfigFileName, err)
Expand Down
8 changes: 4 additions & 4 deletions controllers/util/drpolicy_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func DrpolicyRegionNames(drpolicy *rmn.DRPolicy, drClusters []rmn.DRCluster) []s
return regionNames
}

func DrpolicyRegionNamesAsASet(drpolicy *rmn.DRPolicy, drClusters []rmn.DRCluster) sets.String {
return sets.NewString(DrpolicyRegionNames(drpolicy, drClusters)...)
func DrpolicyRegionNamesAsASet(drpolicy *rmn.DRPolicy, drClusters []rmn.DRCluster) sets.Set[string] {
return sets.New(DrpolicyRegionNames(drpolicy, drClusters)...)
}

func DrpolicyValidated(drpolicy *rmn.DRPolicy) error {
Expand All @@ -68,8 +68,8 @@ func GetAllDRPolicies(ctx context.Context, cli client.Reader) (rmn.DRPolicyList,
return drpolicies, nil
}

func DRPolicyS3Profiles(drpolicy *rmn.DRPolicy, drclusters []rmn.DRCluster) sets.String {
mustHaveS3Profiles := sets.String{}
func DRPolicyS3Profiles(drpolicy *rmn.DRPolicy, drclusters []rmn.DRCluster) sets.Set[string] {
mustHaveS3Profiles := sets.New[string]()

for _, managedCluster := range DrpolicyClusterNames(drpolicy) {
s3ProfileName := ""
Expand Down
1 change: 0 additions & 1 deletion controllers/vrg_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ func recipesWatch(b *builder.Builder, m objectToReconcileRequestsMapper) *builde
}

func (m objectToReconcileRequestsMapper) recipeToVrgReconcileRequestsMapper(
<<<<<<< HEAD
_ context.Context,
rcp client.Object,
) []reconcile.Request {
Expand Down
2 changes: 1 addition & 1 deletion controllers/vrg_recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ var _ = Describe("VolumeReplicationGroupRecipe", func() {
recipeHooksDefine(hook(ns0ParameterRef))
})
JustBeforeEach(func() {
recipeExpanded = &*r
recipeExpanded = r
Expect(controllers.RecipeParametersExpand(recipeExpanded, vrgRecipeParameters(), testLogger)).To(Succeed())
})
It("expands a parameter list enclosed in double quotes to a single string with quotes preserved", func() {
Expand Down
2 changes: 1 addition & 1 deletion controllers/vrg_volrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ func restoreClusterDataObjects[

for i := range objList {
object := &objList[i]
objectCopy := &*object
objectCopy := object
obj := ClientObject(objectCopy)

cleanupForRestore(objectCopy)
Expand Down

0 comments on commit ebc2060

Please sign in to comment.