@@ -21,6 +21,7 @@ import (
2121
2222 workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
2323 "github.com/project-codeflare/appwrapper/pkg/utils"
24+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2526 "sigs.k8s.io/controller-runtime/pkg/client"
2627)
@@ -33,16 +34,33 @@ func CacheClient(k8sclient client.Client) {
3334 cachedClient = k8sclient
3435}
3536
37+ const controllerName = "workload.codeflare.dev-appwrapper"
38+
39+ func BaseForStatusPatch (aw * workloadv1beta2.AppWrapper ) * workloadv1beta2.AppWrapper {
40+ patch := & workloadv1beta2.AppWrapper {
41+ ObjectMeta : metav1.ObjectMeta {
42+ UID : aw .UID ,
43+ Name : aw .Name ,
44+ Namespace : aw .Namespace ,
45+ },
46+ TypeMeta : metav1.TypeMeta {
47+ APIVersion : workloadv1beta2 .GroupVersion .String (),
48+ Kind : "AppWrapper" ,
49+ },
50+ }
51+ return patch
52+ }
53+
3654func EnsureComponentStatusInitialized (ctx context.Context , aw * workloadv1beta2.AppWrapper ) error {
3755 if len (aw .Status .ComponentStatus ) == len (aw .Spec .Components ) {
3856 return nil
3957 }
4058
4159 // Construct definitive PodSets from the Spec + InferPodSets and cache in the Status (to avoid clashing with user updates to the Spec via apply)
42- aw . Status . ComponentStatus = make ([]workloadv1beta2.AppWrapperComponentStatus , len (aw .Spec .Components ))
60+ compStatus : = make ([]workloadv1beta2.AppWrapperComponentStatus , len (aw .Spec .Components ))
4361 for idx := range aw .Spec .Components {
4462 if len (aw .Spec .Components [idx ].DeclaredPodSets ) > 0 {
45- aw . Status . ComponentStatus [idx ].PodSets = aw .Spec .Components [idx ].DeclaredPodSets
63+ compStatus [idx ].PodSets = aw .Spec .Components [idx ].DeclaredPodSets
4664 } else {
4765 obj := & unstructured.Unstructured {}
4866 if _ , _ , err := unstructured .UnstructuredJSONScheme .Decode (aw .Spec .Components [idx ].Template .Raw , nil , obj ); err != nil {
@@ -54,9 +72,12 @@ func EnsureComponentStatusInitialized(ctx context.Context, aw *workloadv1beta2.A
5472 // Transient error; InferPodSets was validated by our AdmissionController
5573 return err
5674 }
57- aw . Status . ComponentStatus [idx ].PodSets = podSets
75+ compStatus [idx ].PodSets = podSets
5876 }
5977 }
78+ aw .Status .ComponentStatus = compStatus
6079
61- return cachedClient .Status ().Update (ctx , aw )
80+ patch := BaseForStatusPatch (aw )
81+ patch .Status .ComponentStatus = compStatus
82+ return cachedClient .Status ().Patch (ctx , patch , client .Apply , client .FieldOwner (controllerName ), client .ForceOwnership )
6283}
0 commit comments