@@ -52,7 +52,7 @@ func parseComponent(raw []byte, expectedNamespace string) (*unstructured.Unstruc
52
52
}
53
53
54
54
//gocyclo:ignore
55
- func (r * AppWrapperReconciler ) createComponent (ctx context.Context , aw * workloadv1beta2.AppWrapper , componentIdx int ) (* unstructured. Unstructured , error , bool ) {
55
+ func (r * AppWrapperReconciler ) createComponent (ctx context.Context , aw * workloadv1beta2.AppWrapper , componentIdx int ) (error , bool ) {
56
56
component := aw .Spec .Components [componentIdx ]
57
57
componentStatus := aw .Status .ComponentStatus [componentIdx ]
58
58
toMap := func (x interface {}) map [string ]string {
@@ -80,7 +80,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
80
80
81
81
obj , err := parseComponent (component .Template .Raw , aw .Namespace )
82
82
if err != nil {
83
- return nil , err , true
83
+ return err , true
84
84
}
85
85
if r .Config .EnableKueueIntegrations && ! r .Config .DisableChildAdmissionCtrl {
86
86
obj .SetLabels (utilmaps .MergeKeepFirst (obj .GetLabels (), map [string ]string {AppWrapperLabel : aw .Name , constants .QueueLabel : childJobQueueName }))
@@ -95,13 +95,13 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
95
95
if podSetsIdx < len (component .PodSetInfos ) {
96
96
toInject = & component .PodSetInfos [podSetsIdx ]
97
97
} else {
98
- return nil , fmt .Errorf ("missing podSetInfo %v for component %v" , podSetsIdx , componentIdx ), true
98
+ return fmt .Errorf ("missing podSetInfo %v for component %v" , podSetsIdx , componentIdx ), true
99
99
}
100
100
}
101
101
102
102
p , err := utils .GetRawTemplate (obj .UnstructuredContent (), podSet .Path )
103
103
if err != nil {
104
- return nil , err , true // Should not happen, path validity is enforced by validateAppWrapperInvariants
104
+ return err , true // Should not happen, path validity is enforced by validateAppWrapperInvariants
105
105
}
106
106
if md , ok := p ["metadata" ]; ! ok || md == nil {
107
107
p ["metadata" ] = make (map [string ]interface {})
@@ -113,7 +113,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
113
113
if len (toInject .Annotations ) > 0 {
114
114
existing := toMap (metadata ["annotations" ])
115
115
if err := utilmaps .HaveConflict (existing , toInject .Annotations ); err != nil {
116
- return nil , podset .BadPodSetsUpdateError ("annotations" , err ), true
116
+ return podset .BadPodSetsUpdateError ("annotations" , err ), true
117
117
}
118
118
metadata ["annotations" ] = utilmaps .MergeKeepFirst (existing , toInject .Annotations )
119
119
}
@@ -122,15 +122,15 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
122
122
mergedLabels := utilmaps .MergeKeepFirst (toInject .Labels , awLabels )
123
123
existing := toMap (metadata ["labels" ])
124
124
if err := utilmaps .HaveConflict (existing , mergedLabels ); err != nil {
125
- return nil , podset .BadPodSetsUpdateError ("labels" , err ), true
125
+ return podset .BadPodSetsUpdateError ("labels" , err ), true
126
126
}
127
127
metadata ["labels" ] = utilmaps .MergeKeepFirst (existing , mergedLabels )
128
128
129
129
// NodeSelectors
130
130
if len (toInject .NodeSelector ) > 0 {
131
131
existing := toMap (spec ["nodeSelector" ])
132
132
if err := utilmaps .HaveConflict (existing , toInject .NodeSelector ); err != nil {
133
- return nil , podset .BadPodSetsUpdateError ("nodeSelector" , err ), true
133
+ return podset .BadPodSetsUpdateError ("nodeSelector" , err ), true
134
134
}
135
135
spec ["nodeSelector" ] = utilmaps .MergeKeepFirst (existing , toInject .NodeSelector )
136
136
}
@@ -156,43 +156,57 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
156
156
}
157
157
158
158
if err := controllerutil .SetControllerReference (aw , obj , r .Scheme ); err != nil {
159
- return nil , err , true
159
+ return err , true
160
+ }
161
+
162
+ if meta .FindStatusCondition (aw .Status .ComponentStatus [componentIdx ].Conditions , string (workloadv1beta2 .ResourcesDeployed )) == nil {
163
+ aw .Status .ComponentStatus [componentIdx ].Name = obj .GetName ()
164
+ aw .Status .ComponentStatus [componentIdx ].Kind = obj .GetKind ()
165
+ aw .Status .ComponentStatus [componentIdx ].APIVersion = obj .GetAPIVersion ()
166
+ meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
167
+ Type : string (workloadv1beta2 .ResourcesDeployed ),
168
+ Status : metav1 .ConditionUnknown ,
169
+ Reason : "ComponentCreationInitiated" ,
170
+ })
171
+ if err := r .Status ().Update (ctx , aw ); err != nil {
172
+ return err , false
173
+ }
160
174
}
161
175
162
176
if err := r .Create (ctx , obj ); err != nil {
163
177
if apierrors .IsAlreadyExists (err ) {
164
178
// obj is not updated if Create returns an error; Get required for accurate information
165
179
if err := r .Get (ctx , client .ObjectKeyFromObject (obj ), obj ); err != nil {
166
- return nil , err , false
180
+ return err , false
167
181
}
168
182
ctrlRef := metav1 .GetControllerOf (obj )
169
183
if ctrlRef == nil || ctrlRef .Name != aw .Name {
170
- return nil , fmt .Errorf ("resource %v exists, but is not controlled by appwrapper" , obj .GetName ()), true
184
+ return fmt .Errorf ("resource %v exists, but is not controlled by appwrapper" , obj .GetName ()), true
171
185
}
172
- return obj , nil , false // ok -- already exists and the correct appwrapper owns it.
186
+ // fall through. This is not actually an error. The object already exists and the correct appwrapper owns it.
173
187
} else {
174
- return nil , err , meta .IsNoMatchError (err ) || apierrors .IsInvalid (err ) // fatal
188
+ return err , meta .IsNoMatchError (err ) || apierrors .IsInvalid (err ) // fatal
175
189
}
176
190
}
177
191
178
- return obj , nil , false
192
+ meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
193
+ Type : string (workloadv1beta2 .ResourcesDeployed ),
194
+ Status : metav1 .ConditionTrue ,
195
+ Reason : "ComponentCreatedSuccessfully" ,
196
+ })
197
+ if err := r .Status ().Update (ctx , aw ); err != nil {
198
+ return err , false
199
+ }
200
+
201
+ return nil , false
179
202
}
180
203
181
204
func (r * AppWrapperReconciler ) createComponents (ctx context.Context , aw * workloadv1beta2.AppWrapper ) (error , bool ) {
182
205
for componentIdx := range aw .Spec .Components {
183
206
if ! meta .IsStatusConditionTrue (aw .Status .ComponentStatus [componentIdx ].Conditions , string (workloadv1beta2 .ResourcesDeployed )) {
184
- obj , err , fatal := r .createComponent (ctx , aw , componentIdx )
185
- if err != nil {
207
+ if err , fatal := r .createComponent (ctx , aw , componentIdx ); err != nil {
186
208
return err , fatal
187
209
}
188
- aw .Status .ComponentStatus [componentIdx ].Name = obj .GetName ()
189
- aw .Status .ComponentStatus [componentIdx ].Kind = obj .GetKind ()
190
- aw .Status .ComponentStatus [componentIdx ].APIVersion = obj .GetAPIVersion ()
191
- meta .SetStatusCondition (& aw .Status .ComponentStatus [componentIdx ].Conditions , metav1.Condition {
192
- Type : string (workloadv1beta2 .ResourcesDeployed ),
193
- Status : metav1 .ConditionTrue ,
194
- Reason : "CompononetCreated" ,
195
- })
196
210
}
197
211
}
198
212
return nil , false
@@ -201,7 +215,7 @@ func (r *AppWrapperReconciler) createComponents(ctx context.Context, aw *workloa
201
215
func (r * AppWrapperReconciler ) deleteComponents (ctx context.Context , aw * workloadv1beta2.AppWrapper ) bool {
202
216
deleteIfPresent := func (idx int , opts ... client.DeleteOption ) bool {
203
217
cs := & aw .Status .ComponentStatus [idx ]
204
- if ! meta .IsStatusConditionTrue (cs .Conditions , string (workloadv1beta2 .ResourcesDeployed )) {
218
+ if rd := meta .FindStatusCondition (cs .Conditions , string (workloadv1beta2 .ResourcesDeployed )); rd == nil || rd . Status == metav1 . ConditionFalse {
205
219
return false // not present
206
220
}
207
221
obj := & metav1.PartialObjectMetadata {
0 commit comments