-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: migration nutanix API to v4 #1444
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
base: main
Are you sure you want to change the base?
Conversation
…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)
b21883a to
45fdee2
Compare
- 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
| 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 | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
| // 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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, )
There was a problem hiding this comment.
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.
16b82eb to
d341471
Compare
- 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
09189a6 to
0600133
Compare
refactor: migration nutanix API to v4