Skip to content

Commit 44d0636

Browse files
committed
[ws-manger-mk2] Set owner reference
1 parent 2b6c37c commit 44d0636

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,7 @@ func (ssc *SnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Request)
115115
snapshot.Status.Error = fmt.Errorf("could not take snapshot: %w", snapshotErr).Error()
116116
}
117117

118-
err = ssc.Status().Update(ctx, &snapshot)
119-
if err != nil {
120-
return err
121-
}
122-
123-
return ssc.Client.Delete(ctx, &snapshot)
118+
return ssc.Status().Update(ctx, &snapshot)
124119
})
125120

126121
if err != nil {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,18 +522,21 @@ func (wsm *WorkspaceManagerServer) TakeSnapshot(ctx context.Context, req *wsmana
522522
APIVersion: workspacev1.GroupVersion.String(),
523523
Kind: "Snapshot",
524524
},
525-
526525
ObjectMeta: metav1.ObjectMeta{
527526
Name: fmt.Sprintf("%s-%d", req.Id, time.Now().UnixNano()),
528527
Namespace: wsm.Config.Namespace,
529-
Labels: map[string]string{},
530528
},
531529
Spec: workspacev1.SnapshotSpec{
532530
NodeName: ws.Status.Runtime.NodeName,
533531
WorkspaceID: ws.Name,
534532
},
535533
}
536534

535+
err = controllerutil.SetOwnerReference(&ws, &snapshot, wsm.Client.Scheme())
536+
if err != nil {
537+
return nil, status.Errorf(codes.Internal, "cannot set owner for snapshot: %q", err)
538+
}
539+
537540
err = wsm.Client.Create(ctx, &snapshot)
538541
if err != nil {
539542
return nil, status.Errorf(codes.Internal, "cannot create snapshot object: %q", err)
@@ -580,8 +583,6 @@ func (wsm *WorkspaceManagerServer) TakeSnapshot(ctx context.Context, req *wsmana
580583
}
581584
}
582585

583-
log.Info("return url")
584-
585586
return &wsmanapi.TakeSnapshotResponse{
586587
Url: sso.Status.URL,
587588
}, nil

0 commit comments

Comments
 (0)