@@ -21,6 +21,7 @@ import (
21
21
22
22
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
23
23
"github.com/project-codeflare/appwrapper/pkg/utils"
24
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
25
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
25
26
"sigs.k8s.io/controller-runtime/pkg/client"
26
27
)
@@ -33,16 +34,33 @@ func CacheClient(k8sclient client.Client) {
33
34
cachedClient = k8sclient
34
35
}
35
36
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
+
36
54
func EnsureComponentStatusInitialized (ctx context.Context , aw * workloadv1beta2.AppWrapper ) error {
37
55
if len (aw .Status .ComponentStatus ) == len (aw .Spec .Components ) {
38
56
return nil
39
57
}
40
58
41
59
// 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 ))
43
61
for idx := range aw .Spec .Components {
44
62
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
46
64
} else {
47
65
obj := & unstructured.Unstructured {}
48
66
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
54
72
// Transient error; InferPodSets was validated by our AdmissionController
55
73
return err
56
74
}
57
- aw . Status . ComponentStatus [idx ].PodSets = podSets
75
+ compStatus [idx ].PodSets = podSets
58
76
}
59
77
}
78
+ aw .Status .ComponentStatus = compStatus
60
79
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 )
62
83
}
0 commit comments