Skip to content

Commit 5e6ab2a

Browse files
authored
fix for multiple sc with same fs maps to same trident backend
1 parent dea1ba3 commit 5e6ab2a

File tree

3 files changed

+68
-26
lines changed

3 files changed

+68
-26
lines changed

operator/controllers/configurator/storage_drivers/fsx.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ const (
2828
SvmStateCreated = "CREATED"
2929
AWSRegion = "AWS_REGION"
3030

31-
TridentSecretPattern = "trident-%s"
32-
SvmNamePattern = "trident-%s"
33-
StorageClassNamePattern = "trident-%s-%s"
34-
BackendNamePattern = "trident-%s-%s"
35-
VsAdmin = "vsadmin"
36-
Description = "Trident secret for FsxN for ONTAP"
31+
TridentSecretPattern = "trident-%s"
32+
SvmNamePattern = "trident-%s"
33+
StorageClassNamePattern = "trident-%s-%s"
34+
BackendNamePattern = "trident-%s-%s"
35+
SCManagedBackendNamePattern = "trident-%s-%s-%s"
36+
VsAdmin = "vsadmin"
37+
Description = "Trident secret for FsxN for ONTAP"
3738

3839
// Tags for the secret
3940
FileSystemId = "file-system-id"
@@ -288,7 +289,7 @@ func (aws *AWS) Create() ([]string, error) {
288289
)
289290
for _, svm := range aws.SVMs {
290291
for _, protocol := range svm.Protocols {
291-
backendName = getFSxNBackendName(svm.FsxnID, protocol)
292+
backendName = getFSxNBackendName(aws, svm.FsxnID, protocol)
292293
backendYAML := getFsxnTBCYaml(svm, aws.TridentNamespace, backendName, protocol, aws.TBCNamePrefix, aws.SCManagedTConf, aws.TConfSpec)
293294
if err := aws.ConfClient.CreateOrPatchObject(confClients.OBackend, backendName,
294295
aws.TridentNamespace, backendYAML); err != nil {
@@ -342,7 +343,7 @@ func (aws *AWS) DeleteBackend(request map[string]interface{}) error {
342343
protocols := request["protocols"].([]string)
343344
fsxnId := request["FSxNID"].(string)
344345
for _, protocol := range protocols {
345-
backendName := getFSxNBackendName(fsxnId, protocol)
346+
backendName := getFSxNBackendName(aws, fsxnId, protocol)
346347
if err := aws.ConfClient.DeleteObject(confClients.OBackend, backendName, aws.TridentNamespace); err != nil {
347348
return fmt.Errorf("error occurred while deleting backend: %w", err)
348349
}
@@ -447,7 +448,11 @@ func deleteSecret(ctx context.Context, aws *AWS, secretName string) error {
447448
}
448449

449450
// getFSxNBackendName returns the FsxN Trident backend config name
450-
func getFSxNBackendName(fsxnId, protocolType string) string {
451+
func getFSxNBackendName(aws *AWS, fsxnId, protocolType string) string {
452+
if aws.SCManagedTConf {
453+
scName := strings.TrimPrefix(aws.TBCNamePrefix, "tconf-")
454+
return fmt.Sprintf(SCManagedBackendNamePattern, scName, fsxnId, protocolType)
455+
}
451456
return fmt.Sprintf(BackendNamePattern, fsxnId, protocolType)
452457
}
453458

operator/controllers/configurator/storage_drivers/fsx_test.go

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -526,18 +526,54 @@ func TestAWS_DeleteSnapshotClass_ListError(t *testing.T) {
526526
// Test utility functions
527527
func TestGetFSxNBackendName(t *testing.T) {
528528
tests := []struct {
529-
fsxnId string
530-
protocolType string
531-
expected string
529+
name string
530+
fsxnId string
531+
protocolType string
532+
scManagedTConf bool
533+
tbcNamePrefix string
534+
expected string
532535
}{
533-
{testFsxnID, sa.NFS, testBackendPrefix + testFsxnID + "-nfs"},
534-
{testFsxnID, sa.ISCSI, testBackendPrefix + testFsxnID + "-iscsi"},
535-
{"fs-test", "custom", testBackendPrefix + "fs-test-custom"},
536+
{
537+
name: "NFS non-managed",
538+
fsxnId: testFsxnID,
539+
protocolType: sa.NFS,
540+
scManagedTConf: false,
541+
tbcNamePrefix: "",
542+
expected: testBackendPrefix + testFsxnID + "-nfs",
543+
},
544+
{
545+
name: "ISCSI non-managed",
546+
fsxnId: testFsxnID,
547+
protocolType: sa.ISCSI,
548+
scManagedTConf: false,
549+
tbcNamePrefix: "",
550+
expected: testBackendPrefix + testFsxnID + "-iscsi",
551+
},
552+
{
553+
name: "custom protocol non-managed",
554+
fsxnId: "fs-test",
555+
protocolType: "custom",
556+
scManagedTConf: false,
557+
tbcNamePrefix: "",
558+
expected: testBackendPrefix + "fs-test-custom",
559+
},
560+
{
561+
name: "NFS SC-managed",
562+
fsxnId: testFsxnID,
563+
protocolType: sa.NFS,
564+
scManagedTConf: true,
565+
tbcNamePrefix: "tconf-sc-name",
566+
expected: testBackendPrefix + "sc-name-" + testFsxnID + "-nfs",
567+
},
536568
}
537569

538570
for _, tt := range tests {
539-
t.Run(fmt.Sprintf("%s_%s", tt.fsxnId, tt.protocolType), func(t *testing.T) {
540-
result := getFSxNBackendName(tt.fsxnId, tt.protocolType)
571+
t.Run(tt.name, func(t *testing.T) {
572+
aws := &AWS{
573+
SCManagedTConf: tt.scManagedTConf,
574+
TBCNamePrefix: tt.tbcNamePrefix,
575+
}
576+
result := getFSxNBackendName(aws, tt.fsxnId, tt.protocolType)
541577
assert.Equal(t, tt.expected, result)
542578
})
543579
}
@@ -998,12 +1034,13 @@ func TestAWS_Create_SCManagedTConf(t *testing.T) {
9981034
TConfSpec: tconfSpec,
9991035
}
10001036

1001-
// Mock backend creation
1002-
mockClient.EXPECT().CreateOrPatchObject(gomock.Any(), testBackendPrefix+testFsxnID+"-nfs", testTridentNamespace, gomock.Any()).Return(nil)
1037+
// Mock backend creation - SC-managed uses different naming pattern
1038+
expectedBackendName := testBackendPrefix + testFSxConfiguratorName + "-" + testFsxnID + "-nfs"
1039+
mockClient.EXPECT().CreateOrPatchObject(gomock.Any(), expectedBackendName, testTridentNamespace, gomock.Any()).Return(nil)
10031040

10041041
backends, err := aws.Create()
10051042

10061043
assert.NoError(t, err)
10071044
assert.Len(t, backends, 1)
1008-
assert.Contains(t, backends, testBackendPrefix+testFsxnID+"-nfs")
1045+
assert.Contains(t, backends, expectedBackendName)
10091046
}

operator/controllers/resourcemonitor/fsx.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020
AdditionalFsxNFileSystemIDAnnotation = "trident.netapp.io/additionalFsxNFileSystemID"
2121

2222
// Backend naming pattern for FSxN
23-
BackendNamePattern = "trident-%s-%s" // filesystemID, protocol
23+
SCManagedBackendNamePattern = "trident-%s-%s-%s"
2424
)
2525

2626
// FsxStorageDriverHandler implements StorageDriverHandler for FSxN
@@ -104,7 +104,7 @@ func (h *FsxStorageDriverHandler) BuildAdditionalStoragePoolsValue(sc *storagev1
104104
// Start with the primary filesystem
105105
primaryFsxID := sc.Parameters[FSxFilesystemIDParam]
106106
if primaryFsxID != "" {
107-
backendName := buildBackendName(primaryFsxID, protocol)
107+
backendName := buildBackendName(sc.Name, primaryFsxID, protocol)
108108
// Use ".*" as a regex pattern to match all pools for this backend
109109
backendPools = append(backendPools, fmt.Sprintf("%s:.*", backendName))
110110
}
@@ -123,7 +123,7 @@ func (h *FsxStorageDriverHandler) BuildAdditionalStoragePoolsValue(sc *storagev1
123123
// Add additional FSx filesystems
124124
for _, fsxID := range idList {
125125
if fsxID != "" {
126-
backendName := buildBackendName(fsxID, protocol)
126+
backendName := buildBackendName(sc.Name, fsxID, protocol)
127127
backendPools = append(backendPools, fmt.Sprintf("%s:.*", backendName))
128128
}
129129
}
@@ -276,7 +276,7 @@ func getProtocolFromDriver(driverName string) string {
276276
}
277277
}
278278

279-
// buildBackendName generates a backend name using the pattern trident-{filesystemID}-{protocol}
280-
func buildBackendName(filesystemID, protocol string) string {
281-
return fmt.Sprintf(BackendNamePattern, filesystemID, protocol)
279+
// buildBackendName generates a backend name using the pattern trident-<scName>-<filesystemID>-<protocol>
280+
func buildBackendName(scName, filesystemID, protocol string) string {
281+
return fmt.Sprintf(SCManagedBackendNamePattern, scName, filesystemID, protocol)
282282
}

0 commit comments

Comments
 (0)