Skip to content
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

Get dev mode (make run) working again #232

Merged
merged 1 commit into from
Aug 16, 2024
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
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