Skip to content

Commit 13bae6b

Browse files
authored
AppWrapper configuration (#24)
Put AppWrapper configuration into a struct to be closer to conformance with ADR-0007 (struct is not yet in api package).
1 parent d5b0743 commit 13bae6b

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

cmd/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func main() {
6262
var probeAddr string
6363
var secureMetrics bool
6464
var enableHTTP2 bool
65+
66+
config := controller.AppWrapperConfig{}
67+
6568
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6669
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6770
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
@@ -71,6 +74,7 @@ func main() {
7174
"If set the metrics endpoint is served securely")
7275
flag.BoolVar(&enableHTTP2, "enable-http2", false,
7376
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
77+
flag.BoolVar(&config.ManageJobsWithoutQueueName, "manage-no-queue", true, "Manage AppWrappers without queue names")
7478
opts := zap.Options{
7579
Development: true,
7680
}
@@ -131,6 +135,7 @@ func main() {
131135
if err := controller.WorkloadReconciler(
132136
mgr.GetClient(),
133137
mgr.GetEventRecorderFor("kueue"),
138+
jobframework.WithManageJobsWithoutQueueName(config.ManageJobsWithoutQueueName),
134139
).SetupWithManager(mgr); err != nil {
135140
setupLog.Error(err, "Unable to create controller", "controller", "Workload")
136141
os.Exit(1)
@@ -139,13 +144,13 @@ func main() {
139144
if err = (&controller.AppWrapperReconciler{
140145
Client: mgr.GetClient(),
141146
Scheme: mgr.GetScheme(),
147+
Config: &config,
142148
}).SetupWithManager(mgr); err != nil {
143149
setupLog.Error(err, "unable to create controller", "controller", "AppWrapper")
144150
os.Exit(1)
145151
}
146152
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
147-
// TODO: Proper configuration of ManageJobsWithoutQueueName via config file
148-
wh := &controller.AppWrapperWebhook{ManageJobsWithoutQueueName: true}
153+
wh := &controller.AppWrapperWebhook{Config: &config}
149154
if err := ctrl.NewWebhookManagedBy(mgr).
150155
For(&workloadv1beta2.AppWrapper{}).
151156
WithDefaulter(wh).

internal/controller/appwrapper_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const (
4747
type AppWrapperReconciler struct {
4848
client.Client
4949
Scheme *runtime.Scheme
50+
Config *AppWrapperConfig
5051
}
5152

5253
type podStatusSummary struct {

internal/controller/appwrapper_webhook.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
type AppWrapperWebhook struct {
33-
ManageJobsWithoutQueueName bool
33+
Config *AppWrapperConfig
3434
}
3535

3636
//+kubebuilder:webhook:path=/mutate-workload-codeflare-dev-v1beta2-appwrapper,mutating=true,failurePolicy=fail,sideEffects=None,groups=workload.codeflare.dev,resources=appwrappers,verbs=create,versions=v1beta2,name=mappwrapper.kb.io,admissionReviewVersions=v1
@@ -41,7 +41,7 @@ var _ webhook.CustomDefaulter = &AppWrapperWebhook{}
4141
func (w *AppWrapperWebhook) Default(ctx context.Context, obj runtime.Object) error {
4242
aw := obj.(*workloadv1beta2.AppWrapper)
4343
log.FromContext(ctx).Info("Applying defaults", "job", aw)
44-
jobframework.ApplyDefaultForSuspend((*AppWrapper)(aw), w.ManageJobsWithoutQueueName)
44+
jobframework.ApplyDefaultForSuspend((*AppWrapper)(aw), w.Config.ManageJobsWithoutQueueName)
4545
return nil
4646
}
4747

@@ -56,7 +56,7 @@ func (w *AppWrapperWebhook) ValidateCreate(ctx context.Context, obj runtime.Obje
5656

5757
allErrors := w.validateAppWrapperInvariants(ctx, aw)
5858

59-
if w.ManageJobsWithoutQueueName || jobframework.QueueName((*AppWrapper)(aw)) != "" {
59+
if w.Config.ManageJobsWithoutQueueName || jobframework.QueueName((*AppWrapper)(aw)) != "" {
6060
allErrors = append(allErrors, jobframework.ValidateCreateForQueueName((*AppWrapper)(aw))...)
6161
}
6262

@@ -71,7 +71,7 @@ func (w *AppWrapperWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj r
7171

7272
allErrors := w.validateAppWrapperInvariants(ctx, newAW)
7373

74-
if w.ManageJobsWithoutQueueName || jobframework.QueueName((*AppWrapper)(newAW)) != "" {
74+
if w.Config.ManageJobsWithoutQueueName || jobframework.QueueName((*AppWrapper)(newAW)) != "" {
7575
allErrors = append(allErrors, jobframework.ValidateUpdateForQueueName((*AppWrapper)(oldAW), (*AppWrapper)(newAW))...)
7676
allErrors = append(allErrors, jobframework.ValidateUpdateForWorkloadPriorityClassName((*AppWrapper)(oldAW), (*AppWrapper)(newAW))...)
7777
}

internal/controller/confg.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2024 IBM Corporation.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
type AppWrapperConfig struct {
20+
ManageJobsWithoutQueueName bool `json:"manageJobsWithoutQueueName,omitempty"`
21+
}

0 commit comments

Comments
 (0)