Skip to content

Commit

Permalink
Ensure fallback config is only read when prismCentral is absent (#403)
Browse files Browse the repository at this point in the history
Skip reading fallback config file from /etc/nutanix/config/prismCentral
if NutanixCluster has prismCentral set.

Co-authored-by: Sid Shukla <sid.shukla@nutanix.com>
  • Loading branch information
deepakm-ntnx and thunderboltsid authored Apr 9, 2024
1 parent 3171df2 commit 92800d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
18 changes: 9 additions & 9 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ func (n *NutanixClientHelper) buildManagementEndpoint(ctx context.Context, nutan
providers = append(providers, providerForNutanixCluster)
} else {
log.Info(fmt.Sprintf("[WARNING] prismCentral attribute was not set on NutanixCluster %s in namespace %s. Defaulting to CAPX manager credentials", nutanixCluster.Name, nutanixCluster.Namespace))
}

// Fallback to building a provider using the global CAPX manager credentials
providerForLocalFile, err := n.buildProviderFromFile()
if err != nil {
return nil, fmt.Errorf("error building an environment provider from file: %w", err)
}
if providerForLocalFile != nil {
providers = append(providers, providerForLocalFile)
// Fallback to building a provider using prism central information from the CAPX management cluster
// using information from /etc/nutanix/config/prismCentral
providerForLocalFile, err := n.buildProviderFromFile()
if err != nil {
return nil, fmt.Errorf("error building an environment provider from file: %w", err)
}
if providerForLocalFile != nil {
providers = append(providers, providerForLocalFile)
}
}

// Initialize environment with providers
Expand Down
18 changes: 3 additions & 15 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,11 @@ func Test_buildManagementEndpoint(t *testing.T) {
expectedErr error
}{
{
name: "all information set in NutanixCluster",
name: "all information set in NutanixCluster, should not fallback to management",
// asserting that not being able to read the file will not result in an error
helper: testHelperWithFakedInformers(testSecrets, testConfigMaps).withCustomNutanixPrismEndpointReader(
func() (*credentials.NutanixPrismEndpoint, error) {
return &credentials.NutanixPrismEndpoint{
Address: "manager-endpoint",
Port: 9440,
CredentialRef: &credentials.NutanixCredentialReference{
Kind: credentials.SecretKind,
Name: "capx-nutanix-creds",
Namespace: "capx-system",
},
AdditionalTrustBundle: &credentials.NutanixTrustBundleReference{
Kind: credentials.NutanixTrustBundleKindConfigMap,
Name: "cm",
Namespace: "capx-system",
},
}, nil
return nil, fmt.Errorf("could not read config")
},
),
nutanixCluster: &infrav1.NutanixCluster{
Expand Down

0 comments on commit 92800d9

Please sign in to comment.