Skip to content

Commit

Permalink
Add new argument to set annotations in CreatePVCFromSnapshot (#1518)
Browse files Browse the repository at this point in the history
* Add new argument to set annotations in CreatePVCFromSnapshot

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>

* Validate annotations on new PVC in unit test

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
PrasadG193 and mergify[bot] committed Jun 29, 2022
1 parent 8aa060b commit f4c178d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/kube/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func CreatePVC(ctx context.Context, kubeCli kubernetes.Interface, ns string, nam
// '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.
// 'Labels' will be added to the PVC.
// 'Annotations' will be added to the PVC.
type CreatePVCFromSnapshotArgs struct {
KubeCli kubernetes.Interface
DynCli dynamic.Interface
Expand All @@ -112,6 +113,7 @@ type CreatePVCFromSnapshotArgs struct {
SnapshotName string
RestoreSize string
Labels map[string]string
Annotations map[string]string
VolumeMode *v1.PersistentVolumeMode
AccessModes []v1.PersistentVolumeAccessMode
}
Expand All @@ -131,7 +133,8 @@ func CreatePVCFromSnapshot(ctx context.Context, args *CreatePVCFromSnapshotArgs)
snapshotAPIGroup := "snapshot.storage.k8s.io"
pvc := &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Labels: args.Labels,
Labels: args.Labels,
Annotations: args.Annotations,
},
Spec: v1.PersistentVolumeClaimSpec{
AccessModes: args.AccessModes,
Expand Down
2 changes: 2 additions & 0 deletions pkg/kube/volume/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func (s *TestVolSuite) TestCreatePVC(c *C) {
c.Assert(err, IsNil)
c.Assert(len(pvc2.Spec.AccessModes) >= 1, Equals, true)
c.Assert(*pvc2.Spec.VolumeMode, Equals, v1.PersistentVolumeBlock)
c.Assert(pvc2.GetAnnotations(), NotNil)
c.Assert(pvc2.GetAnnotations()["a1"], Equals, "foo")
}

func (s *TestVolSuite) TestGetPVCRestoreSize(c *C) {
Expand Down

0 comments on commit f4c178d

Please sign in to comment.