Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass group version as an argument while creating PVC from volume snapshot #2295

Merged
merged 7 commits into from
Sep 14, 2023
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
kale-amruta marked this conversation as resolved.
Show resolved Hide resolved
}

// 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"
kale-amruta marked this conversation as resolved.
Show resolved Hide resolved
kale-amruta marked this conversation as resolved.
Show resolved Hide resolved
if !args.GroupVersion.Empty() {
snapshotAPIGroup = args.GroupVersion.String()
}

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