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

Support annotation in VolumeSnapshot and VolumeSnapshotContent resources #2986

Merged
merged 28 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4bc7da9
WIP
saima-s Jul 17, 2024
43c1170
fix test and support annotation
saima-s Jul 17, 2024
dac2180
Add test for annotation support
saima-s Jul 23, 2024
42fe44a
Removed annotation support from kanister functions
saima-s Jul 23, 2024
98e0ef1
Removed annotation support from test
saima-s Jul 23, 2024
c3865d5
added logs
saima-s Jul 25, 2024
679a7ca
removed logs and fix linter issue
saima-s Jul 25, 2024
fae441e
Merge branch 'master' into orange/saima/support-snapshot-annotation
saima-s Jul 25, 2024
2b9fe1c
add comment on method definition
saima-s Jul 25, 2024
e49bb8f
Merge remote-tracking branch 'origin/orange/saima/support-snapshot-an…
saima-s Jul 25, 2024
8f8efcf
update test comment
saima-s Jul 25, 2024
c5f136d
Merge branch 'master' into orange/saima/support-snapshot-annotation
saima-s Jul 25, 2024
216a9ef
Fixed review comments
saima-s Jul 26, 2024
e03ba27
Fixed review comment with new struct
saima-s Jul 30, 2024
a3b15cc
Renamed struct
saima-s Jul 30, 2024
e1de82f
Renamed unused fields
saima-s Jul 30, 2024
3de7196
fix linter goimport and added comments to functions.
saima-s Jul 30, 2024
5ed6db4
fix review comment
saima-s Jul 30, 2024
20f8818
add release notes and fix review comments
saima-s Aug 1, 2024
043d6a6
fix review comment
saima-s Aug 1, 2024
0a455e9
fix review comments
saima-s Aug 1, 2024
b27193d
Merge branch 'master' into orange/saima/support-snapshot-annotation
saima-s Aug 2, 2024
cbbe269
fix review comments for fixing comments
saima-s Aug 2, 2024
39a1f2f
fix release notes
saima-s Aug 2, 2024
1d6e2e3
Update pkg/kube/snapshot/types.go
saima-s Aug 5, 2024
3d62652
Merge branch 'master' into orange/saima/support-snapshot-annotation
saima-s Aug 5, 2024
a4f271e
fix review comment on test
saima-s Aug 5, 2024
1dc0df3
Merge branch 'master' into orange/saima/support-snapshot-annotation
saima-s Aug 5, 2024
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
3 changes: 2 additions & 1 deletion pkg/function/create_csi_snapshot_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ func createCSISnapshotStatic(
Name: name,
Namespace: namespace,
}
if err := snapshotter.CreateFromSource(ctx, source, wait, snapshotMeta, snapshot.ObjectMeta{}); err != nil {
snapshotContentMeta := snapshot.ObjectMeta{}
if err := snapshotter.CreateFromSource(ctx, source, wait, snapshotMeta, snapshotContentMeta); err != nil {
return nil, err
}

Expand Down
8 changes: 2 additions & 6 deletions pkg/function/delete_csi_snapshot_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,11 @@ func (testSuite *DeleteCSISnapshotContentTestSuite) TestDeleteCSISnapshotContent
Driver: driver,
VolumeSnapshotClassName: snapshotClassName,
}
fakeSnapshotMeta := snapshot.ObjectMeta{
Name: snapshotName,
Namespace: snapshotNamespace,
}
fakeSnapshotContentMeta := snapshot.ObjectMeta{
Name: snapshotContentName,
}
err = fakeSnapshotter.CreateContentFromSource(ctx, source,
deletionPolicy, fakeSnapshotMeta, fakeSnapshotContentMeta)
err = fakeSnapshotter.CreateContentFromSource(ctx, source, snapshotName,
snapshotNamespace, deletionPolicy, fakeSnapshotContentMeta)
c.Assert(err, IsNil)

