Skip to content

Commit

Permalink
Merge pull request #203 from kanisterio/sc_name
Browse files Browse the repository at this point in the history
Add storage class during creation of PVC
  • Loading branch information
pavannd1 committed Aug 14, 2019
2 parents 588e737 + ee9988d commit e7e0eea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/kube/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (s *SnapshotTestSuite) TestVolumeSnapshot(c *C) {
err = Clone(ctx, s.snapCli, snapshotName, s.sourceNamespace, snapshotCloneName, s.targetNamespace, wait)
c.Assert(err, IsNil)

_, err = volume.CreatePVCFromSnapshot(ctx, s.cli, s.snapCli, s.targetNamespace, volumeCloneName, snapshotCloneName, nil)
_, err = volume.CreatePVCFromSnapshot(ctx, s.cli, s.snapCli, s.targetNamespace, volumeCloneName, "", snapshotCloneName, nil)
c.Assert(err, IsNil)
poll.Wait(ctx, func(ctx context.Context) (bool, error) {
pvc, err = s.cli.CoreV1().PersistentVolumeClaims(s.targetNamespace).Get(volumeCloneName, metav1.GetOptions{})
Expand All @@ -266,7 +266,7 @@ func (s *SnapshotTestSuite) TestVolumeSnapshot(c *C) {
// Try with a greater restore size.
sizeNew := 2
volumeCloneName += "-2"
_, err = volume.CreatePVCFromSnapshot(ctx, s.cli, s.snapCli, s.targetNamespace, volumeCloneName, snapshotCloneName, &sizeNew)
_, err = volume.CreatePVCFromSnapshot(ctx, s.cli, s.snapCli, s.targetNamespace, volumeCloneName, "", snapshotCloneName, &sizeNew)
c.Assert(err, IsNil)
poll.Wait(ctx, func(ctx context.Context) (bool, error) {
pvc, err = s.cli.CoreV1().PersistentVolumeClaims(s.targetNamespace).Get(volumeCloneName, metav1.GetOptions{})
Expand Down
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

0 comments on commit e7e0eea

Please sign in to comment.