Skip to content

Commit

Permalink
Pass group version as an argument while creating PVC from volume snap…
Browse files Browse the repository at this point in the history
…shot (#2295)

* add groupversion field in the args

Signed-off-by: Amruta Kale <amruta.kale@veeam.com>

* remove pointer from group version field

* add comments

Signed-off-by: Amruta Kale <amruta.kale@veeam.com>

---------

Signed-off-by: Amruta Kale <amruta.kale@veeam.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
kale-amruta and mergify[bot] committed Sep 14, 2023
1 parent dbae8b8 commit e3fadce
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/kube/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand All @@ -130,7 +132,16 @@ 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()
}

pvc := &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Labels: args.Labels,
Expand Down

0 comments on commit e3fadce

Please sign in to comment.