@@ -22,7 +22,8 @@ import (
22
22
"fmt"
23
23
"time"
24
24
25
- workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
25
+ awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
26
+ utilmaps "github.com/project-codeflare/appwrapper/internal/util"
26
27
"github.com/project-codeflare/appwrapper/pkg/utils"
27
28
v1 "k8s.io/api/core/v1"
28
29
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -34,8 +35,6 @@ import (
34
35
"sigs.k8s.io/controller-runtime/pkg/client"
35
36
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
36
37
"sigs.k8s.io/controller-runtime/pkg/log"
37
- "sigs.k8s.io/kueue/pkg/podset"
38
- utilmaps "sigs.k8s.io/kueue/pkg/util/maps"
39
38
)
40
39
41
40
func parseComponent (raw []byte , expectedNamespace string ) (* unstructured.Unstructured , error ) {
@@ -188,7 +187,7 @@ func addNodeSelectorsToAffinity(spec map[string]interface{}, exprsToAdd []v1.Nod
188
187
}
189
188
190
189
//gocyclo:ignore
191
- func (r * AppWrapperReconciler ) createComponent (ctx context.Context , aw * workloadv1beta2 .AppWrapper , componentIdx int ) (error , bool ) {
190
+ func (r * AppWrapperReconciler ) createComponent (ctx context.Context , aw * awv1beta2 .AppWrapper , componentIdx int ) (error , bool ) {
192
191
component := aw .Spec .Components [componentIdx ]
193
192
componentStatus := aw .Status .ComponentStatus [componentIdx ]
194
193
toMap := func (x interface {}) map [string ]string {
@@ -218,17 +217,13 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
218
217
if err != nil {
219
218
return err , true
220
219
}
221
- awLabels := map [string ]string {workloadv1beta2 .AppWrapperLabel : aw .Name }
220
+ awLabels := map [string ]string {awv1beta2 .AppWrapperLabel : aw .Name }
222
221
obj .SetLabels (utilmaps .MergeKeepFirst (obj .GetLabels (), awLabels ))
223
222
224
223
for podSetsIdx , podSet := range componentStatus .PodSets {
225
- toInject := & workloadv1beta2.AppWrapperPodSetInfo {}
226
- if r .Config .EnableKueueIntegrations {
227
- if podSetsIdx < len (component .PodSetInfos ) {
228
- toInject = & component .PodSetInfos [podSetsIdx ]
229
- } else {
230
- return fmt .Errorf ("missing podSetInfo %v for component %v" , podSetsIdx , componentIdx ), true
231
- }
224
+ toInject := & awv1beta2.AppWrapperPodSetInfo {}
225
+ if podSetsIdx < len (component .PodSetInfos ) {
226
+ toInject = & component .PodSetInfos [podSetsIdx ]
232
227
}
233
228
234
229
p , err := utils .GetRawTemplate (obj .UnstructuredContent (), podSet .Path )
@@ -245,7 +240,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
245
240
if len (toInject .Annotations ) > 0 {
246
241
existing := toMap (metadata ["annotations" ])
247
242
if err := utilmaps .HaveConflict (existing , toInject .Annotations ); err != nil {
248
- return podset . BadPodSetsUpdateError ( " annotations" , err ), true
243
+ return fmt . Errorf ( "conflict updating annotations: %w " , err ), true
249
244
}
250
245
metadata ["annotations" ] = utilmaps .MergeKeepFirst (existing , toInject .Annotations )
251
246
}
@@ -254,15 +249,15 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
254
249
mergedLabels := utilmaps .MergeKeepFirst (toInject .Labels , awLabels )
255
250
existing := toMap (metadata ["labels" ])
256
251
if err := utilmaps .HaveConflict (existing , mergedLabels ); err != nil {
257
- return podset . BadPodSetsUpdateError ( " labels" , err ), true
252
+ return fmt . Errorf ( "conflict updating labels: %w " , err ), true
258
253
}
259
254
metadata ["labels" ] = utilmaps .MergeKeepFirst (existing , mergedLabels )
260
255
261
256
// NodeSelectors
262
257
if len (toInject .NodeSelector ) > 0 {
263
258
existing := toMap (spec ["nodeSelector" ])
264
259
if err := utilmaps .HaveConflict (existing , toInject .NodeSelector ); err != nil {
265
- return podset . BadPodSetsUpdateError ( " nodeSelector" , err ), true
260
+ return fmt . Errorf ( "conflict updating nodeSelector: %w " , err ), true
266
261
}
267
262
spec ["nodeSelector" ] = utilmaps .MergeKeepFirst (existing , toInject .NodeSelector )
268
263
}
@@ -354,12 +349,12 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
354
349
log .FromContext (ctx ).Info ("After injection" , "obj" , obj )
355
350
356
351
orig := copyForStatusPatch (aw )
357
- if meta .FindStatusCondition (aw .Status .ComponentStatus [componentIdx ].Conditions , string (workloadv1beta2 .ResourcesDeployed )) == nil {
352
+ if meta .FindStatusCondition (aw .Status .ComponentStatus [componentIdx ].Conditions , string (awv1beta2 .ResourcesDeployed )) == nil {
358
353
aw .Status .ComponentStatus [componentIdx ].Name = obj .GetName ()
359
354
aw .Status .ComponentStatus [componentIdx ].Kind = obj .GetKind ()
360
355
aw .Status .ComponentStatus [componentIdx ].APIVersion = obj .GetAPIVersion ()
361
356
meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
362
- Type : string (workloadv1beta2 .ResourcesDeployed ),
357
+ Type : string (awv1beta2 .ResourcesDeployed ),
363
358
Status : metav1 .ConditionUnknown ,
364
359
Reason : "ComponentCreationInitiated" ,
365
360
})
@@ -383,7 +378,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
383
378
// resource not actually created; patch status to reflect that
384
379
orig := copyForStatusPatch (aw )
385
380
meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
386
- Type : string (workloadv1beta2 .ResourcesDeployed ),
381
+ Type : string (awv1beta2 .ResourcesDeployed ),
387
382
Status : metav1 .ConditionFalse ,
388
383
Reason : "ComponentCreationErrored" ,
389
384
})
@@ -399,7 +394,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
399
394
orig = copyForStatusPatch (aw )
400
395
aw .Status .ComponentStatus [componentIdx ].Name = obj .GetName () // Update name to support usage of GenerateName
401
396
meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
402
- Type : string (workloadv1beta2 .ResourcesDeployed ),
397
+ Type : string (awv1beta2 .ResourcesDeployed ),
403
398
Status : metav1 .ConditionTrue ,
404
399
Reason : "ComponentCreatedSuccessfully" ,
405
400
})
@@ -411,9 +406,9 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
411
406
}
412
407
413
408
// createComponents incrementally patches aw.Status -- MUST NOT CARRY STATUS PATCHES ACROSS INVOCATIONS
414
- func (r * AppWrapperReconciler ) createComponents (ctx context.Context , aw * workloadv1beta2 .AppWrapper ) (error , bool ) {
409
+ func (r * AppWrapperReconciler ) createComponents (ctx context.Context , aw * awv1beta2 .AppWrapper ) (error , bool ) {
415
410
for componentIdx := range aw .Spec .Components {
416
- if ! meta .IsStatusConditionTrue (aw .Status .ComponentStatus [componentIdx ].Conditions , string (workloadv1beta2 .ResourcesDeployed )) {
411
+ if ! meta .IsStatusConditionTrue (aw .Status .ComponentStatus [componentIdx ].Conditions , string (awv1beta2 .ResourcesDeployed )) {
417
412
if err , fatal := r .createComponent (ctx , aw , componentIdx ); err != nil {
418
413
return err , fatal
419
414
}
@@ -422,10 +417,10 @@ func (r *AppWrapperReconciler) createComponents(ctx context.Context, aw *workloa
422
417
return nil , false
423
418
}
424
419
425
- func (r * AppWrapperReconciler ) deleteComponents (ctx context.Context , aw * workloadv1beta2 .AppWrapper ) bool {
420
+ func (r * AppWrapperReconciler ) deleteComponents (ctx context.Context , aw * awv1beta2 .AppWrapper ) bool {
426
421
deleteIfPresent := func (idx int , opts ... client.DeleteOption ) bool {
427
422
cs := & aw .Status .ComponentStatus [idx ]
428
- rd := meta .FindStatusCondition (cs .Conditions , string (workloadv1beta2 .ResourcesDeployed ))
423
+ rd := meta .FindStatusCondition (cs .Conditions , string (awv1beta2 .ResourcesDeployed ))
429
424
if rd == nil || rd .Status == metav1 .ConditionFalse || (rd .Status == metav1 .ConditionUnknown && cs .Name == "" ) {
430
425
return false // not present
431
426
}
@@ -437,7 +432,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
437
432
if apierrors .IsNotFound (err ) {
438
433
// Has already been undeployed; update componentStatus and return not present
439
434
meta .SetStatusCondition (& cs .Conditions , metav1.Condition {
440
- Type : string (workloadv1beta2 .ResourcesDeployed ),
435
+ Type : string (awv1beta2 .ResourcesDeployed ),
441
436
Status : metav1 .ConditionFalse ,
442
437
Reason : "CompononetDeleted" ,
443
438
})
@@ -451,7 +446,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
451
446
}
452
447
453
448
meta .SetStatusCondition (& aw .Status .Conditions , metav1.Condition {
454
- Type : string (workloadv1beta2 .DeletingResources ),
449
+ Type : string (awv1beta2 .DeletingResources ),
455
450
Status : metav1 .ConditionTrue ,
456
451
Reason : "DeletionInitiated" ,
457
452
})
@@ -462,7 +457,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
462
457
}
463
458
464
459
deletionGracePeriod := r .forcefulDeletionGraceDuration (ctx , aw )
465
- whenInitiated := meta .FindStatusCondition (aw .Status .Conditions , string (workloadv1beta2 .DeletingResources )).LastTransitionTime
460
+ whenInitiated := meta .FindStatusCondition (aw .Status .Conditions , string (awv1beta2 .DeletingResources )).LastTransitionTime
466
461
gracePeriodExpired := time .Now ().After (whenInitiated .Time .Add (deletionGracePeriod ))
467
462
468
463
if componentsRemaining && ! gracePeriodExpired {
@@ -474,13 +469,13 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
474
469
if err := r .List (ctx , pods ,
475
470
client .UnsafeDisableDeepCopy ,
476
471
client .InNamespace (aw .Namespace ),
477
- client.MatchingLabels {workloadv1beta2 .AppWrapperLabel : aw .Name }); err != nil {
472
+ client.MatchingLabels {awv1beta2 .AppWrapperLabel : aw .Name }); err != nil {
478
473
log .FromContext (ctx ).Error (err , "Pod list error" )
479
474
}
480
475
481
476
if ! componentsRemaining && len (pods .Items ) == 0 {
482
477
// no resources or pods left; deletion is complete
483
- clearCondition (aw , workloadv1beta2 .DeletingResources , "DeletionComplete" , "" )
478
+ clearCondition (aw , awv1beta2 .DeletingResources , "DeletionComplete" , "" )
484
479
return true
485
480
}
486
481
0 commit comments