Skip to content

Commit 2e6a3a8

Browse files
committed
Removes test helper constant NoS3StoreAvailable
removes test helper constant NoS3StoreAvailable Removes the NoS3StoreAvailable constant ("NoS3") that was marked with FIXME as a test helper. Replace all usages with empty string checks and refactor S3Profiles slice handling to filter empty strings upfront before processing. Changes: - Remove NoS3StoreAvailable constant from ramenconfig.go - Replace constant comparisons with empty string checks for single S3ProfileName fields - Refactor S3Profiles slice handling to filter empty strings upfront instead of checking during iteration - Remove skipIfS3ProfileIsForTest() function as it's no longer needed - Update test files to use empty strings instead of the constant This improves code quality by: - Removing test-specific constants from production code - Using more efficient upfront filtering for slices - Maintaining consistent behavior while simplifying the codebase Resolves #1710 Signed-off-by: raaizik <[email protected]>
1 parent 9b34d7b commit 2e6a3a8

File tree

9 files changed

+62
-62
lines changed

9 files changed

+62
-62
lines changed

internal/controller/drcluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func filterDRClusterSecret(ctx context.Context, reader client.Reader, secret *co
319319

320320
s3ProfileName := drcluster.Spec.S3ProfileName
321321

322-
if s3ProfileName == NoS3StoreAvailable {
322+
if s3ProfileName == "" {
323323
continue
324324
}
325325

@@ -499,7 +499,7 @@ func validateS3Profile(ctx context.Context, apiReader client.Reader,
499499
objectStoreGetter ObjectStoreGetter,
500500
drcluster *ramen.DRCluster, listKeyPrefix string, log logr.Logger,
501501
) (string, error) {
502-
if drcluster.Spec.S3ProfileName != NoS3StoreAvailable {
502+
if drcluster.Spec.S3ProfileName != "" {
503503
if reason, err := s3ProfileValidate(ctx, apiReader, objectStoreGetter,
504504
drcluster.Spec.S3ProfileName, listKeyPrefix, log); err != nil {
505505
return reason, err

internal/controller/drcluster_drcconfig_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ var _ = Describe("DRCluster-DRClusterConfigTests", Ordered, func() {
149149
// Initialize --- DRCluster
150150
drCluster1 = &ramen.DRCluster{
151151
ObjectMeta: metav1.ObjectMeta{Name: drCluster1Name},
152-
Spec: ramen.DRClusterSpec{S3ProfileName: "NoS3", Region: "east"},
152+
Spec: ramen.DRClusterSpec{S3ProfileName: "", Region: "east"},
153153
}
154154

155155
Expect(k8sClient.Create(context.TODO(), drCluster1)).To(Succeed())

internal/controller/ramenconfig.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ const (
4343
DefaultVolSyncCopyMethod = "Snapshot"
4444
)
4545

46-
// FIXME
47-
const NoS3StoreAvailable = "NoS3"
48-
4946
var ControllerType ramendrv1alpha1.ControllerType
5047

5148
var cachedRamenConfigFileName string

internal/controller/s3_store_accessors.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,23 @@ func s3StoreAccessorsGet(
2121
objectStorerGet func(string) (ObjectStorer, ramen.S3StoreProfile, error),
2222
log logr.Logger,
2323
) []s3StoreAccessor {
24-
s3StoreAccessors := make([]s3StoreAccessor, 0, len(s3ProfileNames))
24+
// Filter out empty profile names (no S3 store configured)
25+
s3Profiles := make([]string, 0, len(s3ProfileNames))
26+
for _, profile := range s3ProfileNames {
27+
if profile != "" {
28+
s3Profiles = append(s3Profiles, profile)
29+
}
30+
}
2531

26-
for _, s3ProfileName := range s3ProfileNames {
27-
if s3ProfileName == NoS3StoreAvailable {
28-
log.Info("Kube object protection store dummy")
32+
if len(s3Profiles) == 0 {
33+
log.Info("Kube object protection store dummy")
2934

30-
continue
31-
}
35+
return []s3StoreAccessor{}
36+
}
37+
38+
s3StoreAccessors := make([]s3StoreAccessor, 0, len(s3Profiles))
39+
40+
for _, s3ProfileName := range s3Profiles {
3241

3342
objectStorer, s3StoreProfile, err := objectStorerGet(s3ProfileName)
3443
if err != nil {

internal/controller/vrg_kubeobjects.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -557,18 +557,6 @@ func (v *VRGInstance) getVRGFromS3Profile(s3ProfileName string) (*ramen.VolumeRe
557557
return vrg, nil
558558
}
559559

560-
func (v *VRGInstance) skipIfS3ProfileIsForTest() bool {
561-
for _, s3ProfileName := range v.instance.Spec.S3Profiles {
562-
if s3ProfileName == NoS3StoreAvailable {
563-
v.log.Info("NoS3 available to fetch")
564-
565-
return true
566-
}
567-
}
568-
569-
return false
570-
}
571-
572560
func (v *VRGInstance) kubeObjectsRecoverFromS3(result *ctrl.Result, accessor s3StoreAccessor) error {
573561
s3ProfileName := accessor.S3ProfileName
574562

@@ -600,14 +588,8 @@ func (v *VRGInstance) kubeObjectsRecover(result *ctrl.Result) error {
600588
}
601589

602590
if len(v.s3StoreAccessors) == 0 {
603-
v.log.Info("No S3 profiles configured")
604-
605-
result.Requeue = true
606-
607-
return fmt.Errorf("no S3Profiles configured")
608-
}
591+
v.log.Info("No S3 profiles configured, skipping kube objects recovery")
609592

610-
if v.skipIfS3ProfileIsForTest() {
611593
return nil
612594
}
613595

internal/controller/vrg_recipe_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ var _ = Describe("VolumeReplicationGroupRecipe", func() {
221221
vrg = &ramen.VolumeReplicationGroup{
222222
ObjectMeta: metav1.ObjectMeta{Namespace: namespaceName, Name: "a"},
223223
Spec: ramen.VolumeReplicationGroupSpec{
224-
S3Profiles: []string{controllers.NoS3StoreAvailable},
224+
S3Profiles: []string{""},
225225
ReplicationState: ramen.Primary,
226226
Sync: &ramen.VRGSyncSpec{
227227
PeerClasses: vrgSyncPeerClasses(),

internal/controller/vrg_volgrouprep.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -910,17 +910,23 @@ func (v *VRGInstance) restoreVGRsAndVGRCsForVolRep(result *ctrl.Result) error {
910910
}
911911

912912
func (v *VRGInstance) restoreVGRsAndVGRCsFromS3(result *ctrl.Result) error {
913-
err := errors.New("s3Profiles empty")
914-
NoS3 := false
913+
// Filter out empty profile names (no S3 store configured)
914+
s3Profiles := make([]string, 0, len(v.instance.Spec.S3Profiles))
915+
for _, profile := range v.instance.Spec.S3Profiles {
916+
if profile != "" {
917+
s3Profiles = append(s3Profiles, profile)
918+
}
919+
}
915920

916-
for _, s3ProfileName := range v.instance.Spec.S3Profiles {
917-
if s3ProfileName == NoS3StoreAvailable {
918-
v.log.Info("NoS3 available to fetch")
921+
if len(s3Profiles) == 0 {
922+
v.log.Info("NoS3 available to fetch")
919923

920-
NoS3 = true
924+
return nil
925+
}
921926

922-
continue
923-
}
927+
err := errors.New("s3Profiles empty")
928+
929+
for _, s3ProfileName := range s3Profiles {
924930

925931
var objectStore ObjectStorer
926932

@@ -953,10 +959,6 @@ func (v *VRGInstance) restoreVGRsAndVGRCsFromS3(result *ctrl.Result) error {
953959
return nil
954960
}
955961

956-
if NoS3 {
957-
return nil
958-
}
959-
960962
result.Requeue = true
961963

962964
return err

internal/controller/vrg_volrep.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,13 +1106,21 @@ func (v *VRGInstance) pvAndPvcObjectReplicasDelete(pvc corev1.PersistentVolumeCl
11061106
}
11071107

11081108
func (v *VRGInstance) s3StoresDo(do func(ObjectStorer) error, msg string) error {
1109-
for _, s3ProfileName := range v.instance.Spec.S3Profiles {
1110-
if s3ProfileName == NoS3StoreAvailable {
1111-
v.log.Info("NoS3 available to clean")
1112-
1113-
continue
1109+
// Filter out empty profile names (no S3 store configured)
1110+
s3Profiles := make([]string, 0, len(v.instance.Spec.S3Profiles))
1111+
for _, profile := range v.instance.Spec.S3Profiles {
1112+
if profile != "" {
1113+
s3Profiles = append(s3Profiles, profile)
11141114
}
1115+
}
1116+
1117+
if len(s3Profiles) == 0 {
1118+
v.log.Info("NoS3 available to clean")
11151119

1120+
return nil
1121+
}
1122+
1123+
for _, s3ProfileName := range s3Profiles {
11161124
if err := v.s3StoreDo(do, msg, s3ProfileName); err != nil {
11171125
return fmt.Errorf("%s using profile %s, err %w", msg, s3ProfileName, err)
11181126
}
@@ -2151,17 +2159,23 @@ func (v *VRGInstance) restorePVsAndPVCsForVolRep(result *ctrl.Result) (int, erro
21512159
}
21522160

21532161
func (v *VRGInstance) restorePVsAndPVCsFromS3(result *ctrl.Result) (int, error) {
2154-
err := errors.New("s3Profiles empty")
2155-
NoS3 := false
2162+
// Filter out empty profile names (no S3 store configured)
2163+
s3Profiles := make([]string, 0, len(v.instance.Spec.S3Profiles))
2164+
for _, profile := range v.instance.Spec.S3Profiles {
2165+
if profile != "" {
2166+
s3Profiles = append(s3Profiles, profile)
2167+
}
2168+
}
21562169

2157-
for _, s3ProfileName := range v.instance.Spec.S3Profiles {
2158-
if s3ProfileName == NoS3StoreAvailable {
2159-
v.log.Info("NoS3 available to fetch")
2170+
if len(s3Profiles) == 0 {
2171+
v.log.Info("NoS3 available to fetch")
21602172

2161-
NoS3 = true
2173+
return 0, nil
2174+
}
21622175

2163-
continue
2164-
}
2176+
err := errors.New("s3Profiles empty")
2177+
2178+
for _, s3ProfileName := range s3Profiles {
21652179

21662180
var objectStore ObjectStorer
21672181

@@ -2201,10 +2215,6 @@ func (v *VRGInstance) restorePVsAndPVCsFromS3(result *ctrl.Result) (int, error)
22012215
return pvCount + pvcCount, nil
22022216
}
22032217

2204-
if NoS3 {
2205-
return 0, nil
2206-
}
2207-
22082218
result.Requeue = true
22092219

22102220
return 0, err

internal/controller/vrg_volrep_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ var _ = Describe("VolumeReplicationGroupVolRepController", func() {
616616
vrgS3UploadTestCase.verifyCachedUploadError()
617617
})
618618
Specify("set VRG's S3 profile names to empty", func() {
619-
vrgS3UploadTestCase.vrgS3ProfilesSet([]string{vrgController.NoS3StoreAvailable})
619+
vrgS3UploadTestCase.vrgS3ProfilesSet([]string{""})
620620
})
621621
It("cleans up after testing", func() {
622622
vrgS3UploadTestCase.cleanupStatusUnprotected()

0 commit comments

Comments
 (0)