gv := strings.Split(api.GroupVersion, "/")
Expand Down
19 changes: 9 additions & 10 deletions pkg/kube/snapshot/mocks/mock_snapshotter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/kube/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ type Snapshotter interface {
// 'name' is the name of the VolumeSnapshot that will be cloned.
// 'namespace' is the namespace of the VolumeSnapshot that will be cloned.
// 'waitForReady' will make the function blocks until the clone's status is ready to use.
// 'cloneSnapshotMeta' has metadata of the VolumeSnapshot resource that is going to get created.
// 'snapshotMeta' has metadata of the VolumeSnapshot resource that is going to get created.
// 'snapshotContentMeta' has metadata of the VolumeSnapshotContent content resource that is going to get created.
Clone(ctx context.Context, name, namespace string, waitForReady bool, cloneSnapshotMeta, snapshotContentMeta ObjectMeta) error
Clone(ctx context.Context, name, namespace string, waitForReady bool, snapshotMeta, snapshotContentMeta ObjectMeta) error
// GetSource will return the CSI source that backs the volume snapshot.
//
// 'snapshotName' is the name of the VolumeSnapshot.
Expand All @@ -104,7 +104,7 @@ type Snapshotter interface {
// 'deletionPolicy' is the deletion policy to set on the created VSC
// 'snapshotMeta' has metadata of the VolumeSnapshot resource that is source reference for VSC created.
saima-s marked this conversation as resolved.
Show resolved Hide resolved
// 'snapshotContentMeta' has metadata of the VolumeSnapshotContent resource that is going to get created.
CreateContentFromSource(ctx context.Context, source *Source, deletionPolicy string, snapshotMeta, snapshotContentMeta ObjectMeta) error
CreateContentFromSource(ctx context.Context, source *Source, snapshotName, namespace, deletionPolicy string, snapshotContentMeta ObjectMeta) error
// WaitOnReadyToUse will block until the VolumeSnapshot in namespace 'namespace' with name 'snapshotName'
// has status 'ReadyToUse' or 'ctx.Done()' is signalled.
WaitOnReadyToUse(ctx context.Context, snapshotName, namespace string) error
Expand Down
25 changes: 14 additions & 11 deletions pkg/kube/snapshot/snapshot_alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,20 @@ func (sna *SnapshotAlpha) DeleteContent(ctx context.Context, name string) error

// Clone will clone the VolumeSnapshot to namespace 'cloneNamespace'.
// Underlying VolumeSnapshotContent will be cloned with a different name.
func (sna *SnapshotAlpha) Clone(ctx context.Context, name, namespace string, waitForReady bool, cloneSnapshotMeta, snapshotContentMeta ObjectMeta) error {
_, err := sna.Get(ctx, cloneSnapshotMeta.Name, cloneSnapshotMeta.Namespace)
func (sna *SnapshotAlpha) Clone(ctx context.Context, name, namespace string, waitForReady bool, snapshotMeta, snapshotContentMeta ObjectMeta) error {
_, err := sna.Get(ctx, snapshotMeta.Name, snapshotMeta.Namespace)
if err == nil {
return errkit.New("Target snapshot already exists in target namespace", "name", cloneSnapshotMeta.Name, "namespace", cloneSnapshotMeta.Namespace)
return errkit.New("Target snapshot already exists in target namespace", "name", snapshotMeta.Name, "namespace", snapshotMeta.Namespace)
}
if !apierrors.IsNotFound(err) {
return errkit.Wrap(err, "Failed to query target Volumesnapshot", "name", cloneSnapshotMeta.Name, "namespace", cloneSnapshotMeta.Namespace)
return errkit.Wrap(err, "Failed to query target Volumesnapshot", "name", snapshotMeta.Name, "namespace", snapshotMeta.Namespace)
}

src, err := sna.GetSource(ctx, name, namespace)
if err != nil {
return errkit.Wrap(err, "Failed to get source")
}
return sna.CreateFromSource(ctx, src, waitForReady, cloneSnapshotMeta, snapshotContentMeta)
return sna.CreateFromSource(ctx, src, waitForReady, snapshotMeta, snapshotContentMeta)
}

// GetSource will return the CSI source that backs the volume snapshot.
Expand Down Expand Up @@ -268,7 +268,7 @@ func (sna *SnapshotAlpha) CreateFromSource(ctx context.Context, source *Source,
snapshotContentMeta.Name = snapshotMeta.Name + "-content-" + string(uuid.NewUUID())
snapshotMeta.Labels = blockstorage.SanitizeTags(snapshotMeta.Labels)
snap := UnstructuredVolumeSnapshotAlpha("", source.VolumeSnapshotClassName, snapshotMeta, snapshotContentMeta)
if err := sna.CreateContentFromSource(ctx, source, deletionPolicy, snapshotMeta, snapshotContentMeta); err != nil {
if err := sna.CreateContentFromSource(ctx, source, snapshotMeta.Name, snapshotMeta.Namespace, deletionPolicy, snapshotContentMeta); err != nil {
return err
}
if _, err := sna.dynCli.Resource(v1alpha1.VolSnapGVR).Namespace(snapshotMeta.Namespace).Create(ctx, snap, metav1.CreateOptions{}); err != nil {
Expand Down Expand Up @@ -299,8 +299,8 @@ func (sna *SnapshotAlpha) UpdateVolumeSnapshotStatusAlpha(ctx context.Context, n
}

// CreateContentFromSource will create a 'VolumesnaphotContent' for the underlying snapshot source.
func (sna *SnapshotAlpha) CreateContentFromSource(ctx context.Context, source *Source, deletionPolicy string, snapshotMeta, snapshotContentMeta ObjectMeta) error {
content := UnstructuredVolumeSnapshotContentAlpha(deletionPolicy, source.Driver, source.Handle, source.VolumeSnapshotClassName, snapshotMeta, snapshotContentMeta)
func (sna *SnapshotAlpha) CreateContentFromSource(ctx context.Context, source *Source, snapshotName, namespace, deletionPolicy string, snapshotContentMeta ObjectMeta) error {
content := UnstructuredVolumeSnapshotContentAlpha(snapshotName, namespace, deletionPolicy, source.Driver, source.Handle, source.VolumeSnapshotClassName, snapshotContentMeta)
if _, err := sna.dynCli.Resource(v1alpha1.VolSnapContentGVR).Create(ctx, content, metav1.CreateOptions{}); err != nil {
return errkit.Wrap(err, "Failed to create content", "contentName", content.GetName())
}
Expand Down Expand Up @@ -395,7 +395,7 @@ func UnstructuredVolumeSnapshotAlpha(pvcName, snapClassName string, snapshotMeta
}

// UnstructuredVolumeSnapshotContentAlpha returns Unstructured object for the VolumeSnapshotContent resource.
func UnstructuredVolumeSnapshotContentAlpha(deletionPolicy, driver, handle, snapClassName string, snapshotMeta, snapshotContentMeta ObjectMeta) *unstructured.Unstructured {
func UnstructuredVolumeSnapshotContentAlpha(snapshotName, snapshotNs, deletionPolicy, driver, handle, snapClassName string, snapshotContentMeta ObjectMeta) *unstructured.Unstructured {
saima-s marked this conversation as resolved.
Show resolved Hide resolved
snaphotContent := unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": fmt.Sprintf("%s/%s", v1alpha1.GroupName, v1alpha1.Version),
Expand All @@ -410,14 +410,17 @@ func UnstructuredVolumeSnapshotContentAlpha(deletionPolicy, driver, handle, snap
},
"volumeSnapshotRef": map[string]interface{}{
"kind": VolSnapKind,
"name": snapshotMeta.Name,
"namespace": snapshotMeta.Namespace,
"name": snapshotName,
"namespace": snapshotNs,
},
"snapshotClassName": snapClassName,
"deletionPolicy": deletionPolicy,
},
},
}
if snapshotContentMeta.Labels != nil {
snaphotContent.SetLabels(snapshotContentMeta.Labels)
}
if snapshotContentMeta.Annotations != nil {
snaphotContent.SetAnnotations(snapshotContentMeta.Annotations)
}
Expand Down
30 changes: 17 additions & 13 deletions pkg/kube/snapshot/snapshot_beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func createSnapshot(
return errkit.Wrap(err, "Failed to query PVC", "pvc", volumeName, "namespace", snapshotMeta.Namespace)
}
snapshotMeta.Labels = blockstorage.SanitizeTags(snapshotMeta.Labels)
snap := UnstructuredVolumeSnapshot(snapGVR, volumeName, *snapshotClass, snapshotMeta, ObjectMeta{})
snapshotContentMeta := ObjectMeta{}
snap := UnstructuredVolumeSnapshot(snapGVR, volumeName, *snapshotClass, snapshotMeta, snapshotContentMeta)
if _, err := dynCli.Resource(snapGVR).Namespace(snapshotMeta.Namespace).Create(ctx, snap, metav1.CreateOptions{}); err != nil {
return errkit.Wrap(err, "Failed to create snapshot resource", "name", snapshotMeta.Name, "namespace", snapshotMeta.Namespace)
}
Expand Down Expand Up @@ -187,22 +188,22 @@ func (sna *SnapshotBeta) DeleteContent(ctx context.Context, name string) error {
return nil
}

// Clone will clone the VolumeSnapshot to namespace 'cloneNamespace'.
// Clone will clone the VolumeSnapshot to namespace 'snapshotMeta.Namespace'.
// Underlying VolumeSnapshotContent will be cloned with a different name.
func (sna *SnapshotBeta) Clone(ctx context.Context, name, namespace string, waitForReady bool, cloneSnapshotMeta, snapshotContentMeta ObjectMeta) error {
_, err := sna.Get(ctx, cloneSnapshotMeta.Name, cloneSnapshotMeta.Namespace)
func (sna *SnapshotBeta) Clone(ctx context.Context, name, namespace string, waitForReady bool, snapshotMeta, snapshotContentMeta ObjectMeta) error {
_, err := sna.Get(ctx, snapshotMeta.Name, snapshotMeta.Namespace)
if err == nil {
return errkit.New("Target snapshot already exists in target namespace", "volumeSnapshot", cloneSnapshotMeta.Name, "namespace", cloneSnapshotMeta.Namespace)
return errkit.New("Target snapshot already exists in target namespace", "volumeSnapshot", snapshotMeta.Name, "namespace", snapshotMeta.Namespace)
}
if !apierrors.IsNotFound(err) {
return errkit.Wrap(err, "Failed to query target Volumesnapshot", "volumeSnapshot", cloneSnapshotMeta.Name, "namespace", cloneSnapshotMeta.Namespace)
return errkit.Wrap(err, "Failed to query target Volumesnapshot", "volumeSnapshot", snapshotMeta.Name, "namespace", snapshotMeta.Namespace)
}

src, err := sna.GetSource(ctx, name, namespace)
if err != nil {
return errkit.New("Failed to get source")
}
return sna.CreateFromSource(ctx, src, waitForReady, cloneSnapshotMeta, snapshotContentMeta)
return sna.CreateFromSource(ctx, src, waitForReady, snapshotMeta, snapshotContentMeta)
}

// GetSource will return the CSI source that backs the volume snapshot.
Expand Down Expand Up @@ -245,7 +246,7 @@ func (sna *SnapshotBeta) CreateFromSource(ctx context.Context, source *Source, w
snapshotContentMeta.Name = snapshotMeta.Name + "-content-" + string(uuid.NewUUID())
snapshotMeta.Labels = blockstorage.SanitizeTags(snapshotMeta.Labels)
snap := UnstructuredVolumeSnapshot(v1beta1.VolSnapGVR, "", source.VolumeSnapshotClassName, snapshotMeta, snapshotContentMeta)
if err := sna.CreateContentFromSource(ctx, source, deletionPolicy, snapshotMeta, snapshotContentMeta); err != nil {
if err := sna.CreateContentFromSource(ctx, source, snapshotMeta.Name, snapshotMeta.Namespace, deletionPolicy, snapshotContentMeta); err != nil {
return err
}
if _, err := sna.dynCli.Resource(v1beta1.VolSnapGVR).Namespace(snapshotMeta.Namespace).Create(ctx, snap, metav1.CreateOptions{}); err != nil {
Expand Down Expand Up @@ -288,8 +289,8 @@ func updateVolumeSnapshotStatus(ctx context.Context, dynCli dynamic.Interface, s
}

// CreateContentFromSource will create a 'VolumesnaphotContent' for the underlying snapshot source.
func (sna *SnapshotBeta) CreateContentFromSource(ctx context.Context, source *Source, deletionPolicy string, snapshotMeta, snapshotContentMeta ObjectMeta) error {
content := UnstructuredVolumeSnapshotContent(v1beta1.VolSnapContentGVR, deletionPolicy, source.Driver, source.Handle, source.VolumeSnapshotClassName, snapshotMeta, snapshotContentMeta)
func (sna *SnapshotBeta) CreateContentFromSource(ctx context.Context, source *Source, snapshotName, namespace, deletionPolicy string, snapshotContentMeta ObjectMeta) error {
content := UnstructuredVolumeSnapshotContent(v1beta1.VolSnapContentGVR, snapshotName, namespace, deletionPolicy, source.Driver, source.Handle, source.VolumeSnapshotClassName, snapshotContentMeta)
if _, err := sna.dynCli.Resource(v1beta1.VolSnapContentGVR).Create(ctx, content, metav1.CreateOptions{}); err != nil {
return errkit.Wrap(err, "Failed to create content", "volumeSnapshotContent", content.GetName())
}
Expand Down Expand Up @@ -380,7 +381,7 @@ func UnstructuredVolumeSnapshot(gvr schema.GroupVersionResource, pvcName, snapCl
}

// UnstructuredVolumeSnapshotContent returns Unstructured object for the VolumeSnapshotContent resource.
func UnstructuredVolumeSnapshotContent(gvr schema.GroupVersionResource, deletionPolicy, driver, handle, snapClassName string, snapshotMeta, snapshotContentMeta ObjectMeta) *unstructured.Unstructured {
func UnstructuredVolumeSnapshotContent(gvr schema.GroupVersionResource, snapshotName, snapshotNs, deletionPolicy, driver, handle, snapClassName string, snapshotContentMeta ObjectMeta) *unstructured.Unstructured {
snapshotContent := unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": fmt.Sprintf("%s/%s", gvr.Group, gvr.Version),
Expand All @@ -391,8 +392,8 @@ func UnstructuredVolumeSnapshotContent(gvr schema.GroupVersionResource, deletion
"spec": map[string]interface{}{
"volumeSnapshotRef": map[string]interface{}{
"kind": VolSnapKind,
"name": snapshotMeta.Name,
"namespace": snapshotMeta.Namespace,
"name": snapshotName,
"namespace": snapshotNs,
},
"deletionPolicy": deletionPolicy,
"driver": driver,
Expand All @@ -403,6 +404,9 @@ func UnstructuredVolumeSnapshotContent(gvr schema.GroupVersionResource, deletion
},
},
}
if snapshotContentMeta.Labels != nil {
snapshotContent.SetLabels(snapshotContentMeta.Labels)
}
if snapshotContentMeta.Annotations != nil {
snapshotContent.SetAnnotations(snapshotContentMeta.Annotations)
}
saima-s marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading