Skip to content

Commit 92800d9

Browse files
Ensure fallback config is only read when prismCentral is absent (#403)
Skip reading fallback config file from /etc/nutanix/config/prismCentral if NutanixCluster has prismCentral set. Co-authored-by: Sid Shukla <[email protected]>
1 parent 3171df2 commit 92800d9

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

pkg/client/client.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ func (n *NutanixClientHelper) buildManagementEndpoint(ctx context.Context, nutan
108108
providers = append(providers, providerForNutanixCluster)
109109
} else {
110110
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))
111-
}
112-
113-
// Fallback to building a provider using the global CAPX manager credentials
114-
providerForLocalFile, err := n.buildProviderFromFile()
115-
if err != nil {
116-
return nil, fmt.Errorf("error building an environment provider from file: %w", err)
117-
}
118-
if providerForLocalFile != nil {
119-
providers = append(providers, providerForLocalFile)
111+
// Fallback to building a provider using prism central information from the CAPX management cluster
112+
// using information from /etc/nutanix/config/prismCentral
113+
providerForLocalFile, err := n.buildProviderFromFile()
114+
if err != nil {
115+
return nil, fmt.Errorf("error building an environment provider from file: %w", err)
116+
}
117+
if providerForLocalFile != nil {
118+
providers = append(providers, providerForLocalFile)
119+
}
120120
}
121121

122122
// Initialize environment with providers

pkg/client/client_test.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,11 @@ func Test_buildManagementEndpoint(t *testing.T) {
116116
expectedErr error
117117
}{
118118
{
119-
name: "all information set in NutanixCluster",
119+
name: "all information set in NutanixCluster, should not fallback to management",
120+
// asserting that not being able to read the file will not result in an error
120121
helper: testHelperWithFakedInformers(testSecrets, testConfigMaps).withCustomNutanixPrismEndpointReader(
121122
func() (*credentials.NutanixPrismEndpoint, error) {
122-
return &credentials.NutanixPrismEndpoint{
123-
Address: "manager-endpoint",
124-
Port: 9440,
125-
CredentialRef: &credentials.NutanixCredentialReference{
126-
Kind: credentials.SecretKind,
127-
Name: "capx-nutanix-creds",
128-
Namespace: "capx-system",
129-
},
130-
AdditionalTrustBundle: &credentials.NutanixTrustBundleReference{
131-
Kind: credentials.NutanixTrustBundleKindConfigMap,
132-
Name: "cm",
133-
Namespace: "capx-system",
134-
},
135-
}, nil
123+
return nil, fmt.Errorf("could not read config")
136124
},
137125
),
138126
nutanixCluster: &infrav1.NutanixCluster{

0 commit comments

Comments
 (0)