diff --git a/internal/pkg/nutanix/prismclient.go b/internal/pkg/nutanix/prismclient.go index 4679f3129880..abe53e08e2d2 100644 --- a/internal/pkg/nutanix/prismclient.go +++ b/internal/pkg/nutanix/prismclient.go @@ -6,7 +6,6 @@ import ( "strings" prismgoclient "github.com/nutanix-cloud-native/prism-go-client" - "github.com/nutanix-cloud-native/prism-go-client/utils" v3 "github.com/nutanix-cloud-native/prism-go-client/v3" "github.com/aws/eks-anywhere/pkg/providers/nutanix" @@ -44,30 +43,39 @@ func NewPrismClient(endpoint, port string, insecure bool) (PrismClient, error) { // GetImageUUIDFromName retrieves the image uuid from the given image name. func (c *client) GetImageUUIDFromName(ctx context.Context, imageName string) (*string, error) { - res, err := c.V3.ListImage(ctx, &v3.DSMetadata{ - Filter: utils.StringPtr(fmt.Sprintf("name==%s", imageName)), - }) - if err != nil || len(res.Entities) == 0 { + res, err := c.V3.ListAllImage(ctx, "") + if err != nil { + return nil, fmt.Errorf("failed to list images: %v", err) + } + + images := make([]*v3.ImageIntentResponse, 0) + + for _, image := range res.Entities { + if image.Spec.Name != nil && *image.Spec.Name == imageName { + images = append(images, image) + } + } + + if len(images) == 0 { return nil, fmt.Errorf("failed to find image by name %q: %v", imageName, err) } - if len(res.Entities) > 1 { - return nil, fmt.Errorf("found more than one (%v) image with name %q", len(res.Entities), imageName) + if len(images) > 1 { + return nil, fmt.Errorf("found more than one (%v) image with name %q", len(images), imageName) } - return res.Entities[0].Metadata.UUID, nil + return images[0].Metadata.UUID, nil } // GetClusterUUIDFromName retrieves the cluster uuid from the given cluster name. // //nolint:gocyclo func (c *client) GetClusterUUIDFromName(ctx context.Context, clusterName string) (*string, error) { - res, err := c.V3.ListCluster(ctx, &v3.DSMetadata{ - Filter: utils.StringPtr(fmt.Sprintf("name==%s", clusterName)), - }) + res, err := c.V3.ListAllCluster(ctx, "") if err != nil { - return nil, fmt.Errorf("failed to find cluster by name %q: %v", clusterName, err) + return nil, fmt.Errorf("failed to list clusters: %v", err) } + entities := make([]*v3.ClusterIntentResponse, 0) for _, entity := range res.Entities { if entity.Status != nil && entity.Status.Resources != nil && entity.Status.Resources.Config != nil { @@ -97,16 +105,26 @@ func (c *client) GetClusterUUIDFromName(ctx context.Context, clusterName string) // GetSubnetUUIDFromName retrieves the subnet uuid from the given subnet name. func (c *client) GetSubnetUUIDFromName(ctx context.Context, subnetName string) (*string, error) { - res, err := c.V3.ListSubnet(ctx, &v3.DSMetadata{ - Filter: utils.StringPtr(fmt.Sprintf("name==%s", subnetName)), - }) - if err != nil || len(res.Entities) == 0 { + res, err := c.V3.ListAllSubnet(ctx, "", nil) + if err != nil { + return nil, fmt.Errorf("failed to list subnets: %v", err) + } + + subnets := make([]*v3.SubnetIntentResponse, 0) + + for _, subnet := range res.Entities { + if subnet.Spec.Name != nil && *subnet.Spec.Name == subnetName { + subnets = append(subnets, subnet) + } + } + + if len(subnets) == 0 { return nil, fmt.Errorf("failed to find subnet by name %q: %v", subnetName, err) } - if len(res.Entities) > 1 { - return nil, fmt.Errorf("found more than one (%v) subnet with name %q", len(res.Entities), subnetName) + if len(subnets) > 1 { + return nil, fmt.Errorf("found more than one (%v) subnet with name %q", len(subnets), subnetName) } - return res.Entities[0].Metadata.UUID, nil + return subnets[0].Metadata.UUID, nil } diff --git a/pkg/providers/nutanix/client.go b/pkg/providers/nutanix/client.go index 286fd66b7cc8..c1694509a798 100644 --- a/pkg/providers/nutanix/client.go +++ b/pkg/providers/nutanix/client.go @@ -3,19 +3,20 @@ package nutanix import ( "context" + prismgoclient "github.com/nutanix-cloud-native/prism-go-client" v3 "github.com/nutanix-cloud-native/prism-go-client/v3" ) type Client interface { GetSubnet(ctx context.Context, uuid string) (*v3.SubnetIntentResponse, error) ListAllHost(ctx context.Context) (*v3.HostListResponse, error) - ListSubnet(ctx context.Context, getEntitiesRequest *v3.DSMetadata) (*v3.SubnetListIntentResponse, error) + ListAllSubnet(ctx context.Context, filter string, clientSideFilters []*prismgoclient.AdditionalFilter) (*v3.SubnetListIntentResponse, error) GetImage(ctx context.Context, uuid string) (*v3.ImageIntentResponse, error) - ListImage(ctx context.Context, getEntitiesRequest *v3.DSMetadata) (*v3.ImageListIntentResponse, error) + ListAllImage(ctx context.Context, filter string) (*v3.ImageListIntentResponse, error) GetCluster(ctx context.Context, uuid string) (*v3.ClusterIntentResponse, error) - ListCluster(ctx context.Context, getEntitiesRequest *v3.DSMetadata) (*v3.ClusterListIntentResponse, error) + ListAllCluster(ctx context.Context, filter string) (*v3.ClusterListIntentResponse, error) GetProject(ctx context.Context, uuid string) (*v3.Project, error) - ListProject(ctx context.Context, getEntitiesRequest *v3.DSMetadata) (*v3.ProjectListResponse, error) + ListAllProject(ctx context.Context, filter string) (*v3.ProjectListResponse, error) GetCurrentLoggedInUser(ctx context.Context) (*v3.UserIntentResponse, error) ListCategories(ctx context.Context, getEntitiesRequest *v3.CategoryListMetadata) (*v3.CategoryKeyListResponse, error) GetCategoryKey(ctx context.Context, name string) (*v3.CategoryKeyStatus, error) diff --git a/pkg/providers/nutanix/mocks/client.go b/pkg/providers/nutanix/mocks/client.go index 796e0ea723ec..1fa3261ec49d 100644 --- a/pkg/providers/nutanix/mocks/client.go +++ b/pkg/providers/nutanix/mocks/client.go @@ -9,6 +9,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" + prismgoclient "github.com/nutanix-cloud-native/prism-go-client" v3 "github.com/nutanix-cloud-native/prism-go-client/v3" ) @@ -155,107 +156,107 @@ func (mr *MockClientMockRecorder) GetSubnet(ctx, uuid interface{}) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnet", reflect.TypeOf((*MockClient)(nil).GetSubnet), ctx, uuid) } -// ListAllHost mocks base method. -func (m *MockClient) ListAllHost(ctx context.Context) (*v3.HostListResponse, error) { +// ListAllCluster mocks base method. +func (m *MockClient) ListAllCluster(ctx context.Context, filter string) (*v3.ClusterListIntentResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListAllHost", ctx) - ret0, _ := ret[0].(*v3.HostListResponse) + ret := m.ctrl.Call(m, "ListAllCluster", ctx, filter) + ret0, _ := ret[0].(*v3.ClusterListIntentResponse) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListAllHost indicates an expected call of ListAllHost. -func (mr *MockClientMockRecorder) ListAllHost(ctx interface{}) *gomock.Call { +// ListAllCluster indicates an expected call of ListAllCluster. +func (mr *MockClientMockRecorder) ListAllCluster(ctx, filter interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllHost", reflect.TypeOf((*MockClient)(nil).ListAllHost), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllCluster", reflect.TypeOf((*MockClient)(nil).ListAllCluster), ctx, filter) } -// ListCategories mocks base method. -func (m *MockClient) ListCategories(ctx context.Context, getEntitiesRequest *v3.CategoryListMetadata) (*v3.CategoryKeyListResponse, error) { +// ListAllHost mocks base method. +func (m *MockClient) ListAllHost(ctx context.Context) (*v3.HostListResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListCategories", ctx, getEntitiesRequest) - ret0, _ := ret[0].(*v3.CategoryKeyListResponse) + ret := m.ctrl.Call(m, "ListAllHost", ctx) + ret0, _ := ret[0].(*v3.HostListResponse) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListCategories indicates an expected call of ListCategories. -func (mr *MockClientMockRecorder) ListCategories(ctx, getEntitiesRequest interface{}) *gomock.Call { +// ListAllHost indicates an expected call of ListAllHost. +func (mr *MockClientMockRecorder) ListAllHost(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListCategories", reflect.TypeOf((*MockClient)(nil).ListCategories), ctx, getEntitiesRequest) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllHost", reflect.TypeOf((*MockClient)(nil).ListAllHost), ctx) } -// ListCategoryValues mocks base method. -func (m *MockClient) ListCategoryValues(ctx context.Context, name string, getEntitiesRequest *v3.CategoryListMetadata) (*v3.CategoryValueListResponse, error) { +// ListAllImage mocks base method. +func (m *MockClient) ListAllImage(ctx context.Context, filter string) (*v3.ImageListIntentResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListCategoryValues", ctx, name, getEntitiesRequest) - ret0, _ := ret[0].(*v3.CategoryValueListResponse) + ret := m.ctrl.Call(m, "ListAllImage", ctx, filter) + ret0, _ := ret[0].(*v3.ImageListIntentResponse) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListCategoryValues indicates an expected call of ListCategoryValues. -func (mr *MockClientMockRecorder) ListCategoryValues(ctx, name, getEntitiesRequest interface{}) *gomock.Call { +// ListAllImage indicates an expected call of ListAllImage. +func (mr *MockClientMockRecorder) ListAllImage(ctx, filter interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListCategoryValues", reflect.TypeOf((*MockClient)(nil).ListCategoryValues), ctx, name, getEntitiesRequest) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllImage", reflect.TypeOf((*MockClient)(nil).ListAllImage), ctx, filter) } -// ListCluster mocks base method. -func (m *MockClient) ListCluster(ctx context.Context, getEntitiesRequest *v3.DSMetadata) (*v3.ClusterListIntentResponse, error) { +// ListAllProject mocks base method. +func (m *MockClient) ListAllProject(ctx context.Context, filter string) (*v3.ProjectListResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListCluster", ctx, getEntitiesRequest) - ret0, _ := ret[0].(*v3.ClusterListIntentResponse) + ret := m.ctrl.Call(m, "ListAllProject", ctx, filter) + ret0, _ := ret[0].(*v3.ProjectListResponse) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListCluster indicates an expected call of ListCluster. -func (mr *MockClientMockRecorder) ListCluster(ctx, getEntitiesRequest interface{}) *gomock.Call { +// ListAllProject indicates an expected call of ListAllProject. +func (mr *MockClientMockRecorder) ListAllProject(ctx, filter interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListCluster", reflect.TypeOf((*MockClient)(nil).ListCluster), ctx, getEntitiesRequest) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllProject", reflect.TypeOf((*MockClient)(nil).ListAllProject), ctx, filter) } -// ListImage mocks base method. -func (m *MockClient) ListImage(ctx context.Context, getEntitiesRequest *v3.DSMetadata) (*v3.ImageListIntentResponse, error) { +// ListAllSubnet mocks base method. +func (m *MockClient) ListAllSubnet(ctx context.Context, filter string, clientSideFilters []*prismgoclient.AdditionalFilter) (*v3.SubnetListIntentResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListImage", ctx, getEntitiesRequest) - ret0, _ := ret[0].(*v3.ImageListIntentResponse) + ret := m.ctrl.Call(m, "ListAllSubnet", ctx, filter, clientSideFilters) + ret0, _ := ret[0].(*v3.SubnetListIntentResponse) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListImage indicates an expected call of ListImage. -func (mr *MockClientMockRecorder) ListImage(ctx, getEntitiesRequest interface{}) *gomock.Call { +// ListAllSubnet indicates an expected call of ListAllSubnet. +func (mr *MockClientMockRecorder) ListAllSubnet(ctx, filter, clientSideFilters interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListImage", reflect.TypeOf((*MockClient)(nil).ListImage), ctx, getEntitiesRequest) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllSubnet", reflect.TypeOf((*MockClient)(nil).ListAllSubnet), ctx, filter, clientSideFilters) } -// ListProject mocks base method. -func (m *MockClient) ListProject(ctx context.Context, getEntitiesRequest *v3.DSMetadata) (*v3.ProjectListResponse, error) { +// ListCategories mocks base method. +func (m *MockClient) ListCategories(ctx context.Context, getEntitiesRequest *v3.CategoryListMetadata) (*v3.CategoryKeyListResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListProject", ctx, getEntitiesRequest) - ret0, _ := ret[0].(*v3.ProjectListResponse) + ret := m.ctrl.Call(m, "ListCategories", ctx, getEntitiesRequest) + ret0, _ := ret[0].(*v3.CategoryKeyListResponse) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListProject indicates an expected call of ListProject. -func (mr *MockClientMockRecorder) ListProject(ctx, getEntitiesRequest interface{}) *gomock.Call { +// ListCategories indicates an expected call of ListCategories. +func (mr *MockClientMockRecorder) ListCategories(ctx, getEntitiesRequest interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListProject", reflect.TypeOf((*MockClient)(nil).ListProject), ctx, getEntitiesRequest) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListCategories", reflect.TypeOf((*MockClient)(nil).ListCategories), ctx, getEntitiesRequest) } -// ListSubnet mocks base method. -func (m *MockClient) ListSubnet(ctx context.Context, getEntitiesRequest *v3.DSMetadata) (*v3.SubnetListIntentResponse, error) { +// ListCategoryValues mocks base method. +func (m *MockClient) ListCategoryValues(ctx context.Context, name string, getEntitiesRequest *v3.CategoryListMetadata) (*v3.CategoryValueListResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListSubnet", ctx, getEntitiesRequest) - ret0, _ := ret[0].(*v3.SubnetListIntentResponse) + ret := m.ctrl.Call(m, "ListCategoryValues", ctx, name, getEntitiesRequest) + ret0, _ := ret[0].(*v3.CategoryValueListResponse) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListSubnet indicates an expected call of ListSubnet. -func (mr *MockClientMockRecorder) ListSubnet(ctx, getEntitiesRequest interface{}) *gomock.Call { +// ListCategoryValues indicates an expected call of ListCategoryValues. +func (mr *MockClientMockRecorder) ListCategoryValues(ctx, name, getEntitiesRequest interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListSubnet", reflect.TypeOf((*MockClient)(nil).ListSubnet), ctx, getEntitiesRequest) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListCategoryValues", reflect.TypeOf((*MockClient)(nil).ListCategoryValues), ctx, name, getEntitiesRequest) } diff --git a/pkg/providers/nutanix/provider_test.go b/pkg/providers/nutanix/provider_test.go index 97e2650f766f..4b48dfb83dd9 100644 --- a/pkg/providers/nutanix/provider_test.go +++ b/pkg/providers/nutanix/provider_test.go @@ -391,7 +391,7 @@ func TestNutanixProviderSetupAndValidateCreate(t *testing.T) { }, }, } - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(clusters, nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(clusters, nil).AnyTimes() subnets := &v3.SubnetListIntentResponse{ Entities: []*v3.SubnetIntentResponse{ { @@ -400,11 +400,16 @@ func TestNutanixProviderSetupAndValidateCreate(t *testing.T) { }, Spec: &v3.Subnet{ Name: utils.StringPtr("prism-subnet"), + ClusterReference: &v3.Reference{ + Kind: utils.StringPtr("cluster"), + UUID: utils.StringPtr("a15f6966-bfc7-4d1e-8575-224096fc1cda"), + Name: utils.StringPtr("prism-cluster"), + }, }, }, }, } - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(subnets, nil).AnyTimes() + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), nil).Return(subnets, nil).AnyTimes() images := &v3.ImageListIntentResponse{ Entities: []*v3.ImageIntentResponse{ { @@ -415,9 +420,17 @@ func TestNutanixProviderSetupAndValidateCreate(t *testing.T) { Name: utils.StringPtr("prism-image"), }, }, + { + Metadata: &v3.Metadata{ + UUID: utils.StringPtr("a15f6966-bfc7-4d1e-8575-224096fc1cdd"), + }, + Spec: &v3.Image{ + Name: utils.StringPtr("prism-image-1-19"), + }, + }, }, } - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(images, nil).AnyTimes() + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(images, nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(fakeHostList(), nil).AnyTimes() mockCertValidator := mockCrypto.NewMockTlsValidator(ctrl) mockCertValidator.EXPECT().ValidateCert(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) diff --git a/pkg/providers/nutanix/validator.go b/pkg/providers/nutanix/validator.go index 4723f3ee46f4..86e8e38975dd 100644 --- a/pkg/providers/nutanix/validator.go +++ b/pkg/providers/nutanix/validator.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/nutanix-cloud-native/prism-go-client/environment/credentials" - "github.com/nutanix-cloud-native/prism-go-client/utils" v3 "github.com/nutanix-cloud-native/prism-go-client/v3" "k8s.io/apimachinery/pkg/api/resource" @@ -745,18 +744,29 @@ func checkMachineConfigIsForWorker(config *anywherev1.NutanixMachineConfig, clus // findSubnetUUIDByName retrieves the subnet uuid by the given subnet name. func findSubnetUUIDByName(ctx context.Context, v3Client Client, clusterUUID, subnetName string) (*string, error) { - res, err := v3Client.ListSubnet(ctx, &v3.DSMetadata{ - Filter: utils.StringPtr(fmt.Sprintf("name==%s;cluster_uuid==%s", subnetName, clusterUUID)), - }) - if err != nil || len(res.Entities) == 0 { + res, err := v3Client.ListAllSubnet(ctx, "", nil) + if err != nil { + return nil, fmt.Errorf("failed to list subnets: %v", err) + } + + subnets := make([]*v3.SubnetIntentResponse, 0) + for _, subnet := range res.Entities { + if subnet.Spec.ClusterReference != nil && *subnet.Spec.ClusterReference.UUID != "" { + if *subnet.Spec.ClusterReference.UUID == clusterUUID && subnet.Spec.Name != nil && *subnet.Spec.Name == subnetName { + subnets = append(subnets, subnet) + } + } + } + + if len(subnets) == 0 { return nil, fmt.Errorf("failed to find subnet by name %q: %v", subnetName, err) } - if len(res.Entities) > 1 { - return nil, fmt.Errorf("found more than one (%v) subnet with name %q and cluster uuid %v", len(res.Entities), subnetName, clusterUUID) + if len(subnets) > 1 { + return nil, fmt.Errorf("found more than one (%v) subnet with name %q and cluster uuid %v", len(subnets), subnetName, clusterUUID) } - return res.Entities[0].Metadata.UUID, nil + return subnets[0].Metadata.UUID, nil } // getWorkerMachineGroups retrieves the worker machine group names from the cluster spec. @@ -794,12 +804,11 @@ func getClusterUUID(ctx context.Context, v3Client Client, cluster anywherev1.Nut // findClusterUUIDByName retrieves the cluster uuid by the given cluster name. func findClusterUUIDByName(ctx context.Context, v3Client Client, clusterName string) (*string, error) { - res, err := v3Client.ListCluster(ctx, &v3.DSMetadata{ - Filter: utils.StringPtr(fmt.Sprintf("name==%s", clusterName)), - }) + res, err := v3Client.ListAllCluster(ctx, "") if err != nil { - return nil, fmt.Errorf("failed to find cluster by name %q: %v", clusterName, err) + return nil, fmt.Errorf("failed to list clusters: %v", err) } + entities := make([]*v3.ClusterIntentResponse, 0) for _, entity := range res.Entities { if entity.Status != nil && entity.Status.Resources != nil && entity.Status.Resources.Config != nil { @@ -816,6 +825,7 @@ func findClusterUUIDByName(ctx context.Context, v3Client Client, clusterName str } } } + if len(entities) == 0 { return nil, fmt.Errorf("failed to find cluster by name %q: %v", clusterName, err) } @@ -829,34 +839,52 @@ func findClusterUUIDByName(ctx context.Context, v3Client Client, clusterName str // findImageUUIDByName retrieves the image uuid by the given image name. func findImageUUIDByName(ctx context.Context, v3Client Client, imageName string) (*string, error) { - res, err := v3Client.ListImage(ctx, &v3.DSMetadata{ - Filter: utils.StringPtr(fmt.Sprintf("name==%s", imageName)), - }) - if err != nil || len(res.Entities) == 0 { + res, err := v3Client.ListAllImage(ctx, "") + if err != nil { + return nil, fmt.Errorf("failed to list images: %v", err) + } + + images := make([]*v3.ImageIntentResponse, 0) + for _, image := range res.Entities { + if image.Spec.Name != nil && *image.Spec.Name == imageName { + images = append(images, image) + } + } + + if len(images) == 0 { return nil, fmt.Errorf("failed to find image by name %q: %v", imageName, err) } - if len(res.Entities) > 1 { - return nil, fmt.Errorf("found more than one (%v) image with name %q", len(res.Entities), imageName) + if len(images) > 1 { + return nil, fmt.Errorf("found more than one (%v) image with name %q", len(images), imageName) } - return res.Entities[0].Metadata.UUID, nil + return images[0].Metadata.UUID, nil } // findProjectUUIDByName retrieves the project uuid by the given image name. func findProjectUUIDByName(ctx context.Context, v3Client Client, projectName string) (*string, error) { - res, err := v3Client.ListProject(ctx, &v3.DSMetadata{ - Filter: utils.StringPtr(fmt.Sprintf("name==%s", projectName)), - }) - if err != nil || len(res.Entities) == 0 { + res, err := v3Client.ListAllProject(ctx, "") + if err != nil { + return nil, fmt.Errorf("failed to list projects: %v", err) + } + + projects := make([]*v3.Project, 0) + for _, project := range res.Entities { + if project.Spec.Name == projectName { + projects = append(projects, project) + } + } + + if len(projects) == 0 { return nil, fmt.Errorf("failed to find project by name %q: %v", projectName, err) } - if len(res.Entities) > 1 { + if len(projects) > 1 { return nil, fmt.Errorf("found more than one (%v) project with name %q", len(res.Entities), projectName) } - return res.Entities[0].Metadata.UUID, nil + return projects[0].Metadata.UUID, nil } func isRequestedGPUAssignable(gpu v3.GPU, requestedGpu anywherev1.NutanixGPUIdentifier) bool { diff --git a/pkg/providers/nutanix/validator_test.go b/pkg/providers/nutanix/validator_test.go index be2606fc9561..5f30bf4d32c4 100644 --- a/pkg/providers/nutanix/validator_test.go +++ b/pkg/providers/nutanix/validator_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/golang/mock/gomock" + prismgoclient "github.com/nutanix-cloud-native/prism-go-client" "github.com/nutanix-cloud-native/prism-go-client/utils" v3 "github.com/nutanix-cloud-native/prism-go-client/v3" "github.com/stretchr/testify/assert" @@ -95,13 +96,18 @@ func fakeSubnetList() *v3.SubnetListIntentResponse { }, Spec: &v3.Subnet{ Name: utils.StringPtr("prism-subnet"), + ClusterReference: &v3.Reference{ + Kind: utils.StringPtr("cluster"), + UUID: utils.StringPtr("a15f6966-bfc7-4d1e-8575-224096fc1cdb"), + Name: utils.StringPtr("prism-cluster"), + }, }, }, }, } } -func fakeClusterListForDCTest(filter *string) (*v3.ClusterListIntentResponse, error) { +func fakeClusterListForDCTest(filter string) (*v3.ClusterListIntentResponse, error) { data := &v3.ClusterListIntentResponse{ Entities: []*v3.ClusterIntentResponse{ { @@ -141,19 +147,21 @@ func fakeClusterListForDCTest(filter *string) (*v3.ClusterListIntentResponse, er Entities: []*v3.ClusterIntentResponse{}, } - if filter != nil && *filter != "" { - str := strings.Replace(*filter, "name==", "", -1) + if filter != "" { + str := strings.Replace(filter, "name==", "", -1) for _, cluster := range data.Entities { if str == *cluster.Spec.Name { result.Entities = append(result.Entities, cluster) } } + } else { + result.Entities = data.Entities } return result, nil } -func fakeSubnetListForDCTest(filter *string) (*v3.SubnetListIntentResponse, error) { +func fakeSubnetListForDCTest(filter string) (*v3.SubnetListIntentResponse, error) { data := &v3.SubnetListIntentResponse{ Entities: []*v3.SubnetIntentResponse{ { @@ -162,6 +170,11 @@ func fakeSubnetListForDCTest(filter *string) (*v3.SubnetListIntentResponse, erro }, Spec: &v3.Subnet{ Name: utils.StringPtr("prism-subnet"), + ClusterReference: &v3.Reference{ + Kind: utils.StringPtr("cluster"), + UUID: utils.StringPtr("4d69ca7d-022f-49d1-a454-74535993bda4"), + Name: utils.StringPtr("prism-cluster-1"), + }, }, }, { @@ -170,6 +183,11 @@ func fakeSubnetListForDCTest(filter *string) (*v3.SubnetListIntentResponse, erro }, Spec: &v3.Subnet{ Name: utils.StringPtr("prism-subnet-1"), + ClusterReference: &v3.Reference{ + Kind: utils.StringPtr("cluster"), + UUID: utils.StringPtr("a15f6966-bfc7-4d1e-8575-224096fc1cdb"), + Name: utils.StringPtr("prism-cluster"), + }, }, }, }, @@ -179,14 +197,16 @@ func fakeSubnetListForDCTest(filter *string) (*v3.SubnetListIntentResponse, erro Entities: []*v3.SubnetIntentResponse{}, } - if filter != nil && *filter != "" { - filters := strings.Split(*filter, ";") + if filter != "" { + filters := strings.Split(filter, ";") str := strings.Replace(filters[0], "name==", "", -1) for _, subnet := range data.Entities { if str == *subnet.Spec.Name { result.Entities = append(result.Entities, subnet) } } + } else { + result.Entities = data.Entities } return result, nil @@ -215,7 +235,7 @@ func fakeProjectList() *v3.ProjectListResponse { UUID: utils.StringPtr("5c9a0641-1025-40ed-9e1d-0d0a23043e57"), }, Spec: &v3.ProjectSpec{ - Name: "prism-image", + Name: "project", }, }, }, @@ -297,16 +317,16 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "list cluster request failed", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(nil, errors.New("cluster not found")) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(nil, errors.New("cluster not found")) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, - expectedError: "failed to find cluster by name", + expectedError: "failed to list clusters", }, { name: "list cluster request did not find match", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(&v3.ClusterListIntentResponse{}, nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(&v3.ClusterListIntentResponse{}, nil) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, @@ -317,7 +337,7 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { clusters := fakeClusterList() clusters.Entities = append(clusters.Entities, clusters.Entities[0]) - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(clusters, nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(clusters, nil) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, @@ -326,7 +346,7 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "empty subnet name", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) machineConf.Spec.Subnet.Name = nil clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) @@ -336,7 +356,7 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "empty subnet uuid", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) machineConf.Spec.Subnet.Type = anywherev1.NutanixIdentifierUUID machineConf.Spec.Subnet.UUID = nil clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} @@ -347,7 +367,7 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "invalid subnet identifier type", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) machineConf.Spec.Subnet.Type = "notanidentifier" clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) @@ -357,18 +377,18 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "list subnet request failed", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(nil, errors.New("subnet not found")) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("subnet not found")) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, - expectedError: "failed to find subnet by name", + expectedError: "failed to list subnets", }, { name: "list subnet request did not find match", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(&v3.SubnetListIntentResponse{}, nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(&v3.SubnetListIntentResponse{}, nil) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, @@ -377,10 +397,10 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "duplicate subnets found", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) subnets := fakeSubnetList() subnets.Entities = append(subnets.Entities, subnets.Entities[0]) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(subnets, nil) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(subnets, nil) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, @@ -389,8 +409,8 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "empty image name", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) machineConf.Spec.Image.Name = nil clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) @@ -400,8 +420,8 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "empty image uuid", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) machineConf.Spec.Image.Type = anywherev1.NutanixIdentifierUUID machineConf.Spec.Image.UUID = nil clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} @@ -412,8 +432,8 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "invalid image identifier type", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) machineConf.Spec.Image.Type = "notanidentifier" clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) @@ -423,20 +443,20 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "list image request failed", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(nil, errors.New("image not found")) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(nil, errors.New("image not found")) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, - expectedError: "failed to find image by name", + expectedError: "failed to list images", }, { name: "list image request did not find match", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(&v3.ImageListIntentResponse{}, nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(&v3.ImageListIntentResponse{}, nil) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, @@ -445,11 +465,11 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "duplicate image found", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) images := fakeImageList() images.Entities = append(images.Entities, images.Entities[0]) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(images, nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(images, nil) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, @@ -466,9 +486,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { assert.NoError(t, err) cluster.Status.Resources.Config.ServiceList = []*string{utils.StringPtr("PRISM_CENTRAL")} clusters.Entities = append(clusters.Entities, &cluster) - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(clusters, nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(clusters, nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, @@ -477,9 +497,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "empty project name", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.Project = &anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierName, Name: nil, @@ -492,9 +512,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "empty project uuid", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.Project = &anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierUUID, UUID: nil, @@ -507,9 +527,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "invalid project identifier type", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.Project = &anywherev1.NutanixResourceIdentifier{ Type: "notatype", UUID: nil, @@ -522,10 +542,10 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "list project request failed", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) - mockClient.EXPECT().ListProject(gomock.Any(), gomock.Any()).Return(nil, errors.New("project not found")) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllProject(gomock.Any(), gomock.Any()).Return(nil, errors.New("project not found")) machineConf.Spec.Project = &anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierName, Name: utils.StringPtr("notaproject"), @@ -533,15 +553,15 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { clientCache := &ClientCache{clients: map[string]Client{"test": mockClient}} return NewValidator(clientCache, validator, &http.Client{Transport: transport}) }, - expectedError: "failed to find project by name", + expectedError: "failed to list projects", }, { name: "list project request did not find match", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) - mockClient.EXPECT().ListProject(gomock.Any(), gomock.Any()).Return(&v3.ProjectListResponse{}, nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllProject(gomock.Any(), gomock.Any()).Return(&v3.ProjectListResponse{}, nil) machineConf.Spec.Project = &anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierName, Name: utils.StringPtr("notaproject"), @@ -554,12 +574,12 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "duplicate project found", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) projects := fakeProjectList() projects.Entities = append(projects.Entities, projects.Entities[0]) - mockClient.EXPECT().ListProject(gomock.Any(), gomock.Any()).Return(projects, nil) + mockClient.EXPECT().ListAllProject(gomock.Any(), gomock.Any()).Return(projects, nil) machineConf.Spec.Project = &anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierName, Name: utils.StringPtr("project"), @@ -572,9 +592,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "empty category key", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.AdditionalCategories = []anywherev1.NutanixCategoryIdentifier{ { Key: "", @@ -589,9 +609,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "empty category value", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.AdditionalCategories = []anywherev1.NutanixCategoryIdentifier{ { Key: "key", @@ -606,9 +626,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "get category key failed", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) mockClient.EXPECT().GetCategoryKey(gomock.Any(), gomock.Any()).Return(nil, errors.New("category key not found")) machineConf.Spec.AdditionalCategories = []anywherev1.NutanixCategoryIdentifier{ { @@ -624,9 +644,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "get category value failed", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) categoryKey := v3.CategoryKeyStatus{ Name: utils.StringPtr("key"), } @@ -646,9 +666,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "invalid gpu identifier type", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { Type: "invalid", @@ -662,9 +682,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "missing GPU type", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { Type: "", @@ -678,9 +698,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "missing GPU device ID", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { Type: "deviceID", @@ -694,9 +714,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "missing GPU name", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { Type: "name", @@ -710,9 +730,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "machine config is not associated with any worker node group", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Name = "test-wn" machineConf.Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { @@ -727,9 +747,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "GPUs are not supported for control plane machine", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Name = "test-cp" machineConf.Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { @@ -744,9 +764,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "GPUs are not supported for external etcd machine", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Name = "test-etcd" machineConf.Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { @@ -761,9 +781,9 @@ func TestNutanixValidatorValidateMachineConfig(t *testing.T) { { name: "validation pass", setup: func(machineConf *anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) - mockClient.EXPECT().ListImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterList(), nil).Times(2) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeSubnetList(), nil) + mockClient.EXPECT().ListAllImage(gomock.Any(), gomock.Any()).Return(fakeImageList(), nil) machineConf.Name = "eksa-unit-test" machineConf.Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { @@ -1084,7 +1104,7 @@ func TestNutanixValidatorValidateFreeGPU(t *testing.T) { { name: "not enough GPU resources available by name", setup: func(machineConfigs map[string]*anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(fakeHostList(), nil) machineConfigs["cp"].Spec.Cluster = anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierUUID, @@ -1122,7 +1142,7 @@ func TestNutanixValidatorValidateFreeGPU(t *testing.T) { { name: "not enough GPU resources available by name in different PE (UUID)", setup: func(machineConfigs map[string]*anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(fakeHostList(), nil) machineConfigs["cp"].Spec.Cluster = anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierUUID, @@ -1159,7 +1179,7 @@ func TestNutanixValidatorValidateFreeGPU(t *testing.T) { { name: "not enough GPU resources available by deviceID in different PE (UUID)", setup: func(machineConfigs map[string]*anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(fakeHostList(), nil) machineConfigs["cp"].Spec.Cluster = anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierUUID, @@ -1192,7 +1212,7 @@ func TestNutanixValidatorValidateFreeGPU(t *testing.T) { { name: "not enough GPU resources available by deviceID", setup: func(machineConfigs map[string]*anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(fakeHostList(), nil) machineConfigs["cp"].Spec.Cluster = anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierUUID, @@ -1238,7 +1258,7 @@ func TestNutanixValidatorValidateFreeGPU(t *testing.T) { { name: "no GPU resources found", setup: func(machineConfigs map[string]*anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(fakeEmptyHostList(), nil) machineConfigs["worker"].Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { @@ -1266,7 +1286,7 @@ func TestNutanixValidatorValidateFreeGPU(t *testing.T) { { name: "no GPU resources found: ListAllHost failed", setup: func(machineConfigs map[string]*anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(nil, fmt.Errorf("failed to list hosts")) machineConfigs["worker"].Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { @@ -1294,7 +1314,7 @@ func TestNutanixValidatorValidateFreeGPU(t *testing.T) { { name: "mixed passthrough and vGPU mode GPUs in a machine config", setup: func(machineConfigs map[string]*anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(fakeHostList(), nil) machineConfigs["worker"].Spec.GPUs = []anywherev1.NutanixGPUIdentifier{ { @@ -1314,7 +1334,7 @@ func TestNutanixValidatorValidateFreeGPU(t *testing.T) { { name: "GPUs validation successful", setup: func(machineConfigs map[string]*anywherev1.NutanixMachineConfig, mockClient *mocknutanix.MockClient, validator *mockCrypto.MockTlsValidator, transport *mocknutanix.MockRoundTripper) *Validator { - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).Return(fakeClusterListForFreeGPUTest(), nil).AnyTimes() mockClient.EXPECT().ListAllHost(gomock.Any()).Return(fakeHostList(), nil) machineConfigs["cp"].Spec.Cluster = anywherev1.NutanixResourceIdentifier{ Type: anywherev1.NutanixIdentifierUUID, @@ -1473,14 +1493,14 @@ func TestNutanixValidatorValidateDatacenterConfig(t *testing.T) { ctrl := gomock.NewController(t) mockClient := mocknutanix.NewMockClient(ctrl) mockClient.EXPECT().GetCurrentLoggedInUser(gomock.Any()).Return(&v3.UserIntentResponse{}, nil).AnyTimes() - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).DoAndReturn( - func(_ context.Context, filters *v3.DSMetadata) (*v3.ClusterListIntentResponse, error) { - return fakeClusterListForDCTest(filters.Filter) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).DoAndReturn( + func(_ context.Context, filter string) (*v3.ClusterListIntentResponse, error) { + return fakeClusterListForDCTest(filter) }, ).AnyTimes() - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).DoAndReturn( - func(_ context.Context, filters *v3.DSMetadata) (*v3.SubnetListIntentResponse, error) { - return fakeSubnetListForDCTest(filters.Filter) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn( + func(_ context.Context, filter string, _ []*prismgoclient.AdditionalFilter) (*v3.SubnetListIntentResponse, error) { + return fakeSubnetListForDCTest(filter) }, ).AnyTimes() mockClient.EXPECT().GetSubnet(gomock.Any(), gomock.Eq("2d166190-7759-4dc6-b835-923262d6b497")).Return(nil, nil).AnyTimes() @@ -1768,14 +1788,14 @@ func TestValidateMachineConfigFailureDomainsWrongCount(t *testing.T) { ctrl := gomock.NewController(t) mockClient := mocknutanix.NewMockClient(ctrl) mockClient.EXPECT().GetCurrentLoggedInUser(gomock.Any()).Return(&v3.UserIntentResponse{}, nil).AnyTimes() - mockClient.EXPECT().ListCluster(gomock.Any(), gomock.Any()).DoAndReturn( - func(_ context.Context, filters *v3.DSMetadata) (*v3.ClusterListIntentResponse, error) { - return fakeClusterListForDCTest(filters.Filter) + mockClient.EXPECT().ListAllCluster(gomock.Any(), gomock.Any()).DoAndReturn( + func(_ context.Context, filter string) (*v3.ClusterListIntentResponse, error) { + return fakeClusterListForDCTest(filter) }, ).AnyTimes() - mockClient.EXPECT().ListSubnet(gomock.Any(), gomock.Any()).DoAndReturn( - func(_ context.Context, filters *v3.DSMetadata) (*v3.SubnetListIntentResponse, error) { - return fakeSubnetListForDCTest(filters.Filter) + mockClient.EXPECT().ListAllSubnet(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn( + func(_ context.Context, filter string) (*v3.SubnetListIntentResponse, error) { + return fakeSubnetListForDCTest(filter) }, ).AnyTimes() mockClient.EXPECT().GetSubnet(gomock.Any(), gomock.Eq("2d166190-7759-4dc6-b835-923262d6b497")).Return(nil, nil).AnyTimes()