Skip to content

Conversation

@abhay-nutanix
Copy link
Contributor

@abhay-nutanix abhay-nutanix commented Dec 31, 2025

refactor: migration nutanix API to v4

abhay-nutanix and others added 4 commits January 12, 2026 13:19
…m Central version

- Replace GetCurrentLoggedInUser() with ValidateCredentials() using Users.List()
- Replace V3 GetPrismCentral() with DomainManager.GetPrismCentralVersion()
- Remove V3 client dependency from newClient()
- Update tests to use new ValidateCredentials interface
…ctive

- Update prism-go-client from v0.6.0 to v0.6.2
- Remove local replace directive for prism-go-client
- Use published v0.6.2 release which includes DomainManager and SubnetIPReservation features
- Add copyright header to pkg/webhook/preflight/nutanix/cache.go
- Fix import ordering in pkg/webhook/preflight/nutanix/credentials_test.go
  to comply with gci configuration (Standard -> Default -> Prefix groups)
@adarshanand25 adarshanand25 marked this pull request as ready for review January 12, 2026 08:22
@adarshanand25 adarshanand25 self-assigned this Jan 12, 2026
- Migrate e2e tests from direct V4 client to converged/v4 client
- Remove unnecessary taskData variable assignment in WaitForTaskCompletion
- Update networking and cluster helper functions to use converged client APIs
- Fix import ordering in credentials_test.go
- Format GetClusterUUIDFromName function signature to comply with golines
- Fix import ordering in credentials_test.go
Comment on lines +224 to +252
func buildManagementEndpoint(credentials *prismgoclient.Credentials) (*types.ManagementEndpoint, error) {
urlStr := credentials.URL

// Prepend https:// if no scheme is present
// Nutanix Prism Central URLs may be provided as "host:port" without scheme
if !strings.HasPrefix(urlStr, "http://") && !strings.HasPrefix(urlStr, "https://") {
urlStr = "https://" + urlStr
}

// Parse URL - preserve existing scheme if present (e.g., for test servers)
parsedURL, err := url.Parse(urlStr)
if err != nil {
return nil, fmt.Errorf("failed to parse URL %q: %w", urlStr, err)
}

// Validate that we have a host after parsing
if parsedURL.Host == "" {
return nil, fmt.Errorf("invalid URL %q: %w", credentials.URL, ErrEmptyHostInURL)
}

return &types.ManagementEndpoint{
Address: parsedURL,
Insecure: credentials.Insecure,
ApiCredentials: types.ApiCredentials{
Username: credentials.Username,
Password: credentials.Password,
},
}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just use the kubernetes environment provider?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use the Kubernetes environment provider pattern here because the preflight webhook runs before the NutanixCluster CR exists, and kubernetesEnv.NewProvider() requires informers that aren't available in webhook context. Please let me know your thoughts on this

Comment on lines 27 to 34
// ManagementEndpoint returns the management endpoint of the NutanixCluster CR.
func (c *CacheParams) ManagementEndpoint() types.ManagementEndpoint {
return *c.PrismManagementEndpoint
}

// Key returns a unique key for the client cache based on the management endpoint.
func (c *CacheParams) Key() string {
return c.PrismManagementEndpoint.Address.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the cached client be per cluster given each cluster can have different credentials?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can correct and use return fmt.Sprintf("%s:%s:%s:%t", endpoint.Address.String(), endpoint.ApiCredentials.Username, endpoint.ApiCredentials.Password, endpoint.Insecure, )

Copy link
Contributor

@thunderboltsid thunderboltsid Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can use the cluster name itself. See how CAPX handles this https://github.com/nutanix-cloud-native/cluster-api-provider-nutanix/blob/main/pkg/client/cache.go Internally the cache does hash the credentials as a key. this is more for a user-queryable key.

Update cache key to include endpoint address, username, password, and
insecure flag to ensure unique keys per credential set. This is necessary
because Prism Central clients use session-based authentication, where
each client maintains an authenticated session tied to specific credentials.

This ensures that clusters with different credentials get separate cached
clients, which is required for proper authentication.
- Update CacheParams to use types.NamespacedName for user-queryable cache key
- Add newClientWithCluster function to accept cluster information
- Update credentials check to pass cluster info for cache key
- Remove fallback to credentials-based key, always use cluster namespaced name
- Simplify Key() method to match CAPX approach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants