From df91671058e913db56683b6237c9952850656e85 Mon Sep 17 00:00:00 2001 From: JenTing Hsiao Date: Thu, 15 Sep 2022 21:54:04 +0800 Subject: [PATCH] Add workspapce ID annotation to VolumeSnapshot object for filter event Signed-off-by: JenTing Hsiao --- components/ws-manager/pkg/manager/manager.go | 5 +++-- components/ws-manager/pkg/manager/monitor.go | 7 ++++--- .../ws-manager/pkg/manager/volume_snapshot_controller.go | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/ws-manager/pkg/manager/manager.go b/components/ws-manager/pkg/manager/manager.go index 0637a1767bdd25..80f81114445116 100644 --- a/components/ws-manager/pkg/manager/manager.go +++ b/components/ws-manager/pkg/manager/manager.go @@ -453,8 +453,9 @@ func (m *Manager) restoreVolumeSnapshotFromHandle(ctx context.Context, id, handl snapshotContentName := "restored-" + id volumeSnapshot := &volumesnapshotv1.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ - Name: id, - Namespace: m.Config.Namespace, + Name: id, + Namespace: m.Config.Namespace, + Annotations: map[string]string{workspaceIDAnnotation: id}, }, Spec: volumesnapshotv1.VolumeSnapshotSpec{ Source: volumesnapshotv1.VolumeSnapshotSource{ diff --git a/components/ws-manager/pkg/manager/monitor.go b/components/ws-manager/pkg/manager/monitor.go index dfd9691c182df0..45714cdecf009e 100644 --- a/components/ws-manager/pkg/manager/monitor.go +++ b/components/ws-manager/pkg/manager/monitor.go @@ -1128,9 +1128,10 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb // create snapshot object out of PVC volumeSnapshot := &volumesnapshotv1.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{ - Name: pvcVolumeSnapshotName, - Namespace: m.manager.Config.Namespace, - Labels: wso.Pod.Labels, + Name: pvcVolumeSnapshotName, + Namespace: m.manager.Config.Namespace, + Annotations: map[string]string{workspaceIDAnnotation: workspaceID}, + Labels: wso.Pod.Labels, }, Spec: volumesnapshotv1.VolumeSnapshotSpec{ Source: volumesnapshotv1.VolumeSnapshotSource{ diff --git a/components/ws-manager/pkg/manager/volume_snapshot_controller.go b/components/ws-manager/pkg/manager/volume_snapshot_controller.go index 2cd5cab463fae7..b512d5667274e5 100644 --- a/components/ws-manager/pkg/manager/volume_snapshot_controller.go +++ b/components/ws-manager/pkg/manager/volume_snapshot_controller.go @@ -37,6 +37,11 @@ func (r *VolumeSnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Reque return reconcile.Result{}, nil } + queue := vs.Annotations[workspaceIDAnnotation] + if queue == "" { + return ctrl.Result{}, nil + } + r.Monitor.eventpool.Add(vs.Name, watch.Event{ Type: watch.Modified, Object: &vs,