@@ -22,7 +22,8 @@ import (
2222 "fmt"
2323 "time"
2424
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"
2627 "github.com/project-codeflare/appwrapper/pkg/utils"
2728 v1 "k8s.io/api/core/v1"
2829 apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -34,8 +35,6 @@ import (
3435 "sigs.k8s.io/controller-runtime/pkg/client"
3536 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3637 "sigs.k8s.io/controller-runtime/pkg/log"
37- "sigs.k8s.io/kueue/pkg/podset"
38- utilmaps "sigs.k8s.io/kueue/pkg/util/maps"
3938)
4039
4140func parseComponent (raw []byte , expectedNamespace string ) (* unstructured.Unstructured , error ) {
@@ -188,7 +187,7 @@ func addNodeSelectorsToAffinity(spec map[string]interface{}, exprsToAdd []v1.Nod
188187}
189188
190189//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 ) {
192191 component := aw .Spec .Components [componentIdx ]
193192 componentStatus := aw .Status .ComponentStatus [componentIdx ]
194193 toMap := func (x interface {}) map [string ]string {
@@ -218,17 +217,13 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
218217 if err != nil {
219218 return err , true
220219 }
221- awLabels := map [string ]string {workloadv1beta2 .AppWrapperLabel : aw .Name }
220+ awLabels := map [string ]string {awv1beta2 .AppWrapperLabel : aw .Name }
222221 obj .SetLabels (utilmaps .MergeKeepFirst (obj .GetLabels (), awLabels ))
223222
224223 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 ]
232227 }
233228
234229 p , err := utils .GetRawTemplate (obj .UnstructuredContent (), podSet .Path )
@@ -245,7 +240,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
245240 if len (toInject .Annotations ) > 0 {
246241 existing := toMap (metadata ["annotations" ])
247242 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
249244 }
250245 metadata ["annotations" ] = utilmaps .MergeKeepFirst (existing , toInject .Annotations )
251246 }
@@ -254,15 +249,15 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
254249 mergedLabels := utilmaps .MergeKeepFirst (toInject .Labels , awLabels )
255250 existing := toMap (metadata ["labels" ])
256251 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
258253 }
259254 metadata ["labels" ] = utilmaps .MergeKeepFirst (existing , mergedLabels )
260255
261256 // NodeSelectors
262257 if len (toInject .NodeSelector ) > 0 {
263258 existing := toMap (spec ["nodeSelector" ])
264259 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
266261 }
267262 spec ["nodeSelector" ] = utilmaps .MergeKeepFirst (existing , toInject .NodeSelector )
268263 }
@@ -354,12 +349,12 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
354349 log .FromContext (ctx ).Info ("After injection" , "obj" , obj )
355350
356351 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 {
358353 aw .Status .ComponentStatus [componentIdx ].Name = obj .GetName ()
359354 aw .Status .ComponentStatus [componentIdx ].Kind = obj .GetKind ()
360355 aw .Status .ComponentStatus [componentIdx ].APIVersion = obj .GetAPIVersion ()
361356 meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
362- Type : string (workloadv1beta2 .ResourcesDeployed ),
357+ Type : string (awv1beta2 .ResourcesDeployed ),
363358 Status : metav1 .ConditionUnknown ,
364359 Reason : "ComponentCreationInitiated" ,
365360 })
@@ -383,7 +378,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
383378 // resource not actually created; patch status to reflect that
384379 orig := copyForStatusPatch (aw )
385380 meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
386- Type : string (workloadv1beta2 .ResourcesDeployed ),
381+ Type : string (awv1beta2 .ResourcesDeployed ),
387382 Status : metav1 .ConditionFalse ,
388383 Reason : "ComponentCreationErrored" ,
389384 })
@@ -399,7 +394,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
399394 orig = copyForStatusPatch (aw )
400395 aw .Status .ComponentStatus [componentIdx ].Name = obj .GetName () // Update name to support usage of GenerateName
401396 meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
402- Type : string (workloadv1beta2 .ResourcesDeployed ),
397+ Type : string (awv1beta2 .ResourcesDeployed ),
403398 Status : metav1 .ConditionTrue ,
404399 Reason : "ComponentCreatedSuccessfully" ,
405400 })
@@ -411,9 +406,9 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
411406}
412407
413408// 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 ) {
415410 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 )) {
417412 if err , fatal := r .createComponent (ctx , aw , componentIdx ); err != nil {
418413 return err , fatal
419414 }
@@ -422,10 +417,10 @@ func (r *AppWrapperReconciler) createComponents(ctx context.Context, aw *workloa
422417 return nil , false
423418}
424419
425- func (r * AppWrapperReconciler ) deleteComponents (ctx context.Context , aw * workloadv1beta2 .AppWrapper ) bool {
420+ func (r * AppWrapperReconciler ) deleteComponents (ctx context.Context , aw * awv1beta2 .AppWrapper ) bool {
426421 deleteIfPresent := func (idx int , opts ... client.DeleteOption ) bool {
427422 cs := & aw .Status .ComponentStatus [idx ]
428- rd := meta .FindStatusCondition (cs .Conditions , string (workloadv1beta2 .ResourcesDeployed ))
423+ rd := meta .FindStatusCondition (cs .Conditions , string (awv1beta2 .ResourcesDeployed ))
429424 if rd == nil || rd .Status == metav1 .ConditionFalse || (rd .Status == metav1 .ConditionUnknown && cs .Name == "" ) {
430425 return false // not present
431426 }
@@ -437,7 +432,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
437432 if apierrors .IsNotFound (err ) {
438433 // Has already been undeployed; update componentStatus and return not present
439434 meta .SetStatusCondition (& cs .Conditions , metav1.Condition {
440- Type : string (workloadv1beta2 .ResourcesDeployed ),
435+ Type : string (awv1beta2 .ResourcesDeployed ),
441436 Status : metav1 .ConditionFalse ,
442437 Reason : "CompononetDeleted" ,
443438 })
@@ -451,7 +446,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
451446 }
452447
453448 meta .SetStatusCondition (& aw .Status .Conditions , metav1.Condition {
454- Type : string (workloadv1beta2 .DeletingResources ),
449+ Type : string (awv1beta2 .DeletingResources ),
455450 Status : metav1 .ConditionTrue ,
456451 Reason : "DeletionInitiated" ,
457452 })
@@ -462,7 +457,7 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
462457 }
463458
464459 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
466461 gracePeriodExpired := time .Now ().After (whenInitiated .Time .Add (deletionGracePeriod ))
467462
468463 if componentsRemaining && ! gracePeriodExpired {
@@ -474,13 +469,13 @@ func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloa
474469 if err := r .List (ctx , pods ,
475470 client .UnsafeDisableDeepCopy ,
476471 client .InNamespace (aw .Namespace ),
477- client.MatchingLabels {workloadv1beta2 .AppWrapperLabel : aw .Name }); err != nil {
472+ client.MatchingLabels {awv1beta2 .AppWrapperLabel : aw .Name }); err != nil {
478473 log .FromContext (ctx ).Error (err , "Pod list error" )
479474 }
480475
481476 if ! componentsRemaining && len (pods .Items ) == 0 {
482477 // no resources or pods left; deletion is complete
483- clearCondition (aw , workloadv1beta2 .DeletingResources , "DeletionComplete" , "" )
478+ clearCondition (aw , awv1beta2 .DeletingResources , "DeletionComplete" , "" )
484479 return true
485480 }
486481
0 commit comments