@@ -22,20 +22,17 @@ import (
22
22
"os"
23
23
"strings"
24
24
25
- "golang.org/x/net/context"
26
-
27
25
kv "github.com/Azure/azure-sdk-for-go/services/keyvault/2016-10-01/keyvault"
28
26
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-07-01/network"
29
27
"github.com/Azure/azure-sdk-for-go/storage"
30
-
31
28
"github.com/Azure/go-autorest/autorest"
32
-
29
+ "golang.org/x/net/context"
33
30
clientset "k8s.io/client-go/kubernetes"
34
31
"k8s.io/client-go/rest"
35
32
"k8s.io/client-go/tools/clientcmd"
36
33
"k8s.io/klog/v2"
37
34
"k8s.io/utils/pointer"
38
-
35
+ "sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader"
39
36
azure "sigs.k8s.io/cloud-provider-azure/pkg/provider"
40
37
providerconfig "sigs.k8s.io/cloud-provider-azure/pkg/provider/config"
41
38
)
@@ -52,20 +49,14 @@ func IsAzureStackCloud(cloud *azure.Cloud) bool {
52
49
}
53
50
54
51
// getCloudProvider get Azure Cloud Provider
55
- func GetCloudProvider (kubeconfig , nodeID , secretName , secretNamespace , userAgent string , allowEmptyCloudConfig bool , kubeAPIQPS float64 , kubeAPIBurst int ) (* azure.Cloud , error ) {
52
+ func GetCloudProvider (ctx context. Context , kubeconfig , nodeID , secretName , secretNamespace , userAgent string , allowEmptyCloudConfig bool , kubeAPIQPS float64 , kubeAPIBurst int ) (* azure.Cloud , error ) {
56
53
var (
57
54
config * azure.Config
58
55
kubeClient * clientset.Clientset
59
56
fromSecret bool
60
57
)
61
58
62
- az := & azure.Cloud {
63
- InitSecretConfig : azure.InitSecretConfig {
64
- SecretName : secretName ,
65
- SecretNamespace : secretNamespace ,
66
- CloudConfigKey : "cloud-config" ,
67
- },
68
- }
59
+ az := & azure.Cloud {}
69
60
az .Environment .StorageEndpointSuffix = storage .DefaultBaseURL
70
61
71
62
kubeCfg , err := getKubeConfig (kubeconfig )
@@ -85,19 +76,26 @@ func GetCloudProvider(kubeconfig, nodeID, secretName, secretNamespace, userAgent
85
76
}
86
77
87
78
if kubeClient != nil {
88
- klog .V (2 ).Infof ("reading cloud config from secret %s/%s" , az .SecretNamespace , az .SecretName )
89
79
az .KubeClient = kubeClient
90
- config , err = az .GetConfigFromSecret ()
80
+ klog .V (2 ).Infof ("reading cloud config from secret %s/%s" , secretNamespace , secretName )
81
+ config , err := configloader .Load [azure.Config ](ctx , & configloader.K8sSecretLoaderConfig {
82
+ K8sSecretConfig : configloader.K8sSecretConfig {
83
+ SecretName : secretName ,
84
+ SecretNamespace : secretNamespace ,
85
+ CloudConfigKey : "cloud-config" ,
86
+ },
87
+ KubeClient : kubeClient ,
88
+ }, nil )
91
89
if err == nil && config != nil {
92
90
fromSecret = true
93
91
}
94
92
if err != nil {
95
- klog .V (2 ).Infof ("InitializeCloudFromSecret: failed to get cloud config from secret %s/%s: %v" , az . SecretNamespace , az . SecretName , err )
93
+ klog .V (2 ).Infof ("InitializeCloudFromSecret: failed to get cloud config from secret %s/%s: %v" , secretNamespace , secretName , err )
96
94
}
97
95
}
98
96
99
97
if config == nil {
100
- klog .V (2 ).Infof ("could not read cloud config from secret %s/%s" , az . SecretNamespace , az . SecretName )
98
+ klog .V (2 ).Infof ("could not read cloud config from secret %s/%s" , secretNamespace , secretName )
101
99
credFile , ok := os .LookupEnv (DefaultAzureCredentialFileEnv )
102
100
if ok && strings .TrimSpace (credFile ) != "" {
103
101
klog .V (2 ).Infof ("%s env var set as %v" , DefaultAzureCredentialFileEnv , credFile )
@@ -106,15 +104,11 @@ func GetCloudProvider(kubeconfig, nodeID, secretName, secretNamespace, userAgent
106
104
klog .V (2 ).Infof ("use default %s env var: %v" , DefaultAzureCredentialFileEnv , credFile )
107
105
}
108
106
109
- credFileConfig , err := os .Open (credFile )
107
+ config , err = configloader .Load [azure.Config ](ctx , nil , & configloader.FileLoaderConfig {
108
+ FilePath : credFile ,
109
+ })
110
110
if err != nil {
111
111
klog .Warningf ("load azure config from file(%s) failed with %v" , credFile , err )
112
- } else {
113
- defer credFileConfig .Close ()
114
- klog .V (2 ).Infof ("read cloud config from file: %s successfully" , credFile )
115
- if config , err = azure .ParseConfig (credFileConfig ); err != nil {
116
- klog .Warningf ("parse config file(%s) failed with error: %v" , credFile , err )
117
- }
118
112
}
119
113
}
120
114
0 commit comments