From 30aa78cbfd8ec734ad341eb9d1d4a8339c481677 Mon Sep 17 00:00:00 2001 From: Amruta Kale Date: Wed, 30 Aug 2023 19:55:00 +0530 Subject: [PATCH 1/3] add groupversion field in the args Signed-off-by: Amruta Kale --- pkg/kube/volume/volume.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/kube/volume/volume.go b/pkg/kube/volume/volume.go index e63ddec8ed..750134eb80 100644 --- a/pkg/kube/volume/volume.go +++ b/pkg/kube/volume/volume.go @@ -27,6 +27,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" @@ -116,6 +117,7 @@ type CreatePVCFromSnapshotArgs struct { Annotations map[string]string VolumeMode *v1.PersistentVolumeMode AccessModes []v1.PersistentVolumeAccessMode + GroupVersion *schema.GroupVersion } // CreatePVCFromSnapshot will restore a volume and returns the resulting @@ -131,6 +133,10 @@ func CreatePVCFromSnapshot(ctx context.Context, args *CreatePVCFromSnapshotArgs) } snapshotKind := "VolumeSnapshot" snapshotAPIGroup := "snapshot.storage.k8s.io" + if args.GroupVersion != nil { + snapshotAPIGroup = args.GroupVersion.String() + } + pvc := &v1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Labels: args.Labels, From 83ea9d76eb62d864de24c988af75a17ea67ef6f7 Mon Sep 17 00:00:00 2001 From: Amruta Kale Date: Thu, 31 Aug 2023 17:36:37 +0530 Subject: [PATCH 2/3] remove pointer from group version field --- pkg/kube/volume/volume.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/kube/volume/volume.go b/pkg/kube/volume/volume.go index 750134eb80..f1a0014fee 100644 --- a/pkg/kube/volume/volume.go +++ b/pkg/kube/volume/volume.go @@ -117,7 +117,7 @@ type CreatePVCFromSnapshotArgs struct { Annotations map[string]string VolumeMode *v1.PersistentVolumeMode AccessModes []v1.PersistentVolumeAccessMode - GroupVersion *schema.GroupVersion + GroupVersion schema.GroupVersion } // CreatePVCFromSnapshot will restore a volume and returns the resulting @@ -133,7 +133,7 @@ func CreatePVCFromSnapshot(ctx context.Context, args *CreatePVCFromSnapshotArgs) } snapshotKind := "VolumeSnapshot" snapshotAPIGroup := "snapshot.storage.k8s.io" - if args.GroupVersion != nil { + if !args.GroupVersion.Empty() { snapshotAPIGroup = args.GroupVersion.String() } From e9e56bdc723073a7b26d6095463194954510038b Mon Sep 17 00:00:00 2001 From: Amruta Kale Date: Thu, 14 Sep 2023 11:09:13 +0530 Subject: [PATCH 3/3] add comments Signed-off-by: Amruta Kale --- pkg/kube/volume/volume.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/kube/volume/volume.go b/pkg/kube/volume/volume.go index f1a0014fee..be76c32739 100644 --- a/pkg/kube/volume/volume.go +++ b/pkg/kube/volume/volume.go @@ -132,6 +132,11 @@ func CreatePVCFromSnapshot(ctx context.Context, args *CreatePVCFromSnapshotArgs) args.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce} } snapshotKind := "VolumeSnapshot" + + // Group version is not specified here, it is figured out automatically + // while the PVC is being created, which can cause issues. Hence we should explicitly + // check if group api version is passed in the args, and use that + // to create the PVC snapshotAPIGroup := "snapshot.storage.k8s.io" if !args.GroupVersion.Empty() { snapshotAPIGroup = args.GroupVersion.String()