Skip to content

Commit

Permalink
Fix to create default backendname while using workload cloud identity
Browse files Browse the repository at this point in the history
  • Loading branch information
alloydsa authored Oct 14, 2024
1 parent 46b4305 commit 97ef980
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion storage_drivers/gcp/gcp_gcnv.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func (d *NASStorageDriver) GetConfig() drivers.DriverConfig {

// defaultBackendName returns the default name of the backend managed by this driver instance.
func (d *NASStorageDriver) defaultBackendName() string {
return fmt.Sprintf("%s_%s", strings.Replace(d.Name(), "-", "", -1), d.Config.APIKey.PrivateKeyID[0:5])
id := utils.RandomString(5)
if len(d.Config.APIKey.PrivateKeyID) > 5 {
id = d.Config.APIKey.PrivateKeyID[0:5]
}
return fmt.Sprintf("%s_%s", strings.Replace(d.Name(), "-", "", -1), id)
}

// BackendName returns the name of the backend managed by this driver instance.
Expand Down
7 changes: 7 additions & 0 deletions storage_drivers/gcp/gcp_gcnv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ func TestBackendName_UseDefault(t *testing.T) {
assert.Equal(t, "googlecloudnetappvolumes_12345", result, "backend name mismatch")
}

func TestDefaultBackendName_WorkloadIdentity(t *testing.T) {
_, driver := newMockGCNVDriver(t)
driver.Config.APIKey = drivers.GCPPrivateKey{}
result := driver.BackendName()
assert.NotNil(t, result, "received nil for the backend name")
}

func TestPoolName(t *testing.T) {
_, driver := newMockGCNVDriver(t)

Expand Down

0 comments on commit 97ef980

Please sign in to comment.