@@ -62,17 +62,21 @@ type AppWrapperWebhook struct {
62
62
63
63
var _ webhook.CustomDefaulter = & AppWrapperWebhook {}
64
64
65
- // Default ensures that Suspend is set appropriately when an AppWrapper is created
65
+ // Default fills in default values when an AppWrapper is created:
66
+ // 1. Inject default queue name
67
+ // 2. Ensure Suspend is set appropriately
68
+ // 3. Add labels with the user name and id
66
69
func (w * AppWrapperWebhook ) Default (ctx context.Context , obj runtime.Object ) error {
67
70
aw := obj .(* workloadv1beta2.AppWrapper )
68
71
log .FromContext (ctx ).Info ("Applying defaults" , "job" , aw )
72
+
73
+ // Queue name and Suspend
69
74
if w .Config .EnableKueueIntegrations {
75
+ if w .Config .QueueName != "" && aw .Annotations [QueueNameLabel ] == "" && aw .Labels [QueueNameLabel ] == "" {
76
+ aw .Labels [QueueNameLabel ] = w .Config .QueueName
77
+ }
70
78
jobframework .ApplyDefaultForSuspend ((* wlc .AppWrapper )(aw ), w .Config .ManageJobsWithoutQueueName )
71
79
}
72
- if err := inferPodSets (ctx , aw ); err != nil {
73
- log .FromContext (ctx ).Info ("Error raised during podSet inference" , "job" , aw )
74
- return err
75
- }
76
80
77
81
// inject labels with user name and id
78
82
request , err := admission .RequestFromContext (ctx )
@@ -83,11 +87,6 @@ func (w *AppWrapperWebhook) Default(ctx context.Context, obj runtime.Object) err
83
87
username := utils .SanitizeLabel (userInfo .Username )
84
88
aw .Labels = utilmaps .MergeKeepFirst (map [string ]string {AppWrapperUsernameLabel : username , AppWrapperUserIDLabel : userInfo .UID }, aw .Labels )
85
89
86
- // inject default queue name if missing from appwrapper and configured on controller
87
- if w .Config .QueueName != "" && aw .Annotations [QueueNameLabel ] == "" && aw .Labels [QueueNameLabel ] == "" {
88
- aw .Labels [QueueNameLabel ] = w .Config .QueueName
89
- }
90
-
91
90
return nil
92
91
}
93
92
@@ -124,30 +123,6 @@ func (w *AppWrapperWebhook) ValidateDelete(context.Context, runtime.Object) (adm
124
123
return nil , nil
125
124
}
126
125
127
- // inferPodSets infers the AppWrapper's PodSets
128
- func inferPodSets (_ context.Context , aw * workloadv1beta2.AppWrapper ) error {
129
- components := aw .Spec .Components
130
- componentsPath := field .NewPath ("spec" ).Child ("components" )
131
- for idx , component := range components {
132
- compPath := componentsPath .Index (idx )
133
-
134
- // Automatically create elided PodSets for known GVKs
135
- if len (component .DeclaredPodSets ) == 0 {
136
- unstruct := & unstructured.Unstructured {}
137
- _ , _ , err := unstructured .UnstructuredJSONScheme .Decode (component .Template .Raw , nil , unstruct )
138
- if err != nil {
139
- return field .Invalid (compPath .Child ("template" ), component .Template , "failed to decode as JSON" )
140
- }
141
- podSets , err := utils .InferPodSets (unstruct )
142
- if err != nil {
143
- return err
144
- }
145
- components [idx ].DeclaredPodSets = podSets
146
- }
147
- }
148
- return nil
149
- }
150
-
151
126
// rbacs required to enable SubjectAccessReview
152
127
//+kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
153
128
//+kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=list
@@ -221,25 +196,31 @@ func (w *AppWrapperWebhook) validateAppWrapperCreate(ctx context.Context, aw *wo
221
196
}
222
197
}
223
198
224
- // 4. Each PodSet.Path must specify a path within Template to a v1.PodSpecTemplate
199
+ // 4. Every DeclaredPodSet must specify a path within Template to a v1.PodSpecTemplate
225
200
podSetsPath := compPath .Child ("podSets" )
226
201
for psIdx , ps := range component .DeclaredPodSets {
227
202
podSetPath := podSetsPath .Index (psIdx )
228
203
if ps .Path == "" {
229
204
allErrors = append (allErrors , field .Required (podSetPath .Child ("path" ), "podspec must specify path" ))
230
205
}
231
206
if _ , err := utils .GetPodTemplateSpec (unstruct , ps .Path ); err != nil {
232
- allErrors = append (allErrors , field .Invalid (podSetPath .Child ("path" ), ps .Path ,
233
- fmt .Sprintf ("path does not refer to a v1.PodSpecTemplate: %v" , err )))
207
+ allErrors = append (allErrors , field .Invalid (podSetPath .Child ("path" ), ps .Path , fmt .Sprintf ("path does not refer to a v1.PodSpecTemplate: %v" , err )))
234
208
}
235
- podSpecCount += 1
236
209
}
237
210
238
211
// 5. Validate PodSets for known GVKs
239
- if err := utils .ValidatePodSets (unstruct , component .DeclaredPodSets ); err != nil {
240
- allErrors = append (allErrors , field .Invalid (podSetsPath , component .DeclaredPodSets , err .Error ()))
212
+ if inferred , err := utils .InferPodSets (unstruct ); err != nil {
213
+ allErrors = append (allErrors , field .Invalid (compPath .Child ("template" ), component .Template , fmt .Sprintf ("error inferring PodSets: %v" , err )))
214
+ } else {
215
+ if len (component .DeclaredPodSets ) > len (inferred ) {
216
+ podSpecCount += len (component .DeclaredPodSets )
217
+ } else {
218
+ podSpecCount += len (inferred )
219
+ }
220
+ if err := utils .ValidatePodSets (component .DeclaredPodSets , inferred ); err != nil {
221
+ allErrors = append (allErrors , field .Invalid (podSetsPath , component .DeclaredPodSets , err .Error ()))
222
+ }
241
223
}
242
-
243
224
}
244
225
245
226
// 6. Enforce Kueue limitation that 0 < podSpecCount <= 8
0 commit comments