Skip to content

[ws-manager-mk2] Check empty ns, delete secrets before finalizer #16900

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

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion components/ws-manager-api/go/crd/v1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ type WorkspaceRuntimeStatus struct {
// Columns with priority > 0 will only show up with `-o wide`.
//+kubebuilder:printcolumn:name="Workspace",type="string",JSONPath=".spec.ownership.workspaceID",priority=10
//+kubebuilder:printcolumn:name="Class",type="string",JSONPath=".spec.class"
//+kubebuilder:printcolumn:name="Type",type="string",JSONPath=".spec.type",priority=10
//+kubebuilder:printcolumn:name="Type",type="string",JSONPath=".spec.type"
//+kubebuilder:printcolumn:name="Node",type="string",JSONPath=".status.runtime.nodeName"
//+kubebuilder:printcolumn:name="Owner",type="string",JSONPath=".spec.ownership.owner"
//+kubebuilder:printcolumn:name="Team",type="string",JSONPath=".spec.ownership.team"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ spec:
type: string
- jsonPath: .spec.type
name: Type
priority: 10
type: string
- jsonPath: .status.runtime.nodeName
name: Node
Expand Down
10 changes: 5 additions & 5 deletions components/ws-manager-mk2/controllers/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (r *WorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

r.updateMetrics(ctx, &workspace)

log.V(1).Info("updated workspace status", "status", workspace.Status)
log.V(1).Info("updating workspace status", "status", workspace.Status)
err = r.Status().Update(ctx, &workspace)
if err != nil {
// log.WithValues("status", workspace).Error(err, "unable to update workspace status")
Expand Down Expand Up @@ -189,6 +189,10 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
r.metrics.rememberWorkspace(workspace, nil)

case workspace.Status.Phase == workspacev1.WorkspacePhaseStopped:
if err := r.deleteWorkspaceSecrets(ctx, workspace); err != nil {
return ctrl.Result{}, err
}

// Done stopping workspace - remove finalizer.
if controllerutil.ContainsFinalizer(workspace, workspacev1.GitpodFinalizerName) {
controllerutil.RemoveFinalizer(workspace, workspacev1.GitpodFinalizerName)
Expand All @@ -197,10 +201,6 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
}
}

if err := r.deleteWorkspaceSecrets(ctx, workspace); err != nil {
return ctrl.Result{RequeueAfter: 10 * time.Second}, err
}

// Workspace might have already been in a deleting state,
// but not guaranteed, so try deleting anyway.
err := r.Client.Delete(ctx, workspace)
Expand Down
11 changes: 11 additions & 0 deletions components/ws-manager-mk2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ func main() {
go pprof.Serve(cfg.PProf.Addr)
}

// Check that namespace config values are set. Empty namespaces default to a cluster-scoped cache,
// which the controller doesn't have the right RBAC for.
if cfg.Manager.Namespace == "" {
setupLog.Error(nil, "namespace cannot be empty")
os.Exit(1)
}
if cfg.Manager.SecretsNamespace == "" {
setupLog.Error(nil, "secretsNamespace cannot be empty")
os.Exit(1)
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: cfg.Prometheus.Addr,
Expand Down