@@ -17,6 +17,7 @@ limitations under the License.
1717package workload
1818
1919import (
20+ "context"
2021 "fmt"
2122
2223 "k8s.io/apimachinery/pkg/api/meta"
@@ -32,6 +33,7 @@ import (
3233 "sigs.k8s.io/kueue/pkg/podset"
3334
3435 workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
36+ "github.com/project-codeflare/appwrapper/internal/controller/awstatus"
3537 "github.com/project-codeflare/appwrapper/pkg/utils"
3638)
3739
@@ -77,17 +79,21 @@ func (aw *AppWrapper) GVK() schema.GroupVersionKind {
7779
7880func (aw * AppWrapper ) PodSets () []kueue.PodSet {
7981 podSets := []kueue.PodSet {}
80- for componentIdx , component := range aw .Spec .Components {
81- if len (component .PodSets ) > 0 {
82+ if err := awstatus .EnsureComponentStatusInitialized (context .Background (), (* workloadv1beta2 .AppWrapper )(aw )); err != nil {
83+ // Kueue will raise an error on zero length PodSet. Unfortunately, the Kueue API prevents propagating the actual error
84+ return podSets
85+ }
86+ for idx := range aw .Status .ComponentStatus {
87+ if len (aw .Status .ComponentStatus [idx ].PodSets ) > 0 {
8288 obj := & unstructured.Unstructured {}
83- if _ , _ , err := unstructured .UnstructuredJSONScheme .Decode (component .Template .Raw , nil , obj ); err != nil {
89+ if _ , _ , err := unstructured .UnstructuredJSONScheme .Decode (aw . Spec . Components [ idx ] .Template .Raw , nil , obj ); err != nil {
8490 continue // Should be unreachable; Template.Raw validated by our AdmissionController
8591 }
86- for psIdx , podSet := range component .PodSets {
92+ for psIdx , podSet := range aw . Status . ComponentStatus [ idx ] .PodSets {
8793 replicas := utils .Replicas (podSet )
8894 if template , err := utils .GetPodTemplateSpec (obj , podSet .Path ); err == nil {
8995 podSets = append (podSets , kueue.PodSet {
90- Name : fmt .Sprintf ("%s-%v-%v" , aw .Name , componentIdx , psIdx ),
96+ Name : fmt .Sprintf ("%s-%v-%v" , aw .Name , idx , psIdx ),
9197 Template : * template ,
9298 Count : replicas ,
9399 })
@@ -101,17 +107,16 @@ func (aw *AppWrapper) PodSets() []kueue.PodSet {
101107// RunWithPodSetsInfo records the assigned PodSetInfos for each component and sets aw.spec.Suspend to false
102108func (aw * AppWrapper ) RunWithPodSetsInfo (podSetsInfo []podset.PodSetInfo ) error {
103109 podSetsInfoIndex := 0
104- for componentIdx := range aw .Spec .Components {
105- component := & aw .Spec .Components [componentIdx ]
106- if len (component .PodSetInfos ) != len (component .PodSets ) {
107- component .PodSetInfos = make ([]workloadv1beta2.AppWrapperPodSetInfo , len (component .PodSets ))
110+ for idx := range aw .Spec .Components {
111+ if len (aw .Spec .Components [idx ].PodSetInfos ) != len (aw .Status .ComponentStatus [idx ].PodSets ) {
112+ aw .Spec .Components [idx ].PodSetInfos = make ([]workloadv1beta2.AppWrapperPodSetInfo , len (aw .Status .ComponentStatus [idx ].PodSets ))
108113 }
109- for podSetIdx := range component .PodSets {
114+ for podSetIdx := range aw . Status . ComponentStatus [ idx ] .PodSets {
110115 podSetsInfoIndex += 1
111116 if podSetsInfoIndex > len (podSetsInfo ) {
112117 continue // we will return an error below...continuing to get an accurate count for the error message
113118 }
114- component .PodSetInfos [podSetIdx ] = workloadv1beta2.AppWrapperPodSetInfo {
119+ aw . Spec . Components [ idx ] .PodSetInfos [podSetIdx ] = workloadv1beta2.AppWrapperPodSetInfo {
115120 Annotations : podSetsInfo [podSetIdx ].Annotations ,
116121 Labels : podSetsInfo [podSetIdx ].Labels ,
117122 NodeSelector : podSetsInfo [podSetIdx ].NodeSelector ,
0 commit comments