Skip to content

Commit e1db875

Browse files
Fix failing tests
Signed-off-by: faizanahmad055 <faizan.ahmad55@outlook.com>
1 parent eb38bf7 commit e1db875

6 files changed

Lines changed: 27 additions & 12 deletions

File tree

internal/pkg/crypto/sha.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import (
66
)
77

88
// GenerateSHA generates SHA from string
9+
// Always returns a hash value, even for empty strings, to ensure consistent behavior
10+
// and avoid issues with string matching operations (e.g., strings.Contains(str, "") always returns true)
911
func GenerateSHA(data string) string {
10-
if data == "" {
11-
return ""
12-
}
13-
1412
hash := sha512.Sum512_256([]byte(data))
1513
return hex.EncodeToString(hash[:])
1614
}

internal/pkg/crypto/sha_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ func TestGenerateSHA(t *testing.T) {
1313
t.Errorf("Failed to generate SHA")
1414
}
1515
}
16+
17+
// TestGenerateSHAEmptyString verifies that empty string generates a valid hash
18+
// This ensures consistent behavior and avoids issues with string matching operations
19+
func TestGenerateSHAEmptyString(t *testing.T) {
20+
result := GenerateSHA("")
21+
expected := "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a"
22+
if result != expected {
23+
t.Errorf("Failed to generate SHA for empty string. Expected: %s, Got: %s", expected, result)
24+
}
25+
if len(result) != 64 {
26+
t.Errorf("SHA hash should be 64 characters long, got %d", len(result))
27+
}
28+
}

internal/pkg/handler/upgrade.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ func updatePodAnnotations(upgradeFuncs callbacks.RollingUpgradeFuncs, item runti
539539
}
540540

541541
func secretProviderClassAnnotationReloaded(oldAnnotations map[string]string, newConfig common.Config) bool {
542-
annotaion := oldAnnotations[getReloaderAnnotationKey()]
543-
return strings.Contains(annotaion, newConfig.ResourceName) && strings.Contains(annotaion, newConfig.SHAValue)
542+
annotation := oldAnnotations[getReloaderAnnotationKey()]
543+
return strings.Contains(annotation, newConfig.ResourceName) && strings.Contains(annotation, newConfig.SHAValue)
544544
}
545545

546546
func getReloaderAnnotationKey() string {
@@ -645,7 +645,7 @@ func secretProviderClassEnvReloaded(containers []v1.Container, envVar string, sh
645645
}
646646

647647
func populateAnnotationsFromSecretProviderClass(clients kube.Clients, config *common.Config) {
648-
obj, err := clients.CSIClient.SecretsstoreV1().SecretProviderClasses(config.Namespace).Get(context.TODO(), config.ResourceName, metav1.GetOptions{})
648+
obj, err := clients.CSIClient.SecretsstoreV1().SecretProviderClasses(config.Namespace).Get(context.Background(), config.ResourceName, metav1.GetOptions{})
649649
annotations := make(map[string]string)
650650
if err != nil {
651651
if apierrors.IsNotFound(err) {

internal/pkg/handler/upgrade_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,7 +3327,7 @@ func TestRollingUpgradeForStatefulSetWithSecretProviderClassUsingArs(t *testing.
33273327
err := PerformAction(clients, config, statefulSetFuncs, collectors, nil, invokeReloadStrategy)
33283328
time.Sleep(5 * time.Second)
33293329
if err != nil {
3330-
t.Errorf("Rolling upgrade failed for StatefulSet with SecretProviderClass")
3330+
t.Errorf("Rolling upgrade failed for StatefulSet with SecretProviderClass: %v", err)
33313331
}
33323332

33333333
logrus.Infof("Verifying statefulSet update")
@@ -3337,11 +3337,11 @@ func TestRollingUpgradeForStatefulSetWithSecretProviderClassUsingArs(t *testing.
33373337
}
33383338

33393339
if promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)) != 1 {
3340-
t.Errorf("Counter was not increased")
3340+
t.Errorf("Counter was not increased, expected 1 but got %f", promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)))
33413341
}
33423342

33433343
if promtestutil.ToFloat64(collectors.ReloadedByNamespace.With(prometheus.Labels{"success": "true", "namespace": arsNamespace})) != 1 {
3344-
t.Errorf("Counter by namespace was not increased")
3344+
t.Errorf("Counter by namespace was not increased, expected 1 but got %f", promtestutil.ToFloat64(collectors.ReloadedByNamespace.With(prometheus.Labels{"success": "true", "namespace": arsNamespace})))
33453345
}
33463346

33473347
testRollingUpgradeInvokeDeleteStrategyArs(t, clients, config, statefulSetFuncs, collectors, envVarPostfix)

internal/pkg/testutil/kube.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,11 @@ func VerifyResourceAnnotationUpdate(clients kube.Clients, config common.Config,
13271327
}
13281328

13291329
func GetSHAfromEmptyData() string {
1330-
return crypto.GenerateSHA("")
1330+
// Use a special marker that represents "deleted" or "empty" state
1331+
// This ensures we have a distinct, deterministic hash for the delete strategy
1332+
// Note: We could use GenerateSHA("") which now returns a hash, but using a marker
1333+
// makes the intent clearer and avoids potential confusion with actual empty data
1334+
return crypto.GenerateSHA("__RELOADER_EMPTY_DELETE_MARKER__")
13311335
}
13321336

13331337
// GetRollout provides rollout for testing

internal/pkg/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func ConfigureReloaderFlags(cmd *cobra.Command) {
106106
cmd.PersistentFlags().BoolVar(&options.SyncAfterRestart, "sync-after-restart", false, "Sync add events after reloader restarts")
107107
cmd.PersistentFlags().BoolVar(&options.EnablePProf, "enable-pprof", false, "Enable pprof for profiling")
108108
cmd.PersistentFlags().StringVar(&options.PProfAddr, "pprof-addr", ":6060", "Address to start pprof server on. Default is :6060")
109-
cmd.PersistentFlags().BoolVar(&options.EnableCSIIntegration, "enable-csi-integration", false, "Enables CSI integration. Default is :true")
109+
cmd.PersistentFlags().BoolVar(&options.EnableCSIIntegration, "enable-csi-integration", false, "Enables CSI integration. Default is :false")
110110
}
111111

112112
func GetIgnoredResourcesList() (List, error) {

0 commit comments

Comments
 (0)