Skip to content

feat(preflight): Storage container checks for Nutanix #1136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/google/uuid v1.6.0
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api v0.0.0-00010101000000-000000000000
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.7.0
github.com/nutanix-cloud-native/prism-go-client v0.5.1
github.com/nutanix-cloud-native/prism-go-client v0.5.2
github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4 v4.0.1-beta.2
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.2-beta.1
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1
Expand Down Expand Up @@ -122,7 +122,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nutanix/ntnx-api-golang-clients/storage-go-client/v4 v4.0.2-alpha.3 // indirect
github.com/nutanix/ntnx-api-golang-clients/volumes-go-client/v4 v4.0.1-beta.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,14 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/nutanix-cloud-native/prism-go-client v0.5.1 h1:ykiXPCILzEMORHz7XvI8KXNomChsdLIpOAlT/YqBCmo=
github.com/nutanix-cloud-native/prism-go-client v0.5.1/go.mod h1:QhLX+sEep0cStzHVYU6mPgIlnA8U3DySskagrbDprRk=
github.com/nutanix-cloud-native/prism-go-client v0.5.2 h1:qhFJeC3CRrWM8BTaNvxnjShVNH5E99z5MPU3a2BO14A=
github.com/nutanix-cloud-native/prism-go-client v0.5.2/go.mod h1:N/O9fz5fimjb30RxlPbKbGs/Z2lqMgDqrb6CrsZvQrA=
github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4 v4.0.1-beta.2 h1:s1u5/GEw3mTZakepJoTD1OvPVU1YuioRxmKZin+W99s=
github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4 v4.0.1-beta.2/go.mod h1:sd4Fnk6MVfEDVY+8WyRoQTmLhi2SgZ3riySWErVHf8E=
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.2-beta.1 h1:PvZQwYhhJtxmzLpnzEhHTpp2fV6woc6W65PHGsHzVfs=
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.2-beta.1/go.mod h1:+eZgV1+xL/r84qmuFSVt5R8OFRO70rEz92jOnVgJNco=
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1 h1:hvy3QCc2SgVidYxTq0rRPOazJOt1PP8A86kW7j6sywU=
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1/go.mod h1:Yhk+xD4mN90OKEHnk5ARf97CX5p4+MEC/B/YIVoZeZ0=
github.com/nutanix/ntnx-api-golang-clients/storage-go-client/v4 v4.0.2-alpha.3 h1:K3I9YtqKcKKxSL4+tcxnFeLOoaptiVlpsOJ9Xzq3shM=
github.com/nutanix/ntnx-api-golang-clients/storage-go-client/v4 v4.0.2-alpha.3/go.mod h1:kz3gO87xtWnPOCP2kN7yw5LvCDVRnvg8BOWL7CarqXA=
github.com/nutanix/ntnx-api-golang-clients/vmm-go-client/v4 v4.0.1-beta.1 h1:XuTRvYu1kiNjdXOYVwyjhKlFWyo9nMit6GsOYV8+5Cg=
github.com/nutanix/ntnx-api-golang-clients/vmm-go-client/v4 v4.0.1-beta.1/go.mod h1:CaWm4GFpAjQQDc6YXl/dUDrHpuW54h8j6Cj7EslE4Qk=
github.com/nutanix/ntnx-api-golang-clients/volumes-go-client/v4 v4.0.1-beta.1 h1:VJSaQDnnYeNEk1mkQqEbt573OdM62+5s/B0e9kszdas=
Expand Down
12 changes: 9 additions & 3 deletions pkg/webhook/preflight/nutanix/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
)

var Checker = &nutanixChecker{
configurationCheckFactory: newConfigurationCheck,
credentialsCheckFactory: newCredentialsCheck,
vmImageChecksFactory: newVMImageChecks,
configurationCheckFactory: newConfigurationCheck,
credentialsCheckFactory: newCredentialsCheck,
vmImageChecksFactory: newVMImageChecks,
storageContainerChecksFactory: newStorageContainerChecks,
}

