@@ -18,6 +18,7 @@ package plugins
18
18
19
19
import (
20
20
"fmt"
21
+ "strings"
21
22
22
23
v1 "k8s.io/api/core/v1"
23
24
storagev1 "k8s.io/api/storage/v1"
@@ -28,6 +29,29 @@ import (
28
29
const (
29
30
PortworxVolumePluginName = "kubernetes.io/portworx-volume"
30
31
PortworxDriverName = "pxd.portworx.com"
32
+
33
+ OpenStorageAuthSecretNameKey = "openstorage.io/auth-secret-name"
34
+ OpenStorageAuthSecretNamespaceKey = "openstorage.io/auth-secret-namespace"
35
+
36
+ csiParameterPrefix = "csi.storage.k8s.io/"
37
+
38
+ prefixedProvisionerSecretNameKey = csiParameterPrefix + "provisioner-secret-name"
39
+ prefixedProvisionerSecretNamespaceKey = csiParameterPrefix + "provisioner-secret-namespace"
40
+
41
+ prefixedControllerPublishSecretNameKey = csiParameterPrefix + "controller-publish-secret-name"
42
+ prefixedControllerPublishSecretNamespaceKey = csiParameterPrefix + "controller-publish-secret-namespace"
43
+
44
+ prefixedNodeStageSecretNameKey = csiParameterPrefix + "node-stage-secret-name"
45
+ prefixedNodeStageSecretNamespaceKey = csiParameterPrefix + "node-stage-secret-namespace"
46
+
47
+ prefixedNodePublishSecretNameKey = csiParameterPrefix + "node-publish-secret-name"
48
+ prefixedNodePublishSecretNamespaceKey = csiParameterPrefix + "node-publish-secret-namespace"
49
+
50
+ prefixedControllerExpandSecretNameKey = csiParameterPrefix + "controller-expand-secret-name"
51
+ prefixedControllerExpandSecretNamespaceKey = csiParameterPrefix + "controller-expand-secret-namespace"
52
+
53
+ prefixedNodeExpandSecretNameKey = csiParameterPrefix + "node-expand-secret-name"
54
+ prefixedNodeExpandSecretNamespaceKey = csiParameterPrefix + "node-expand-secret-namespace"
31
55
)
32
56
33
57
var _ InTreePlugin = & portworxCSITranslator {}
@@ -44,7 +68,34 @@ func (p portworxCSITranslator) TranslateInTreeStorageClassToCSI(logger klog.Logg
44
68
if sc == nil {
45
69
return nil , fmt .Errorf ("sc is nil" )
46
70
}
71
+
72
+ var params = map [string ]string {}
73
+ for k , v := range sc .Parameters {
74
+ switch strings .ToLower (k ) {
75
+ case OpenStorageAuthSecretNameKey :
76
+ params [prefixedProvisionerSecretNameKey ] = v
77
+ params [prefixedControllerPublishSecretNameKey ] = v
78
+ params [prefixedNodePublishSecretNameKey ] = v
79
+ params [prefixedNodeStageSecretNameKey ] = v
80
+ params [prefixedControllerExpandSecretNameKey ] = v
81
+ params [prefixedNodeExpandSecretNameKey ] = v
82
+ case OpenStorageAuthSecretNamespaceKey :
83
+ params [prefixedProvisionerSecretNamespaceKey ] = v
84
+ params [prefixedControllerPublishSecretNamespaceKey ] = v
85
+ params [prefixedNodePublishSecretNamespaceKey ] = v
86
+ params [prefixedNodeStageSecretNamespaceKey ] = v
87
+ params [prefixedControllerExpandSecretNamespaceKey ] = v
88
+ params [prefixedNodeExpandSecretNamespaceKey ] = v
89
+ default :
90
+ // All other parameters can be copied as is
91
+ params [k ] = v
92
+ }
93
+ }
94
+ if len (params ) > 0 {
95
+ sc .Parameters = params
96
+ }
47
97
sc .Provisioner = PortworxDriverName
98
+
48
99
return sc , nil
49
100
}
50
101
@@ -87,11 +138,26 @@ func (p portworxCSITranslator) TranslateInTreePVToCSI(logger klog.Logger, pv *v1
87
138
if pv == nil || pv .Spec .PortworxVolume == nil {
88
139
return nil , fmt .Errorf ("pv is nil or PortworxVolume not defined on pv" )
89
140
}
141
+ var secretRef * v1.SecretReference
142
+
143
+ if metav1 .HasAnnotation (pv .ObjectMeta , OpenStorageAuthSecretNameKey ) &&
144
+ metav1 .HasAnnotation (pv .ObjectMeta , OpenStorageAuthSecretNamespaceKey ) {
145
+ secretRef = & v1.SecretReference {
146
+ Name : pv .Annotations [OpenStorageAuthSecretNameKey ],
147
+ Namespace : pv .Annotations [OpenStorageAuthSecretNamespaceKey ],
148
+ }
149
+ }
150
+
90
151
csiSource := & v1.CSIPersistentVolumeSource {
91
- Driver : PortworxDriverName ,
92
- VolumeHandle : pv .Spec .PortworxVolume .VolumeID ,
93
- FSType : pv .Spec .PortworxVolume .FSType ,
94
- VolumeAttributes : make (map [string ]string ), // copy access mode
152
+ Driver : PortworxDriverName ,
153
+ VolumeHandle : pv .Spec .PortworxVolume .VolumeID ,
154
+ FSType : pv .Spec .PortworxVolume .FSType ,
155
+ VolumeAttributes : make (map [string ]string ), // copy access mode
156
+ ControllerPublishSecretRef : secretRef ,
157
+ NodeStageSecretRef : secretRef ,
158
+ NodePublishSecretRef : secretRef ,
159
+ ControllerExpandSecretRef : secretRef ,
160
+ NodeExpandSecretRef : secretRef ,
95
161
}
96
162
pv .Spec .PortworxVolume = nil
97
163
pv .Spec .CSI = csiSource
0 commit comments