Skip to content

Commit

Permalink
Merge pull request #1200 from leonardoce/remove-PVCVolumeSnapshotRefList
Browse files Browse the repository at this point in the history
Remove PVCVolumeSnapshotRefList from VolumeGroupSnapshot API
  • Loading branch information
k8s-ci-robot authored Nov 20, 2024
2 parents 9e30bb0 + 1ea7a1a commit 3c79996
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 70 deletions.
6 changes: 0 additions & 6 deletions client/apis/volumegroupsnapshot/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ type VolumeGroupSnapshotStatus struct {
// group snapshot creation. Upon success, this error field will be cleared.
// +optional
Error *snapshotv1.VolumeSnapshotError `json:"error,omitempty" protobuf:"bytes,4,opt,name=error,casttype=VolumeSnapshotError"`

// VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pairs that
// is part of this group snapshot.
// The maximum number of allowed snapshots in the group is 100.
// +optional
PVCVolumeSnapshotRefList []PVCVolumeSnapshotPair `json:"pvcVolumeSnapshotRefList,omitempty" protobuf:"bytes,5,opt,name=pvcVolumeSnapshotRefList"`
}

// PVCVolumeSnapshotPair defines a pair of a PVC reference and a Volume Snapshot Reference
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -221,41 +221,6 @@ spec:
format: date-time
type: string
type: object
pvcVolumeSnapshotRefList:
description: |-
VolumeSnapshotRefList is the list of PVC and VolumeSnapshot pairs that
is part of this group snapshot.
The maximum number of allowed snapshots in the group is 100.
items:
description: PVCVolumeSnapshotPair defines a pair of a PVC reference
and a Volume Snapshot Reference
properties:
persistentVolumeClaimRef:
description: PersistentVolumeClaimRef is a reference to the
PVC this pair is referring to
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
volumeSnapshotRef:
description: VolumeSnapshotRef is a reference to the VolumeSnapshot
this pair is referring to
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: object
type: array
readyToUse:
description: |-
ReadyToUse indicates if all the individual snapshots in the group are ready
Expand Down
24 changes: 18 additions & 6 deletions pkg/common-controller/groupsnapshot_controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(ctx context.Context,
// 2) groupSnapshot.Status.ReadyToUse is false
// 3) groupSnapshot.Status.IsBoundVolumeGroupSnapshotContentNameSet is not set
// 4) groupSnapshot.Status.IsVolumeSnapshotRefListSet is not set
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsPVCVolumeSnapshotRefListSet(groupSnapshot) {
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) {
return ctrl.syncUnreadyGroupSnapshot(ctx, groupSnapshot)
}
return ctrl.syncReadyGroupSnapshot(groupSnapshot)
Expand Down Expand Up @@ -1437,11 +1437,17 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
return nil
}

snapshotMembers, err := ctrl.snapshotLister.List(labels.SelectorFromSet(
labels.Set{
utils.VolumeGroupSnapshotNameLabel: groupSnapshot.Name,
},
))

// check if an individual snapshot belonging to the group snapshot is being
// used for restore a PVC
// If yes, do nothing and wait until PVC restoration finishes
for _, snapshotRef := range groupSnapshot.Status.PVCVolumeSnapshotRefList {
snapshot, err := ctrl.snapshotLister.VolumeSnapshots(groupSnapshot.Namespace).Get(snapshotRef.VolumeSnapshotRef.Name)
for _, snapshot := range snapshotMembers {
snapshot, err := ctrl.snapshotLister.VolumeSnapshots(groupSnapshot.Namespace).Get(snapshot.Name)
if err != nil {
if apierrs.IsNotFound(err) {
continue
Expand Down Expand Up @@ -1488,10 +1494,16 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
klog.V(5).Infof("processGroupSnapshotWithDeletionTimestamp[%s]: Delete individual snapshots that are part of the group snapshot", utils.GroupSnapshotKey(groupSnapshot))

// Delete the individual snapshots part of the group snapshot
for _, snapshot := range groupSnapshot.Status.PVCVolumeSnapshotRefList {
err := ctrl.clientset.SnapshotV1().VolumeSnapshots(groupSnapshot.Namespace).Delete(context.TODO(), snapshot.VolumeSnapshotRef.Name, metav1.DeleteOptions{})
for _, snapshot := range snapshotMembers {
err := ctrl.clientset.SnapshotV1().
VolumeSnapshots(groupSnapshot.Namespace).
Delete(context.TODO(), snapshot.Name, metav1.DeleteOptions{})
if err != nil && !apierrs.IsNotFound(err) {
msg := fmt.Sprintf("failed to delete snapshot API object %s/%s part of group snapshot %s: %v", groupSnapshot.Namespace, snapshot.VolumeSnapshotRef.Name, utils.GroupSnapshotKey(groupSnapshot), err)
msg := fmt.Sprintf(
"failed to delete snapshot API object %s/%s part of group snapshot %s: %v",
groupSnapshot.Namespace,
snapshot.Name,
utils.GroupSnapshotKey(groupSnapshot), err)
klog.Error(msg)
ctrl.eventRecorder.Event(groupSnapshot, v1.EventTypeWarning, "SnapshotDeleteError", msg)
return fmt.Errorf(msg)
Expand Down
7 changes: 0 additions & 7 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,6 @@ func IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot *crdv1alpha1.VolumeG
return true
}

func IsPVCVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool {
if groupSnapshot.Status == nil || len(groupSnapshot.Status.PVCVolumeSnapshotRefList) == 0 {
return false
}
return true
}

func IsVolumeGroupSnapshotRefSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot, content *crdv1alpha1.VolumeGroupSnapshotContent) bool {
if content.Spec.VolumeGroupSnapshotRef.Name == groupSnapshot.Name &&
content.Spec.VolumeGroupSnapshotRef.Namespace == groupSnapshot.Namespace &&
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c79996

Please sign in to comment.