type nutanixChecker struct {
Expand All @@ -37,6 +38,10 @@ type nutanixChecker struct {
vmImageChecksFactory func(
cd *checkDependencies,
) []preflight.Check

storageContainerChecksFactory func(
cd *checkDependencies,
) []preflight.Check
}

type checkDependencies struct {
Expand Down Expand Up @@ -69,6 +74,7 @@ func (n *nutanixChecker) Init(
}

checks = append(checks, n.vmImageChecksFactory(cd)...)
checks = append(checks, n.storageContainerChecksFactory(cd)...)

// Add more checks here as needed.

Expand Down
83 changes: 56 additions & 27 deletions pkg/webhook/preflight/nutanix/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,24 @@ func (m *mockCheck) Run(ctx context.Context) preflight.CheckResult {

func TestNutanixChecker_Init(t *testing.T) {
tests := []struct {
name string
nutanixConfig *carenv1.NutanixClusterConfigSpec
workerNodeConfigs map[string]*carenv1.NutanixWorkerNodeConfigSpec
expectedCheckCount int
expectedFirstCheckName string
expectedSecondCheckName string
vmImageCheckCount int
name string
nutanixConfig *carenv1.NutanixClusterConfigSpec
workerNodeConfigs map[string]*carenv1.NutanixWorkerNodeConfigSpec
expectedCheckCount int
expectedFirstCheckName string
expectedSecondCheckName string
vmImageCheckCount int
storageContainerCheckCount int
}{
{
name: "basic initialization with no configs",
nutanixConfig: nil,
workerNodeConfigs: nil,
expectedCheckCount: 2, // config check and credentials check
expectedFirstCheckName: "NutanixConfiguration",
expectedSecondCheckName: "NutanixCredentials",
vmImageCheckCount: 0,
name: "basic initialization with no configs",
nutanixConfig: nil,
workerNodeConfigs: nil,
expectedCheckCount: 2, // config check and credentials check
expectedFirstCheckName: "NutanixConfiguration",
expectedSecondCheckName: "NutanixCredentials",
vmImageCheckCount: 0,
storageContainerCheckCount: 0,
},
{
name: "initialization with control plane config",
Expand All @@ -57,11 +59,12 @@ func TestNutanixChecker_Init(t *testing.T) {
Nutanix: &carenv1.NutanixNodeSpec{},
},
},
workerNodeConfigs: nil,
expectedCheckCount: 3, // config check, credentials check, 1 VM image check
expectedFirstCheckName: "NutanixConfiguration",
expectedSecondCheckName: "NutanixCredentials",
vmImageCheckCount: 1,
workerNodeConfigs: nil,
expectedCheckCount: 4, // config check, credentials check, 1 VM image check, 1 storage container check
expectedFirstCheckName: "NutanixConfiguration",
expectedSecondCheckName: "NutanixCredentials",
vmImageCheckCount: 1,
storageContainerCheckCount: 1,
},
{
name: "initialization with worker node configs",
Expand All @@ -74,10 +77,11 @@ func TestNutanixChecker_Init(t *testing.T) {
Nutanix: &carenv1.NutanixNodeSpec{},
},
},
expectedCheckCount: 4, // config check, credentials check, 2 VM image checks
expectedFirstCheckName: "NutanixConfiguration",
expectedSecondCheckName: "NutanixCredentials",
vmImageCheckCount: 2,
expectedCheckCount: 6, // config check, credentials check, 2 VM image checks, 2 storage container checks
expectedFirstCheckName: "NutanixConfiguration",
expectedSecondCheckName: "NutanixCredentials",
vmImageCheckCount: 2,
storageContainerCheckCount: 2,
},
{
name: "initialization with both control plane and worker node configs",
Expand All @@ -91,10 +95,12 @@ func TestNutanixChecker_Init(t *testing.T) {
Nutanix: &carenv1.NutanixNodeSpec{},
},
},
expectedCheckCount: 4, // config check, credentials check, 2 VM image checks (1 CP + 1 worker)
expectedFirstCheckName: "NutanixConfiguration",
expectedSecondCheckName: "NutanixCredentials",
vmImageCheckCount: 2,
// config check, credentials check, 2 VM image checks (1 CP + 1 worker), 2 storage container checks (1 CP + 1 worker)
expectedCheckCount: 6,
expectedFirstCheckName: "NutanixConfiguration",
expectedSecondCheckName: "NutanixCredentials",
vmImageCheckCount: 2,
storageContainerCheckCount: 2,
},
}

Expand All @@ -107,6 +113,7 @@ func TestNutanixChecker_Init(t *testing.T) {
configCheckCalled := false
credsCheckCalled := false
vmImageCheckCount := 0
storageContainerCheckCount := 0

checker.configurationCheckFactory = func(cd *checkDependencies) preflight.Check {
configCheckCalled = true
Expand Down Expand Up @@ -144,6 +151,22 @@ func TestNutanixChecker_Init(t *testing.T) {
return checks
}

checker.storageContainerChecksFactory = func(cd *checkDependencies) []preflight.Check {
checks := []preflight.Check{}
for i := 0; i < tt.storageContainerCheckCount; i++ {
storageContainerCheckCount++
checks = append(checks,
&mockCheck{
name: fmt.Sprintf("NutanixStorageContainer-%d", i),
result: preflight.CheckResult{
Allowed: true,
},
},
)
}
return checks
}

// Call Init
ctx := context.Background()
checks := checker.Init(ctx, nil, &clusterv1.Cluster{
Expand All @@ -160,6 +183,12 @@ func TestNutanixChecker_Init(t *testing.T) {
assert.True(t, configCheckCalled, "initNutanixConfiguration should have been called")
assert.True(t, credsCheckCalled, "initCredentialsCheck should have been called")
assert.Equal(t, tt.vmImageCheckCount, vmImageCheckCount, "Wrong number of VM image checks")
assert.Equal(
t,
tt.storageContainerCheckCount,
storageContainerCheckCount,
"Wrong number of storage container checks",
)

// Verify the first two checks when we have results
if len(checks) >= 2 {
Expand Down
73 changes: 73 additions & 0 deletions pkg/webhook/preflight/nutanix/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"

clustermgmtv4 "github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4/models/clustermgmt/v4/config"
vmmv4 "github.com/nutanix/ntnx-api-golang-clients/vmm-go-client/v4/models/vmm/v4/content"

prismgoclient "github.com/nutanix-cloud-native/prism-go-client"
Expand All @@ -29,6 +30,24 @@ type client interface {
*vmmv4.ListImagesApiResponse,
error,
)
GetClusterById(id *string) (*clustermgmtv4.GetClusterApiResponse, error)
ListClusters(
page_ *int,
limit_ *int,
filter_ *string,
orderby_ *string,
apply_ *string,
select_ *string,
args ...map[string]interface{},
) (*clustermgmtv4.ListClustersApiResponse, error)
ListStorageContainers(
page_ *int,
limit_ *int,
filter_ *string,
orderby_ *string,
select_ *string,
args ...map[string]interface{},
) (*clustermgmtv4.ListStorageContainersApiResponse, error)
}

// clientWrapper implements the client interface and wraps both v3 and v4 clients.
Expand Down Expand Up @@ -90,3 +109,57 @@ func (c *clientWrapper) ListImages(page_ *int,
}
return resp, nil
}

func (c *clientWrapper) GetClusterById(id *string) (*clustermgmtv4.GetClusterApiResponse, error) {
resp, err := c.v4client.ClustersApiInstance.GetClusterById(id)
if err != nil {
return nil, err
}
return resp, nil
}

func (c *clientWrapper) ListClusters(
page_ *int,
limit_ *int,
filter_ *string,
orderby_ *string,
apply_ *string,
select_ *string,
args ...map[string]interface{},
) (*clustermgmtv4.ListClustersApiResponse, error) {
resp, err := c.v4client.ClustersApiInstance.ListClusters(
page_,
limit_,
filter_,
orderby_,
apply_,
select_,
args...,
)
if err != nil {
return nil, err
}
return resp, nil
}

func (c *clientWrapper) ListStorageContainers(
page_ *int,
limit_ *int,
filter_ *string,
orderby_ *string,
select_ *string,
args ...map[string]interface{},
) (*clustermgmtv4.ListStorageContainersApiResponse, error) {
resp, err := c.v4client.StorageContainerAPI.ListStorageContainers(
page_,
limit_,
filter_,
orderby_,
select_,
args...,
)
if err != nil {
return nil, err
}
return resp, nil
}
42 changes: 42 additions & 0 deletions pkg/webhook/preflight/nutanix/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package nutanix
import (
"context"

clustermgmtv4 "github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4/models/clustermgmt/v4/config"
vmmv4 "github.com/nutanix/ntnx-api-golang-clients/vmm-go-client/v4/models/vmm/v4/content"

prismv3 "github.com/nutanix-cloud-native/prism-go-client/v3"
Expand Down Expand Up @@ -35,6 +36,27 @@ type mocknclient struct {
*vmmv4.ListImagesApiResponse,
error,
)

getClusterByIdFunc func(id *string) (*clustermgmtv4.GetClusterApiResponse, error)

listClustersFunc func(
page,
limit *int,
filter,
orderby,
apply,
select_ *string,
args ...map[string]interface{},
) (*clustermgmtv4.ListClustersApiResponse, error)

listStorageContainersFunc func(
page,
limit *int,
filter,
orderby,
select_ *string,
args ...map[string]interface{},
) (*clustermgmtv4.ListStorageContainersApiResponse, error)
}

func (m *mocknclient) GetCurrentLoggedInUser(ctx context.Context) (*prismv3.UserIntentResponse, error) {
Expand All @@ -52,3 +74,23 @@ func (m *mocknclient) ListImages(
) (*vmmv4.ListImagesApiResponse, error) {
return m.listImagesFunc(page, limit, filter, orderby, select_)
}

func (m *mocknclient) GetClusterById(id *string) (*clustermgmtv4.GetClusterApiResponse, error) {
return m.getClusterByIdFunc(id)
}

func (m *mocknclient) ListClusters(
page, limit *int,
filter, orderby, apply, select_ *string,
args ...map[string]interface{},
) (*clustermgmtv4.ListClustersApiResponse, error) {
return m.listClustersFunc(page, limit, filter, orderby, apply, select_, args...)
}

func (m *mocknclient) ListStorageContainers(
page, limit *int,
filter, orderby, select_ *string,
args ...map[string]interface{},
) (*clustermgmtv4.ListStorageContainersApiResponse, error) {
return m.listStorageContainersFunc(page, limit, filter, orderby, select_, args...)
}
Loading
Loading