@@ -68,6 +68,11 @@ const (
68
68
mountRotationCompleteReason = "MountRotationComplete"
69
69
k8sSecretRotationFailedReason = "SecretRotationFailed"
70
70
k8sSecretRotationCompleteReason = "SecretRotationComplete"
71
+
72
+ csipodname = "csi.storage.k8s.io/pod.name"
73
+ csipodnamespace = "csi.storage.k8s.io/pod.namespace"
74
+ csipoduid = "csi.storage.k8s.io/pod.uid"
75
+ csipodsa = "csi.storage.k8s.io/serviceAccount.name"
71
76
)
72
77
73
78
// Reconciler reconciles and rotates contents in the pod
@@ -183,14 +188,6 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *v1alpha1.SecretProvid
183
188
errorReason = internalerrors .SecretProviderClassNotFound
184
189
return fmt .Errorf ("failed to get secret provider class %s/%s, err: %+v" , spcNamespace , spcName , err )
185
190
}
186
- paramsJSON , err := json .Marshal (spc .Spec .Parameters )
187
- if err != nil {
188
- return fmt .Errorf ("failed to marshal parameters, err: %+v" , err )
189
- }
190
- permissionJSON , err := json .Marshal (permission )
191
- if err != nil {
192
- return fmt .Errorf ("failed to marshal permission, err: %+v" , err )
193
- }
194
191
// get pod from informer cache
195
192
podName , podNamespace := spcps .Status .PodName , spcps .Namespace
196
193
pod , err := r .store .GetPod (podName , podNamespace )
@@ -199,6 +196,25 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *v1alpha1.SecretProvid
199
196
return fmt .Errorf ("failed to get pod %s/%s, err: %+v" , podNamespace , podName , err )
200
197
}
201
198
199
+ parameters := make (map [string ]string )
200
+ if spc .Spec .Parameters != nil {
201
+ parameters = spc .Spec .Parameters
202
+ }
203
+ // Set these parameters to mimic the exact same attributes we get as part of NodePublishVolumeRequest
204
+ parameters [csipodname ] = podName
205
+ parameters [csipodnamespace ] = podNamespace
206
+ parameters [csipoduid ] = string (pod .UID )
207
+ parameters [csipodsa ] = pod .Spec .ServiceAccountName
208
+
209
+ paramsJSON , err := json .Marshal (parameters )
210
+ if err != nil {
211
+ return fmt .Errorf ("failed to marshal parameters, err: %+v" , err )
212
+ }
213
+ permissionJSON , err := json .Marshal (permission )
214
+ if err != nil {
215
+ return fmt .Errorf ("failed to marshal permission, err: %+v" , err )
216
+ }
217
+
202
218
// check if the volume pertaining to the current spc is using nodePublishSecretRef for
203
219
// accessing external secrets store
204
220
var nodePublishSecretRef * v1.LocalObjectReference
@@ -217,6 +233,7 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *v1alpha1.SecretProvid
217
233
}
218
234
219
235
var secretsJSON []byte
236
+ nodePublishSecretData := make (map [string ]string )
220
237
// read the Kubernetes secret referenced in NodePublishSecretRef and marshal it
221
238
// This comprises the secret parameter in the MountRequest to the provider
222
239
if nodePublishSecretRef != nil {
@@ -231,15 +248,15 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *v1alpha1.SecretProvid
231
248
return fmt .Errorf ("failed to get node publish secret %s/%s, err: %+v" , secretNamespace , secretName , err )
232
249
}
233
250
234
- nodePublishSecretData := make (map [string ]string )
235
251
for k , v := range secret .Data {
236
252
nodePublishSecretData [k ] = string (v )
237
253
}
238
- secretsJSON , err = json .Marshal (nodePublishSecretData )
239
- if err != nil {
240
- r .generateEvent (pod , v1 .EventTypeWarning , mountRotationFailedReason , fmt .Sprintf ("failed to marshal node publish secret data, err: %+v" , err ))
241
- return fmt .Errorf ("failed to marshal node publish secret data, err: %+v" , err )
242
- }
254
+ }
255
+
256
+ secretsJSON , err = json .Marshal (nodePublishSecretData )
257
+ if err != nil {
258
+ r .generateEvent (pod , v1 .EventTypeWarning , mountRotationFailedReason , fmt .Sprintf ("failed to marshal node publish secret data, err: %+v" , err ))
259
+ return fmt .Errorf ("failed to marshal node publish secret data, err: %+v" , err )
243
260
}
244
261
245
262
// generate a map with the current object versions stored in spc pod status
0 commit comments