Skip to content

Commit

Permalink
feat: support PVC annotation template for provisioner secret
Browse files Browse the repository at this point in the history
Provisioner can resolve templated per volume secret in storage class such as following example:
`csi.storage.k8s.io/provisioner-secret-name: ${pvc.annotations['example.com/foo_secret']}`
The secret will be stored as metadata in annotations of PV, so it can find the
secret OnDelete even the PVC was deleted

Signed-off-by: hoyho <luohaihao@gmail.com>
  • Loading branch information
hoyho committed Apr 17, 2024
1 parent d981ff3 commit 0e262ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 1 addition & 6 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,7 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
}

// Resolve provision secret credentials.
provisionerSecretRef, err := getSecretReference(provisionerSecretParams, sc.Parameters, pvName, &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: claim.Name,
Namespace: claim.Namespace,
},
})
provisionerSecretRef, err := getSecretReference(provisionerSecretParams, sc.Parameters, pvName, claim)
if err != nil {
return nil, controller.ProvisioningNoChange, err
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,23 @@ func TestGetSecretReference(t *testing.T) {
},
expectErr: true,
},
"template - valid PVC annotations for Provision and Delete": {
secretParams: provisionerSecretParams,
params: map[string]string{
prefixedProvisionerSecretNamespaceKey: "static-${pvc.namespace}",
prefixedProvisionerSecretNameKey: "static-${pvc.name}-${pvc.annotations['akey']}",
},
pvName: "pvname",
pvc: &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "pvcnamespace",
Annotations: map[string]string{"akey": "avalue"},
},
},
expectErr: false,
expectRef: &v1.SecretReference{Name: "static-name-avalue", Namespace: "static-pvcnamespace"},
},
"template - valid nodepublish secret ref": {
secretParams: nodePublishSecretParams,
params: map[string]string{
Expand Down

0 comments on commit 0e262ef

Please sign in to comment.