Skip to content

Commit

Permalink
Get dev mode (make run) working again (#232)
Browse files Browse the repository at this point in the history
When running without webhooks, apply defaults that are normally set by
the webhook during the Empty==>Suspended transition.
  • Loading branch information
dgrove-oss authored Aug 16, 2024
1 parent 8754de7 commit 8ea11e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions internal/controller/appwrapper/appwrapper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/kueue/pkg/controller/jobframework"
utilmaps "sigs.k8s.io/kueue/pkg/util/maps"

workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
wlc "github.com/project-codeflare/appwrapper/internal/controller/workload"
"github.com/project-codeflare/appwrapper/pkg/config"
"github.com/project-codeflare/appwrapper/pkg/utils"
)
Expand Down Expand Up @@ -156,13 +159,20 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)

case workloadv1beta2.AppWrapperEmpty: // initial state
if !controllerutil.ContainsFinalizer(aw, AppWrapperFinalizer) {
// When deployed normally (with webhook enabled); this block is expected to be unreachable.
// However, we need it to support `make run` (local dev of controller without the webhook).
// The AppWrapperFinalizer is added by our webhook, so if we get here it means that we are
// running in dev mode (`make run`) which disables the webhook. To make dev mode as
// useful as possible, replicate as much of AppWrapperWebhook.Default() as we can without having the admission.Request.
if r.Config.EnableKueueIntegrations {
if r.Config.DefaultQueueName != "" {
aw.Labels = utilmaps.MergeKeepFirst(aw.Labels, map[string]string{"kueue.x-k8s.io/queue-name": r.Config.DefaultQueueName})
}
jobframework.ApplyDefaultForSuspend((*wlc.AppWrapper)(aw), r.Config.KueueJobReconciller.ManageJobsWithoutQueueName)
}
controllerutil.AddFinalizer(aw, AppWrapperFinalizer)
if err := r.Update(ctx, aw); err != nil {
return ctrl.Result{}, err
}
log.FromContext(ctx).Info("Finalizer Added")
log.FromContext(ctx).Info("No webhook: applied default initializations")
}

orig := copyForStatusPatch(aw)
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/appwrapper_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (w *AppWrapperWebhook) Default(ctx context.Context, obj runtime.Object) err
if w.Config.DefaultQueueName != "" {
aw.Labels = utilmaps.MergeKeepFirst(aw.Labels, map[string]string{QueueNameLabel: w.Config.DefaultQueueName})
}
jobframework.ApplyDefaultForSuspend((*wlc.AppWrapper)(aw), true)
jobframework.ApplyDefaultForSuspend((*wlc.AppWrapper)(aw), w.Config.KueueJobReconciller.ManageJobsWithoutQueueName)
}

// inject labels with user name and id
Expand Down

0 comments on commit 8ea11e3

Please sign in to comment.