Skip to content
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

Fix connection initialization flow for joined node #1078

Merged
merged 1 commit into from
Jan 11, 2024
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
15 changes: 10 additions & 5 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,13 +716,13 @@ func configurePolicyConnectorData(d *schema.ResourceData, clients *nsxtClients)
}

if !isVMC {
err = configureLicenses(getPolicyConnectorForInit(*clients, true), clients.CommonConfig.LicenseKeys)
err = configureLicenses(getStandalonePolicyConnector(*clients, true), clients.CommonConfig.LicenseKeys)
if err != nil {
return err
}
}

err = initNSXVersion(getPolicyConnectorForInit(*clients, true))
err = initNSXVersion(getStandalonePolicyConnector(*clients, true))
if err != nil && isVMC {
// In case version API does not work for VMC, we workaround by testing version-specific APIs
// TODO - remove this when /node/version API works for all auth methods on VMC
Expand Down Expand Up @@ -974,15 +974,19 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return clients, nil
}

// Standard policy connection that initializes global connection settings on demand
func getPolicyConnector(clients interface{}) client.Connector {
return getPolicyConnectorWithHeaders(clients, nil, false, true)
}

func getPolicyConnectorForInit(clients interface{}, withRetry bool) client.Connector {
// Standalone policy connector, possibly for different endpoint,
// for the purpose of special tasks (such as joining manager cluster node)
// Does not initialize global connection settings
func getStandalonePolicyConnector(clients interface{}, withRetry bool) client.Connector {
return getPolicyConnectorWithHeaders(clients, nil, true, withRetry)
}

func getPolicyConnectorWithHeaders(clients interface{}, customHeaders *map[string]string, initFlow bool, withRetry bool) client.Connector {
func getPolicyConnectorWithHeaders(clients interface{}, customHeaders *map[string]string, standaloneFlow bool, withRetry bool) client.Connector {
c := clients.(nsxtClients)

retryFunc := func(retryContext retry.RetryContext) bool {
Expand Down Expand Up @@ -1064,7 +1068,8 @@ func getPolicyConnectorWithHeaders(clients interface{}, customHeaders *map[strin
connector := client.NewConnector(c.Host, connectorOptions...)
// Init NSX version on demand if not done yet
// This is also our indication to apply licenses, in case of delayed connection
if nsxVersion == "" && !initFlow {
// This step is skipped if the connector is for special purpose, or for different endpoint
if nsxVersion == "" && !standaloneFlow {
initNSXVersion(connector)
err := configureLicenses(connector, c.CommonConfig.LicenseKeys)
if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions nsxt/resource_nsxt_manager_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func waitForNodeStatus(d *schema.ResourceData, m interface{}, nodes []NsxCluster
log.Printf("[DEBUG]: API probing for NSX is disabled")
return nil
}
connector := getPolicyConnectorForInit(m, false)
connector := getStandalonePolicyConnector(m, false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still see the same failure with the PR applied.
I've tried to change this line to

connector := getPolicyConnector(m)

Which worked - I think that as with getStandalonePolicyConnector we skip license assignment, this is where we want to assign the license and therefore use the regular getPolicyConnector

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This connection just waits for node status, it should not require license, but we don't want it to initialize the version for the main NSX connection and thus skip license assignment for it..

stateConf := getNodeConnectivityStateConf(connector, delay, interval, timeout)
_, err := stateConf.WaitForState()
if err != nil {
Expand All @@ -182,7 +182,7 @@ func waitForNodeStatus(d *schema.ResourceData, m interface{}, nodes []NsxCluster
return err
}
newNsxClients := c.(nsxtClients)
nodeConnector := getPolicyConnectorForInit(newNsxClients, false)
nodeConnector := getStandalonePolicyConnector(newNsxClients, false)
nodeConf := getNodeConnectivityStateConf(nodeConnector, 0, interval, timeout)
_, err = nodeConf.WaitForState()
if err != nil {
Expand Down Expand Up @@ -330,10 +330,6 @@ func configureNewClient(newClient *nsxtClients, oldClient *nsxtClients, host str
}
newClient.PolicySecurityContext = securityCtx
newClient.PolicyHTTPClient = oldClient.PolicyHTTPClient
err = initNSXVersion(getPolicyConnector(*newClient))
if err != nil {
return fmt.Errorf("Failed to configure new client with host %s: %s", host, err)
}
return nil
}

Expand All @@ -344,7 +340,7 @@ func joinNodeToCluster(clusterID string, certSha256Thumbprint string, guestNode
}
log.Printf("[INFO] Cluster %s. Joining node %s", clusterID, guestNode.IPAddress)
newNsxClients := c.(nsxtClients)
connector := getPolicyConnector(newNsxClients)
connector := getStandalonePolicyConnector(newNsxClients, true)
client := nsx.NewClusterClient(connector)
username, password := getHostCredential(m)
hostIP := getMatchingIPVersion(guestNode.IPAddress, hostIPs)
Expand Down