Skip to content

Commit 440149c

Browse files
Merge pull request #323 from umangachapagain/fix-storageid-generation-release-4.19
handle corner cases for StorageID generation
2 parents a09df83 + 9aac337 commit 440149c

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

controllers/utils/hash_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,64 @@ func TestFnvHashTest(t *testing.T) {
2121
}
2222
}
2323
}
24+
25+
func TestCalculateMD5Hash(t *testing.T) {
26+
type args struct {
27+
value any
28+
}
29+
tests := []struct {
30+
name string
31+
args args
32+
want string
33+
}{
34+
{
35+
name: "RBD with empty CephFSID",
36+
args: args{
37+
value: [2]string{"", ""},
38+
},
39+
want: "2432510f5993984b053e7d74ce53d94c",
40+
},
41+
{
42+
name: "CephFS with empty CephFSID",
43+
args: args{
44+
value: [2]string{"", "csi"},
45+
},
46+
want: "793b48b9b17bdad5cd141e6daadfdd4e",
47+
},
48+
{
49+
name: "C1/RBD",
50+
args: args{
51+
value: [2]string{"a0eaa723-bf87-48db-ad11-17e276edda61", ""},
52+
},
53+
want: "bb2361459436fd47121419c658d4c79b",
54+
},
55+
{
56+
name: "C1/CephFS",
57+
args: args{
58+
value: [2]string{"a0eaa723-bf87-48db-ad11-17e276edda61", "csi"},
59+
},
60+
want: "41711cb35464e85f4446ace583adbaa1",
61+
},
62+
{
63+
name: "C2/RBD",
64+
args: args{
65+
value: [2]string{"30dc85db-f35f-4c03-bb43-c8592487d8b9", ""},
66+
},
67+
want: "9e4fbb3d9e52875d6393409a51927243",
68+
},
69+
{
70+
name: "C2/CephFS",
71+
args: args{
72+
value: [2]string{"30dc85db-f35f-4c03-bb43-c8592487d8b9", "csi"},
73+
},
74+
want: "4b7e331b508946ca7165f14804c37ffc",
75+
},
76+
}
77+
for _, tt := range tests {
78+
t.Run(tt.name, func(t *testing.T) {
79+
if got := CalculateMD5Hash(tt.args.value); got != tt.want {
80+
t.Errorf("CalculateMD5Hash() = %v, want %v", got, tt.want)
81+
}
82+
})
83+
}
84+
}

controllers/utils/storageclass.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ func CalculateStorageId(ctx context.Context, c client.Client, sc storagev1.Stora
102102
}
103103

104104
cephClusterFSID := cephCluster.Status.CephStatus.FSID
105-
var storageId string
105+
if cephClusterFSID == "" {
106+
return "", fmt.Errorf("failed to calculate StorageID. Ceph FSID is empty")
107+
}
106108

109+
var storageId string
107110
switch sc.Provisioner {
108111
case fmt.Sprintf(RBDProvisionerTemplate, storageClusterNamespacedName.Namespace):
109112
radosNamespaceName := DefaultRadosNamespace

0 commit comments

Comments
 (0)