@@ -17,6 +17,7 @@ limitations under the License.
17
17
package workload
18
18
19
19
import (
20
+ "context"
20
21
"fmt"
21
22
22
23
"k8s.io/apimachinery/pkg/api/meta"
@@ -32,6 +33,7 @@ import (
32
33
"sigs.k8s.io/kueue/pkg/podset"
33
34
34
35
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
36
+ "github.com/project-codeflare/appwrapper/internal/controller/awstatus"
35
37
"github.com/project-codeflare/appwrapper/pkg/utils"
36
38
)
37
39
@@ -77,17 +79,21 @@ func (aw *AppWrapper) GVK() schema.GroupVersionKind {
77
79
78
80
func (aw * AppWrapper ) PodSets () []kueue.PodSet {
79
81
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 {
82
88
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 {
84
90
continue // Should be unreachable; Template.Raw validated by our AdmissionController
85
91
}
86
- for psIdx , podSet := range component .PodSets {
92
+ for psIdx , podSet := range aw . Status . ComponentStatus [ idx ] .PodSets {
87
93
replicas := utils .Replicas (podSet )
88
94
if template , err := utils .GetPodTemplateSpec (obj , podSet .Path ); err == nil {
89
95
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 ),
91
97
Template : * template ,
92
98
Count : replicas ,
93
99
})
@@ -101,17 +107,16 @@ func (aw *AppWrapper) PodSets() []kueue.PodSet {
101
107
// RunWithPodSetsInfo records the assigned PodSetInfos for each component and sets aw.spec.Suspend to false
102
108
func (aw * AppWrapper ) RunWithPodSetsInfo (podSetsInfo []podset.PodSetInfo ) error {
103
109
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 ))
108
113
}
109
- for podSetIdx := range component .PodSets {
114
+ for podSetIdx := range aw . Status . ComponentStatus [ idx ] .PodSets {
110
115
podSetsInfoIndex += 1
111
116
if podSetsInfoIndex > len (podSetsInfo ) {
112
117
continue // we will return an error below...continuing to get an accurate count for the error message
113
118
}
114
- component .PodSetInfos [podSetIdx ] = workloadv1beta2.AppWrapperPodSetInfo {
119
+ aw . Spec . Components [ idx ] .PodSetInfos [podSetIdx ] = workloadv1beta2.AppWrapperPodSetInfo {
115
120
Annotations : podSetsInfo [podSetIdx ].Annotations ,
116
121
Labels : podSetsInfo [podSetIdx ].Labels ,
117
122
NodeSelector : podSetsInfo [podSetIdx ].NodeSelector ,
0 commit comments