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

Add storage class during creation of PVC #203

Merged
merged 4 commits into from
Aug 14, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/kube/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ func CreatePVC(ctx context.Context, kubeCli kubernetes.Interface, ns string, nam
// PersistentVolumeClaim and any error that happened in the process.
//
// 'volumeName' is the name of the PVC that will be restored from the snapshot.
// 'storageClassName' is the name of the storage class used to create the PVC.
// 'snapshotName' is the name of the VolumeSnapshot that will be used for restoring.
// 'namespace' is the namespace of the VolumeSnapshot. The PVC will be restored to the same namepsace.
// 'restoreSize' will override existing restore size from snapshot content if provided.
func CreatePVCFromSnapshot(ctx context.Context, kubeCli kubernetes.Interface, snapCli snapshotclient.Interface, namespace, volumeName, snapshotName string, restoreSize *int) (string, error) {
func CreatePVCFromSnapshot(ctx context.Context, kubeCli kubernetes.Interface, snapCli snapshotclient.Interface, namespace, volumeName, storageClassName, snapshotName string, restoreSize *int) (string, error) {
snap, err := snapCli.VolumesnapshotV1alpha1().VolumeSnapshots(namespace).Get(snapshotName, metav1.GetOptions{})
if err != nil {
return "", err
Expand Down Expand Up @@ -123,6 +124,9 @@ func CreatePVCFromSnapshot(ctx context.Context, kubeCli kubernetes.Interface, sn
} else {
pvc.ObjectMeta.GenerateName = pvcGenerateName
}
if storageClassName != "" {
pvc.Spec.StorageClassName = &storageClassName
}

pvc, err = kubeCli.CoreV1().PersistentVolumeClaims(namespace).Create(pvc)
if err != nil {
Expand Down