@@ -17,10 +17,7 @@ limitations under the License.
1717package workload
1818
1919import (
20- "fmt"
21-
2220 "k8s.io/apimachinery/pkg/api/meta"
23- "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2421 "k8s.io/apimachinery/pkg/runtime/schema"
2522
2623 "sigs.k8s.io/controller-runtime/pkg/builder"
@@ -75,72 +72,24 @@ func (aw *AppWrapper) GVK() schema.GroupVersionKind {
7572}
7673
7774func (aw * AppWrapper ) PodSets () []kueue.PodSet {
78- podSets := []kueue.PodSet {}
79- if err := utils .EnsureComponentStatusInitialized ((* workloadv1beta2 .AppWrapper )(aw )); err != nil {
80- // Kueue will raise an error on zero length PodSet. Unfortunately, the Kueue API prevents propagating the actual error
81- return podSets
82- }
83- for idx := range aw .Status .ComponentStatus {
84- if len (aw .Status .ComponentStatus [idx ].PodSets ) > 0 {
85- obj := & unstructured.Unstructured {}
86- if _ , _ , err := unstructured .UnstructuredJSONScheme .Decode (aw .Spec .Components [idx ].Template .Raw , nil , obj ); err != nil {
87- // Should be unreachable; Template.Raw validated by AppWrapper AdmissionController
88- return []kueue.PodSet {} // Kueue will raise an error on zero length PodSet.
89- }
90- for psIdx , podSet := range aw .Status .ComponentStatus [idx ].PodSets {
91- replicas := utils .Replicas (podSet )
92- if template , err := utils .GetPodTemplateSpec (obj , podSet .Path ); err == nil {
93- podSets = append (podSets , kueue.PodSet {
94- Name : fmt .Sprintf ("%s-%v-%v" , aw .Name , idx , psIdx ),
95- Template : * template ,
96- Count : replicas ,
97- })
98- }
99- }
100- }
75+ podSets , err := utils .GetPodSets ((* workloadv1beta2 .AppWrapper )(aw ))
76+ if err != nil {
77+ // Kueue will raise an error on zero length PodSet; the Kueue GenericJob API prevents propagating the actual error.
78+ return []kueue.PodSet {}
10179 }
10280 return podSets
10381}
10482
105- // RunWithPodSetsInfo records the assigned PodSetInfos for each component and sets aw.spec.Suspend to false
10683func (aw * AppWrapper ) RunWithPodSetsInfo (podSetsInfo []podset.PodSetInfo ) error {
107- if err := utils .EnsureComponentStatusInitialized ((* workloadv1beta2 .AppWrapper )(aw )); err != nil {
84+ if err := utils .SetPodSetInfos ((* workloadv1beta2 .AppWrapper )(aw ), podSetsInfo ); err != nil {
10885 return err
10986 }
110- podSetsInfoIndex := 0
111- for idx := range aw .Spec .Components {
112- if len (aw .Spec .Components [idx ].PodSetInfos ) != len (aw .Status .ComponentStatus [idx ].PodSets ) {
113- aw .Spec .Components [idx ].PodSetInfos = make ([]workloadv1beta2.AppWrapperPodSetInfo , len (aw .Status .ComponentStatus [idx ].PodSets ))
114- }
115- for podSetIdx := range aw .Status .ComponentStatus [idx ].PodSets {
116- podSetsInfoIndex += 1
117- if podSetsInfoIndex > len (podSetsInfo ) {
118- continue // we will return an error below...continuing to get an accurate count for the error message
119- }
120- aw .Spec .Components [idx ].PodSetInfos [podSetIdx ] = workloadv1beta2.AppWrapperPodSetInfo {
121- Annotations : podSetsInfo [podSetsInfoIndex - 1 ].Annotations ,
122- Labels : podSetsInfo [podSetsInfoIndex - 1 ].Labels ,
123- NodeSelector : podSetsInfo [podSetsInfoIndex - 1 ].NodeSelector ,
124- Tolerations : podSetsInfo [podSetsInfoIndex - 1 ].Tolerations ,
125- }
126- }
127- }
128-
129- if podSetsInfoIndex != len (podSetsInfo ) {
130- return podset .BadPodSetsInfoLenError (podSetsInfoIndex , len (podSetsInfo ))
131- }
132-
13387 aw .Spec .Suspend = false
134-
13588 return nil
13689}
13790
138- // RestorePodSetsInfo clears the PodSetInfos saved by RunWithPodSetsInfo
13991func (aw * AppWrapper ) RestorePodSetsInfo (podSetsInfo []podset.PodSetInfo ) bool {
140- for idx := range aw .Spec .Components {
141- aw .Spec .Components [idx ].PodSetInfos = nil
142- }
143- return true
92+ return utils .ClearPodSetInfos ((* workloadv1beta2 .AppWrapper )(aw ))
14493}
14594
14695func (aw * AppWrapper ) Finished () (message string , success , finished bool ) {
0 commit comments