Skip to content

Commit a2ab92d

Browse files
authored
Merge pull request #1048 from Madhu-1/fix-group-snapshot-secret-bug
Use group specific annotation for the group secrets
2 parents fa9de9c + 30b24e6 commit a2ab92d

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

pkg/common-controller/groupsnapshot_controller_helper.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,11 @@ func (ctrl *csiSnapshotCommonController) createGroupSnapshotContent(groupSnapsho
776776
Add secret reference details
777777
*/
778778
if snapshotterSecretRef != nil {
779-
klog.V(5).Infof("createGroupSnapshotContent: set annotation [%s] on volume group snapshot content [%s].", utils.AnnDeletionSecretRefName, groupSnapshotContent.Name)
780-
metav1.SetMetaDataAnnotation(&groupSnapshotContent.ObjectMeta, utils.AnnDeletionSecretRefName, snapshotterSecretRef.Name)
779+
klog.V(5).Infof("createGroupSnapshotContent: set annotation [%s] on volume group snapshot content [%s].", utils.AnnDeletionGroupSecretRefName, groupSnapshotContent.Name)
780+
metav1.SetMetaDataAnnotation(&groupSnapshotContent.ObjectMeta, utils.AnnDeletionGroupSecretRefName, snapshotterSecretRef.Name)
781781

782-
klog.V(5).Infof("creategroupSnapshotContent: set annotation [%s] on volume group snapshot content [%s].", utils.AnnDeletionSecretRefNamespace, groupSnapshotContent.Name)
783-
metav1.SetMetaDataAnnotation(&groupSnapshotContent.ObjectMeta, utils.AnnDeletionSecretRefNamespace, snapshotterSecretRef.Namespace)
782+
klog.V(5).Infof("creategroupSnapshotContent: set annotation [%s] on volume group snapshot content [%s].", utils.AnnDeletionGroupSecretRefNamespace, groupSnapshotContent.Name)
783+
metav1.SetMetaDataAnnotation(&groupSnapshotContent.ObjectMeta, utils.AnnDeletionGroupSecretRefNamespace, snapshotterSecretRef.Namespace)
784784
}
785785

786786
var updateGroupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent
@@ -843,7 +843,7 @@ func (ctrl *csiSnapshotCommonController) getCreateGroupSnapshotInput(groupSnapsh
843843
contentName := utils.GetDynamicSnapshotContentNameForGroupSnapshot(groupSnapshot)
844844

845845
// Get the secret reference
846-
snapshotterSecretRef, err := utils.GetGroupSnapshotSecretReference(utils.SnapshotterSecretParams, groupSnapshotClass.Parameters, contentName, groupSnapshot)
846+
snapshotterSecretRef, err := utils.GetGroupSnapshotSecretReference(utils.GroupSnapshotterSecretParams, groupSnapshotClass.Parameters, contentName, groupSnapshot)
847847
if err != nil {
848848
return nil, nil, "", nil, err
849849
}

pkg/sidecar-controller/groupsnapshot_helper.go

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ func (ctrl *csiSnapshotSideCarController) GetCredentialsFromAnnotationForGroupSn
297297
var err error
298298

299299
// Check if annotation exists
300-
if metav1.HasAnnotation(groupSnapshotContent.ObjectMeta, utils.AnnDeletionSecretRefName) && metav1.HasAnnotation(groupSnapshotContent.ObjectMeta, utils.AnnDeletionSecretRefNamespace) {
301-
annDeletionSecretName := groupSnapshotContent.Annotations[utils.AnnDeletionSecretRefName]
302-
annDeletionSecretNamespace := groupSnapshotContent.Annotations[utils.AnnDeletionSecretRefNamespace]
300+
if metav1.HasAnnotation(groupSnapshotContent.ObjectMeta, utils.AnnDeletionGroupSecretRefName) && metav1.HasAnnotation(groupSnapshotContent.ObjectMeta, utils.AnnDeletionGroupSecretRefNamespace) {
301+
annDeletionSecretName := groupSnapshotContent.Annotations[utils.AnnDeletionGroupSecretRefName]
302+
annDeletionSecretNamespace := groupSnapshotContent.Annotations[utils.AnnDeletionGroupSecretRefNamespace]
303303

304304
snapshotterSecretRef := &v1.SecretReference{}
305305

@@ -423,7 +423,7 @@ func (ctrl *csiSnapshotSideCarController) createGroupSnapshotWrapper(groupSnapsh
423423
creationTime = time.Now()
424424
}
425425

426-
groupSnapshotSecret, err := utils.GetSecretReference(utils.GroupSnapshotterSecretParams, class.Parameters, groupSnapshotContent.GetObjectMeta().GetName(), nil)
426+
groupSnapshotSecret, err := utils.GetGroupSnapshotSecretReference(utils.GroupSnapshotterSecretParams, class.Parameters, groupSnapshotContent.GetObjectMeta().GetName(), nil)
427427
if err != nil {
428428
klog.Errorf("Failed to get secret reference for group snapshot content %s: %v", groupSnapshotContent.Name, err)
429429
return groupSnapshotContent, fmt.Errorf("failed to get secret reference for group snapshot content %s: %v", groupSnapshotContent.Name, err)
@@ -535,7 +535,7 @@ func (ctrl *csiSnapshotSideCarController) getCSIGroupSnapshotInput(groupSnapshot
535535
}
536536

537537
// Resolve snapshotting secret credentials.
538-
snapshotterCredentials, err := ctrl.GetGroupCredentialsFromAnnotation(groupSnapshotContent)
538+
snapshotterCredentials, err := ctrl.GetCredentialsFromAnnotationForGroupSnapshot(groupSnapshotContent)
539539
if err != nil {
540540
return nil, nil, err
541541
}
@@ -847,32 +847,3 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateGroupSnapshotContentStat
847847
}
848848
return ctrl.createGroupSnapshotWrapper(groupSnapshotContent)
849849
}
850-
851-
func (ctrl *csiSnapshotSideCarController) GetGroupCredentialsFromAnnotation(content *crdv1alpha1.VolumeGroupSnapshotContent) (map[string]string, error) {
852-
var groupSnapshotterCredentials map[string]string
853-
var err error
854-
855-
// Check if annotation exists
856-
if metav1.HasAnnotation(content.ObjectMeta, utils.AnnDeletionSecretRefName) && metav1.HasAnnotation(content.ObjectMeta, utils.AnnDeletionSecretRefNamespace) {
857-
annDeletionSecretName := content.Annotations[utils.AnnDeletionSecretRefName]
858-
annDeletionSecretNamespace := content.Annotations[utils.AnnDeletionSecretRefNamespace]
859-
860-
groupSnapshotterSecretRef := &v1.SecretReference{}
861-
862-
if annDeletionSecretName == "" || annDeletionSecretNamespace == "" {
863-
return nil, fmt.Errorf("cannot retrieve secrets for volume group snapshot content %#v, err: secret name or namespace not specified", content.Name)
864-
}
865-
866-
groupSnapshotterSecretRef.Name = annDeletionSecretName
867-
groupSnapshotterSecretRef.Namespace = annDeletionSecretNamespace
868-
869-
groupSnapshotterCredentials, err = utils.GetCredentials(ctrl.client, groupSnapshotterSecretRef)
870-
if err != nil {
871-
// Continue with deletion, as the secret may have already been deleted.
872-
klog.Errorf("Failed to get credentials for snapshot %s: %s", content.Name, err.Error())
873-
return nil, fmt.Errorf("cannot get credentials for snapshot content %#v", content.Name)
874-
}
875-
}
876-
877-
return groupSnapshotterCredentials, nil
878-
}

pkg/utils/util.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ const (
137137
AnnDeletionSecretRefName = "snapshot.storage.kubernetes.io/deletion-secret-name"
138138
AnnDeletionSecretRefNamespace = "snapshot.storage.kubernetes.io/deletion-secret-namespace"
139139

140+
// Annotation for secret name and namespace will be added to the group
141+
// snapshot content and used at group snapshot content deletion time.
142+
AnnDeletionGroupSecretRefName = "groupsnapshot.storage.kubernetes.io/deletion-secret-name"
143+
AnnDeletionGroupSecretRefNamespace = "groupsnapshot.storage.kubernetes.io/deletion-secret-namespace"
144+
140145
// VolumeSnapshotContentInvalidLabel is applied to invalid content as a label key. The value does not matter.
141146
// See https://github.com/kubernetes/enhancements/blob/master/keps/sig-storage/177-volume-snapshot/tighten-validation-webhook-crd.md#automatic-labelling-of-invalid-objects
142147
VolumeSnapshotContentInvalidLabel = "snapshot.storage.kubernetes.io/invalid-snapshot-content-resource"
@@ -553,6 +558,8 @@ func RemovePrefixedParameters(param map[string]string) (map[string]string, error
553558
case PrefixedSnapshotterSecretNamespaceKey:
554559
case PrefixedSnapshotterListSecretNameKey:
555560
case PrefixedSnapshotterListSecretNamespaceKey:
561+
case PrefixedGroupSnapshotterSecretNameKey:
562+
case PrefixedGroupSnapshotterSecretNamespaceKey:
556563
default:
557564
return map[string]string{}, fmt.Errorf("found unknown parameter key \"%s\" with reserved namespace %s", k, csiParameterPrefix)
558565
}

0 commit comments

Comments
 (0)