Skip to content

Commit 0d10ba0

Browse files
committed
[ws-manager-mk2] Review comments
- Name controller - Return early in case of error - Reduce scope of permissions
1 parent cbc8c59 commit 0d10ba0

File tree

3 files changed

+6
-43
lines changed

3 files changed

+6
-43
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func NewSnapshotController(c client.Client, nodeName string, wso *WorkspaceOpera
3636
// SetupWithManager sets up the controller with the Manager.
3737
func (r *SnapshotReconciler) SetupWithManager(mgr ctrl.Manager) error {
3838
return ctrl.NewControllerManagedBy(mgr).
39+
Named("snapshot").
3940
For(&workspacev1.Snapshot{}).
4041
WithEventFilter(snapshotEventFilter(r.nodeName)).
4142
Complete(r)
@@ -64,11 +65,6 @@ func snapshotEventFilter(nodeName string) predicate.Predicate {
6465

6566
// Reconcile is part of the main kubernetes reconciliation loop which aims to
6667
// move the current state of the cluster closer to the desired state.
67-
// TODO(user): Modify the Reconcile function to compare the state specified by
68-
// the Snapshot object against the actual cluster state, and then
69-
// perform operations to make the cluster state reflect the state specified by
70-
// the user.
71-
//
7268
// For more details, check Reconcile and its Result here:
7369
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
7470
func (ssc *SnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

components/ws-manager-mk2/service/manager.go

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,11 @@ func (wsm *WorkspaceManagerServer) TakeSnapshot(ctx context.Context, req *wsmana
549549
return false, err
550550
}
551551

552-
if sso.Status.URL != "" && sso.Status.Error == "" {
552+
if sso.Status.Error != "" {
553+
return true, fmt.Errorf(sso.Status.Error)
554+
}
555+
556+
if sso.Status.URL != "" {
553557
return true, nil
554558
}
555559

@@ -641,39 +645,6 @@ func (wsm *WorkspaceManagerServer) modifyWorkspace(ctx context.Context, id strin
641645
return nil
642646
}
643647

644-
// func modifyObject[obj client.Object](ctx context.Context, client client.Client, namespace, id string, updateStatus bool, mod func(o obj) error) error {
645-
// var ws obj
646-
// err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
647-
// err := client.Get(ctx, types.NamespacedName{Namespace: namespace, Name: id}, ws)
648-
// if err != nil {
649-
// return err
650-
// }
651-
652-
// err = mod(ws)
653-
// if err != nil {
654-
// return err
655-
// }
656-
657-
// if updateStatus {
658-
// err = client.Status().Update(ctx, ws)
659-
// } else {
660-
// err = client.Update(ctx, ws)
661-
662-
// }
663-
// return err
664-
// })
665-
// if errors.IsNotFound(err) {
666-
// return status.Errorf(codes.NotFound, "%s %s not found", reflect.TypeOf(ws).String(), id)
667-
// }
668-
// if c := status.Code(err); c != codes.Unknown && c != codes.OK {
669-
// return err
670-
// }
671-
// if err != nil {
672-
// return status.Errorf(codes.Internal, "cannot modify %s: %v", reflect.TypeOf(ws).String(), err)
673-
// }
674-
// return nil
675-
// }
676-
677648
// validateStartWorkspaceRequest ensures that acting on this request will not leave the system in an invalid state
678649
func validateStartWorkspaceRequest(req *wsmanapi.StartWorkspaceRequest) error {
679650
err := validation.ValidateStruct(req.Spec,

install/installer/pkg/components/ws-manager-mk2/role.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ func role(ctx *common.RenderContext) ([]runtime.Object, error) {
7777
"delete",
7878
"get",
7979
"list",
80-
"patch",
81-
"update",
8280
"watch",
8381
},
8482
},
@@ -87,8 +85,6 @@ func role(ctx *common.RenderContext) ([]runtime.Object, error) {
8785
Resources: []string{"snapshots/status"},
8886
Verbs: []string{
8987
"get",
90-
"patch",
91-
"update",
9288
},
9389
},
9490
// ConfigMap, Leases, and Events access is required for leader-election.

0 commit comments

Comments
 (0)