@@ -4,26 +4,20 @@ import (
4
4
"context"
5
5
"errors"
6
6
"os"
7
- "strconv"
8
7
9
8
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud/metadata"
10
9
cnfsv1beta1 "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cnfs/v1beta1"
11
10
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/nas/cloud"
12
11
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/nas/interfaces"
13
12
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/options"
13
+ "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils"
14
14
corev1 "k8s.io/api/core/v1"
15
- apierrors "k8s.io/apimachinery/pkg/api/errors"
16
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
16
"k8s.io/client-go/dynamic"
18
17
"k8s.io/client-go/kubernetes"
19
18
"k8s.io/klog/v2"
20
19
)
21
20
22
- const (
23
- configMapName = "csi-plugin"
24
- configMapNamespace = "kube-system"
25
- )
26
-
27
21
type ControllerConfig struct {
28
22
// cluster info
29
23
Region string
@@ -50,26 +44,19 @@ func mustGetKubeClients() (kubernetes.Interface, cnfsv1beta1.CNFSGetter) {
50
44
51
45
func GetControllerConfig (meta * metadata.Metadata ) (* ControllerConfig , error ) {
52
46
kubeClient , cnfsGetter := mustGetKubeClients ()
47
+ cm := utils .DefaultConfig ()
48
+
53
49
config := & ControllerConfig {
54
50
Region : metadata .MustGet (meta , metadata .RegionID ),
55
51
ClusterID : os .Getenv ("CLUSTER_ID" ),
56
52
KubeClient : kubeClient ,
57
53
CNFSGetter : cnfsGetter ,
58
54
NasClientFactory : cloud .NewNasClientFactory (),
59
- }
60
55
61
- cm , err := kubeClient .CoreV1 ().ConfigMaps (configMapNamespace ).Get (context .Background (), configMapName , metav1.GetOptions {})
62
- if err != nil {
63
- if ! apierrors .IsNotFound (err ) {
64
- return nil , err
65
- }
66
- } else {
67
- config .SkipSubpathCreation , _ = parseBool (cm .Data ["nas-fake-provision" ])
56
+ SkipSubpathCreation : cm .GetBool ("nas-fake-provision" , "NAS_FAKE_PROVISION" , false ),
57
+ EnableSubpathFinalizer : cm .GetBool ("nas-subpath-finalizer" , "ENABLE_NAS_SUBPATH_FINALIZER" , true ),
58
+ EnableRecycleBinCheck : cm .GetBool ("nas-recyclebin-check" , "ENABLE_NAS_RECYCLEBIN_CHECK" , false ),
68
59
}
69
-
70
- config .EnableSubpathFinalizer , _ = parseBool (os .Getenv ("ENABLE_NAS_SUBPATH_FINALIZER" ))
71
- config .EnableRecycleBinCheck , _ = parseBool (os .Getenv ("ENABLE_NAS_RECYCLEBIN_CHECK" ))
72
-
73
60
return config , nil
74
61
}
75
62
@@ -92,33 +79,19 @@ type NodeConfig struct {
92
79
93
80
func GetNodeConfig () (* NodeConfig , error ) {
94
81
kubeClient , cnfsGetter := mustGetKubeClients ()
95
- config := & NodeConfig {
96
- // enable nfs port check by default
97
- EnablePortCheck : true ,
98
- KubeClient : kubeClient ,
99
- CNFSGetter : cnfsGetter ,
100
- }
82
+ cm := utils .DefaultConfig ()
101
83
102
- // check if enable nfs port check
103
- if value := os .Getenv ("NAS_PORT_CHECK" ); value != "" {
104
- config .EnablePortCheck , _ = parseBool (value )
84
+ config := & NodeConfig {
85
+ KubeClient : kubeClient ,
86
+ CNFSGetter : cnfsGetter ,
87
+
88
+ EnablePortCheck : cm .GetBool ("nas-port-check" , "NAS_PORT_CHECK" , true ),
89
+ EnableVolumeStats : cm .GetBool ("nas-metric-enable" , "NAS_METRIC_BY_PLUGIN" , false ),
90
+ EnableEFCCache : cm .Get ("cnfs-cache-properties" , "" , "" ) != "" ||
91
+ cm .Get ("nas-efc-cache" , "" , "" ) != "" ,
92
+ EnableLosetup : cm .GetBool ("nas-losetup-enable" , "NAS_LOSETUP_ENABLE" , false ),
105
93
}
106
94
107
- // get csi-plugin configmap
108
- cm , err := kubeClient .CoreV1 ().ConfigMaps (configMapNamespace ).Get (context .Background (), configMapName , metav1.GetOptions {})
109
- if err != nil {
110
- if ! apierrors .IsNotFound (err ) {
111
- return nil , err
112
- }
113
- } else {
114
- if value := cm .Data ["nas-metric-enable" ]; value != "" {
115
- config .EnableVolumeStats , _ = parseBool (value )
116
- }
117
- config .EnableEFCCache = cm .Data ["cnfs-cache-properties" ] != "" || cm .Data ["nas-efc-cache" ] != ""
118
- }
119
- if value := os .Getenv ("NAS_METRIC_BY_PLUGIN" ); value != "" {
120
- config .EnableVolumeStats , _ = parseBool (value )
121
- }
122
95
if config .EnableVolumeStats {
123
96
klog .Info ("enabled nas volume stats" )
124
97
}
@@ -132,9 +105,6 @@ func GetNodeConfig() (*NodeConfig, error) {
132
105
config .NodeName = nodeName
133
106
134
107
// check if losetup enabled
135
- if value := os .Getenv ("NAS_LOSETUP_ENABLE" ); value != "" {
136
- config .EnableLosetup , _ = parseBool (value )
137
- }
138
108
if config .EnableLosetup {
139
109
klog .Info ("enabled nas losetup mode" )
140
110
for _ , addr := range node .Status .Addresses {
@@ -150,13 +120,3 @@ func GetNodeConfig() (*NodeConfig, error) {
150
120
151
121
return config , nil
152
122
}
153
-
154
- func parseBool (str string ) (bool , error ) {
155
- switch str {
156
- case "enable" , "enabled" , "yes" :
157
- return true , nil
158
- case "no" , "" :
159
- return false , nil
160
- }
161
- return strconv .ParseBool (str )
162
- }
0 commit comments