Skip to content

Commit 7afcd17

Browse files
committed
fixup! feat(preflight): Add a check for storage containers
Fix ListStorageContainers filter format. Use single quotes. Also fix corresponding unit test.
1 parent 47752d7 commit 7afcd17

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pkg/webhook/preflight/nutanix/storagecontainer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func getStorageContainer(
144144
return nil, fmt.Errorf("failed to get cluster: %w", err)
145145
}
146146

147-
fltr := fmt.Sprintf("name eq %q and clusterExtId eq %q", storageContainerName, *cluster.ExtId)
147+
fltr := fmt.Sprintf("name eq '%s' and clusterExtId eq '%s'", storageContainerName, *cluster.ExtId)
148148
resp, err := client.ListStorageContainers(nil, nil, &fltr, nil, nil)
149149
if err != nil {
150150
return nil, fmt.Errorf("failed to list storage containers: %w", err)

pkg/webhook/preflight/nutanix/storagecontainer_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -826,16 +826,16 @@ func TestStorageContainerCheck(t *testing.T) {
826826
*clustermgmtv4.ListStorageContainersApiResponse,
827827
error,
828828
) {
829-
// Simply return a container with the requested name
829+
require.NotNil(t, filter)
830+
// Extract name from filter
830831
containerName := ""
831-
if filter != nil {
832-
// Extract name from filter
833-
switch *filter {
834-
case "name eq \"valid-container\" and clusterExtId eq \"cluster-uuid-123\"":
835-
containerName = "valid-container"
836-
case "name eq \"another-valid-container\" and clusterExtId eq \"cluster-uuid-123\"":
837-
containerName = "another-valid-container"
838-
}
832+
switch *filter {
833+
case "name eq 'valid-container' and clusterExtId eq 'cluster-uuid-123'":
834+
containerName = "valid-container"
835+
case "name eq 'another-valid-container' and clusterExtId eq 'cluster-uuid-123'":
836+
containerName = "another-valid-container"
837+
default:
838+
return nil, fmt.Errorf("filter %q does not match any storage container", *filter)
839839
}
840840

841841
resp := &clustermgmtv4.ListStorageContainersApiResponse{

0 commit comments

Comments
 (0)