Skip to content

Commit a07cabe

Browse files
authored
Merge pull request #2942 from k8s-infra-cherrypick-robot/cherry-pick-2940-to-release-1.34
[release-1.34] fix: optionally skip reading the config from the API server
2 parents 9c6c93d + ebf4e92 commit a07cabe

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
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)

pkg/azurefile/azurefile_options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (o *DriverOptions) AddFlags() *flag.FlagSet {
6565
fs.StringVar(&o.DriverName, "drivername", DefaultDriverName, "name of the driver")
6666
fs.BoolVar(&o.EnableAzurefileProxy, "enable-azurefile-proxy", false, "enable azurefile proxy")
6767
fs.StringVar(&o.AzureFileProxyEndpoint, "azurefile-proxy-endpoint", "unix://tmp/azurefile-proxy.sock", "azurefile-proxy endpoint")
68-
fs.StringVar(&o.CloudConfigSecretName, "cloud-config-secret-name", "azure-cloud-provider", "secret name of cloud config")
69-
fs.StringVar(&o.CloudConfigSecretNamespace, "cloud-config-secret-namespace", "kube-system", "secret namespace of cloud config")
68+
fs.StringVar(&o.CloudConfigSecretName, "cloud-config-secret-name", "azure-cloud-provider", "secret name of cloud config. If set to an empty string, the driver will not read cloud config from a Kubernetes secret.")
69+
fs.StringVar(&o.CloudConfigSecretNamespace, "cloud-config-secret-namespace", "kube-system", "secret namespace of cloud config. If set to an empty string, the driver will not read cloud config from a Kubernetes secret.")
7070
fs.StringVar(&o.CustomUserAgent, "custom-user-agent", "", "custom userAgent")
7171
fs.StringVar(&o.UserAgentSuffix, "user-agent-suffix", "", "userAgent suffix")
7272
fs.BoolVar(&o.AllowEmptyCloudConfig, "allow-empty-cloud-config", true, "allow running driver without cloud config")

0 commit comments

Comments
 (0)