Skip to content

Commit c04d318

Browse files
committed
fix: optionally skip reading the config from the API server
Skip reading the driver configuration from the API server when -cloud-config-secret-name or -cloud-config-secret-namespace is explicitly set to an empty string. The unit test change is technically not necessary - no unit test actually tries to get the Secret from provided namespace / name, it only make the unit test future proof once they start doing so.
1 parent 73591ba commit c04d318

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/azurefile/azure.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func getCloudProvider(ctx context.Context, kubeconfig, nodeID, secretName, secre
9999
}
100100
}
101101

102-
if kubeClient != nil {
102+
if kubeClient != nil && secretName != "" && secretNamespace != "" {
103103
klog.V(2).Infof("reading cloud config from secret %s/%s", secretNamespace, secretName)
104104
config, err = configloader.Load[azureconfig.Config](ctx, &configloader.K8sSecretLoaderConfig{
105105
K8sSecretConfig: configloader.K8sSecretConfig{
@@ -118,7 +118,11 @@ func getCloudProvider(ctx context.Context, kubeconfig, nodeID, secretName, secre
118118
}
119119

120120
if config == nil {
121-
klog.V(2).Infof("could not read cloud config from secret %s/%s", secretNamespace, secretName)
121+
if secretName != "" || secretNamespace != "" {
122+
klog.V(2).Infof("reading cloud config from a Kubernetes secret is disabled")
123+
} else {
124+
klog.V(2).Infof("could not read cloud config from secret %s/%s", secretNamespace, secretName)
125+
}
122126
credFile, ok := os.LookupEnv(DefaultAzureCredentialFileEnv)
123127
if ok && strings.TrimSpace(credFile) != "" {
124128
klog.V(2).Infof("%s env var set as %v", DefaultAzureCredentialFileEnv, credFile)

pkg/azurefile/azure_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ users:
268268
t.Setenv("AZURE_FEDERATED_TOKEN_FILE", test.aadFederatedTokenFile)
269269
}
270270

271-
cloud, _, err := getCloudProvider(context.Background(), test.kubeconfig, "", "", "", test.userAgent, test.allowEmptyCloudConfig, false, 5, 10)
271+
cloud, _, err := getCloudProvider(context.Background(), test.kubeconfig, "", "azure-cloud-provider", "kube-system", test.userAgent, test.allowEmptyCloudConfig, false, 5, 10)
272272
if test.expectedErr.DefaultError != nil && test.expectedErr.WindowsError != nil {
273273
if !testutil.AssertError(err, &test.expectedErr) && !strings.Contains(err.Error(), test.expectedErr.DefaultError.Error()) {
274274
t.Errorf("desc: %s,\n input: %q, getCloudProvider err: %v, expectedErr: %v", test.desc, test.kubeconfig, err, test.expectedErr)

0 commit comments

Comments
 (0)