Skip to content

Commit 4225d73

Browse files
committed
[ws-man-mk2] Emit snapshot events
1 parent e2e1bee commit 4225d73

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

components/ws-daemon/pkg/controller/snapshot_controller.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"context"
99
"fmt"
1010

11+
corev1 "k8s.io/api/core/v1"
12+
"k8s.io/client-go/tools/record"
1113
"k8s.io/client-go/util/retry"
1214
ctrl "sigs.k8s.io/controller-runtime"
1315
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -25,14 +27,16 @@ type SnapshotReconciler struct {
2527
maxConcurrentReconciles int
2628
nodeName string
2729
operations *WorkspaceOperations
30+
recorder record.EventRecorder
2831
}
2932

30-
func NewSnapshotController(c client.Client, nodeName string, maxConcurrentReconciles int, wso *WorkspaceOperations) *SnapshotReconciler {
33+
func NewSnapshotController(c client.Client, recorder record.EventRecorder, nodeName string, maxConcurrentReconciles int, wso *WorkspaceOperations) *SnapshotReconciler {
3134
return &SnapshotReconciler{
3235
Client: c,
3336
maxConcurrentReconciles: maxConcurrentReconciles,
3437
nodeName: nodeName,
3538
operations: wso,
39+
recorder: recorder,
3640
}
3741
}
3842

@@ -124,5 +128,20 @@ func (ssc *SnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Request)
124128
log.Error(err, "could not set completion status for snapshot", "workspace", snapshot.Spec.WorkspaceID)
125129
}
126130

131+
ssc.emitEvent(&snapshot, snapshotErr)
127132
return ctrl.Result{}, err
128133
}
134+
135+
func (ssc *SnapshotReconciler) emitEvent(s *workspacev1.Snapshot, failure error) {
136+
eventType := corev1.EventTypeNormal
137+
reason := "Succeeded"
138+
message := ""
139+
140+
if failure != nil {
141+
eventType = corev1.EventTypeWarning
142+
reason = "Failed"
143+
message = failure.Error()
144+
}
145+
146+
ssc.recorder.Event(s, eventType, reason, message)
147+
}

components/ws-manager-api/go/crd/v1/snapshot_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type SnapshotStatus struct {
3030
// +kubebuilder:validation:Optional
3131
URL string `json:"url,omitempty"`
3232

33-
// Completed indicates if the snapshot operation has completed either by taking the snapshot or through failure
33+
// Completed indicates if the snapshot operation has completed either by taking the snapshot or due to failure
3434
// +kubebuilder:validation:Required
3535
Completed bool `json:"completed"`
3636
}

components/ws-manager-mk2/config/crd/bases/workspace.gitpod.io_snapshots.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ spec:
6565
properties:
6666
completed:
6767
description: Completed indicates if the snapshot operation has completed
68-
either by taking the snapshot or through failure
68+
either by taking the snapshot or due to failure
6969
type: boolean
7070
error:
7171
description: Erorr is the error observed during snapshot creation

0 commit comments

Comments
 (0)