Skip to content

Commit

Permalink
WIP: fake rejection
Browse files Browse the repository at this point in the history
TODO:
 - find out if it really works by looking at logs (seems to fast atm)
- also, fix the broken "ns-psp:unprivileged" references
  • Loading branch information
geropl committed Oct 2, 2024
1 parent 2f09f8c commit 2a35e06
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions components/ws-manager-mk2/controllers/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package controllers
import (
"context"
"fmt"
"slices"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -290,6 +291,23 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
}
pod := &workspacePods.Items[0]

marker := slices.ContainsFunc(workspace.Spec.UserEnvVars, func(e corev1.EnvVar) bool {
return e.Name == "GITPOD_WORKSPACE_CONTEXT_URL" && strings.Contains(e.Value, "geropl")
})
if workspace.Status.PodRecreated == 0 && marker && (workspace.Status.Phase == workspacev1.WorkspacePhasePending || workspace.Status.Phase == workspacev1.WorkspacePhaseCreating) {
patch := client.MergeFrom(pod.DeepCopy())
pod.Status.Phase = corev1.PodFailed
pod.Status.Reason = "NodeAffinity"
pod.Status.Message = "Pod was rejected"

log.WithValues("ws", workspace.Name).Info("REJECTING POD FOR TESTING")
err = r.Client.Status().Patch(ctx, pod, patch)
if err != nil {
log.WithValues("ws", workspace.Name).Error(err, "REJECTING POD FOR TESTING: error while patching workspace pod")
}
return ctrl.Result{Requeue: true, RequeueAfter: 5 * time.Second}, nil
}

switch {
// if there is a pod, and it's failed, delete it
case workspace.IsConditionTrue(workspacev1.WorkspaceConditionFailed) && !isPodBeingDeleted(pod):
Expand Down

0 comments on commit 2a35e06

Please sign in to comment.