@@ -46,6 +46,12 @@ const (
46
46
47
47
// DeploymentTargetLabel is the label indicating the DeploymentTarget that's associated with the SpaceRequest
48
48
DeploymentTargetLabel = "appstudio.openshift.io/dt"
49
+
50
+ DeploymentTargetClaimConditionTypeErrorOccurred = "ValidDeploymentTargetClaim"
51
+
52
+ DeploymentTargetClaimReasonErrorOccurred = "ErrorOccurred"
53
+
54
+ DeploymentTargetClaimReasonBound = "Bound"
49
55
)
50
56
51
57
// DeploymentTargetClaimReconciler reconciles a DeploymentTargetClaim object
@@ -98,6 +104,14 @@ func (r *DeploymentTargetClaimReconciler) Reconcile(ctx context.Context, req ctr
98
104
// Add the deletion finalizer if it is absent.
99
105
if addFinalizer (& dtc , applicationv1alpha1 .FinalizerBinder ) {
100
106
if err := r .Client .Update (ctx , & dtc ); err != nil {
107
+
108
+ // Update Status.Conditions field of DeploymentTargetClaim.
109
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client ,
110
+ fmt .Sprintf ("failed to add finalizer %s to DeploymentTargetClaim" , applicationv1alpha1 .FinalizerBinder ),
111
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
112
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
113
+ }
114
+
101
115
return ctrl.Result {}, fmt .Errorf ("failed to add finalizer %s to DeploymentTargetClaim %s in namespace %s: %v" , applicationv1alpha1 .FinalizerBinder , dtc .Name , dtc .Namespace , err )
102
116
}
103
117
log .Info ("Added finalizer to DeploymentTargetClaim" , "finalizer" , applicationv1alpha1 .FinalizerBinder )
@@ -112,6 +126,13 @@ func (r *DeploymentTargetClaimReconciler) Reconcile(ctx context.Context, req ctr
112
126
if dtc .Status .Phase == applicationv1alpha1 .DeploymentTargetClaimPhase_Pending && isMarkedForDynamicProvisioning (dtc ) {
113
127
if err := handleProvisioningOfSpaceRequestForDTC (ctx , dtc , r .Client , log ); err != nil {
114
128
log .Error (err , "unable to handle provisioning of space request for dynamic DTC" )
129
+
130
+ // Update Status.Conditions field of DeploymentTargetClaim.
131
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "unable to handle provisioning of space request for dynamic DTC" ,
132
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
133
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
134
+ }
135
+
115
136
return ctrl.Result {}, err
116
137
}
117
138
}
@@ -121,6 +142,13 @@ func (r *DeploymentTargetClaimReconciler) Reconcile(ctx context.Context, req ctr
121
142
if isDTCBindingCompleted (dtc ) {
122
143
if err := handleBoundedDeploymentTargetClaim (ctx , r .Client , dtc , log ); err != nil {
123
144
log .Error (err , "failed to process bounded DeploymentTargetClaim" )
145
+
146
+ // Update Status.Conditions field of DeploymentTargetClaim.
147
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "failed to process bounded DeploymentTargetClaim" ,
148
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
149
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
150
+ }
151
+
124
152
return ctrl.Result {}, err
125
153
}
126
154
return ctrl.Result {}, nil
@@ -132,6 +160,13 @@ func (r *DeploymentTargetClaimReconciler) Reconcile(ctx context.Context, req ctr
132
160
dt , err := findMatchingDTForDTC (ctx , r .Client , dtc )
133
161
if err != nil {
134
162
log .Error (err , "failed to find a DeploymentTarget that matches the DeploymentTargetClaim" )
163
+
164
+ // Update Status.Conditions field of DeploymentTargetClaim.
165
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "failed to find a DeploymentTarget that matches the DeploymentTargetClaim" ,
166
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
167
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
168
+ }
169
+
135
170
return ctrl.Result {}, err
136
171
}
137
172
@@ -141,6 +176,13 @@ func (r *DeploymentTargetClaimReconciler) Reconcile(ctx context.Context, req ctr
141
176
142
177
if err := bindDeploymentTargetClaimToTarget (ctx , r .Client , & dtc , dt , true , log ); err != nil {
143
178
log .Error (err , "failed to bind DeploymentTargetClaim to the DeploymentTarget" , "DeploymentTargetName" , dt .Name , "Namespace" , dt .Name )
179
+
180
+ // Update Status.Conditions field of DeploymentTargetClaim.
181
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "failed to bind DeploymentTargetClaim to the DeploymentTarget" ,
182
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
183
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
184
+ }
185
+
144
186
return ctrl.Result {}, err
145
187
}
146
188
@@ -151,6 +193,13 @@ func (r *DeploymentTargetClaimReconciler) Reconcile(ctx context.Context, req ctr
151
193
152
194
if err := handleDynamicDTCProvisioning (ctx , r .Client , & dtc , log ); err != nil {
153
195
log .Error (err , "failed to handle DeploymentTargetClaim for dynamic provisioning" )
196
+
197
+ // Update Status.Conditions field of DeploymentTargetClaim.
198
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "failed to handle DeploymentTargetClaim for dynamic provisioning" ,
199
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
200
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
201
+ }
202
+
154
203
return ctrl.Result {}, err
155
204
}
156
205
log .Info ("Waiting for the DeploymentTarget to be dynamically created by the provisioner" )
@@ -188,11 +237,24 @@ func (r *DeploymentTargetClaimReconciler) Reconcile(ctx context.Context, req ctr
188
237
// Both DT and DTC refer each other. So bind them together.
189
238
if err := bindDeploymentTargetClaimToTarget (ctx , r .Client , & dtc , & dt , false , log ); err != nil {
190
239
log .Error (err , "failed to bind DeploymentTargetClaim to the DeploymentTarget" , "DeploymentTargetName" , dt .Name , "Namespace" , dt .Name )
240
+
241
+ // Update Status.Conditions field of DeploymentTargetClaim.
242
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "failed to bind DeploymentTargetClaim to the DeploymentTarget" ,
243
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
244
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
245
+ }
246
+
191
247
return ctrl.Result {}, err
192
248
}
193
249
} else {
194
250
log .Error (nil , "DeploymentTargetClaim wants to claim a DeploymentTarget that is already claimed" , "DeploymentTarget" , dt .Name )
195
251
252
+ // Update Status.Conditions field of DeploymentTargetClaim.
253
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "DeploymentTargetClaim wants to claim a DeploymentTarget that is already claimed" ,
254
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
255
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
256
+ }
257
+
196
258
// Update the DTC status to Pending since the DT is not available
197
259
if err := updateDTCStatusPhase (ctx , r .Client , & dtc , applicationv1alpha1 .DeploymentTargetClaimPhase_Pending , log ); err != nil {
198
260
return ctrl.Result {}, err
@@ -204,18 +266,38 @@ func (r *DeploymentTargetClaimReconciler) Reconcile(ctx context.Context, req ctr
204
266
// At this stage, DT isn't claimed by anyone. The current DTC can try to claim it.
205
267
if err := doesDTMatchDTC (dt , dtc ); err != nil {
206
268
log .Error (err , "DeploymentTarget does not match the specified DeploymentTargetClaim" )
269
+
270
+ // Update Status.Conditions field of DeploymentTargetClaim.
271
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "DeploymentTarget does not match the specified DeploymentTargetClaim" ,
272
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
273
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
274
+ }
275
+
207
276
return ctrl.Result {}, err
208
277
}
209
278
210
279
err := bindDeploymentTargetClaimToTarget (ctx , r .Client , & dtc , & dt , false , log )
211
280
if err != nil {
212
281
log .Error (err , "failed to bind DeploymentTargetClaim to the DeploymentTarget" , "DeploymentTargetName" , dt .Name , "Namespace" , dt .Name )
282
+
283
+ // Update Status.Conditions field of DeploymentTargetClaim.
284
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "failed to bind DeploymentTargetClaim to the DeploymentTarget" ,
285
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionFalse , DeploymentTargetClaimReasonErrorOccurred , log ); err != nil {
286
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
287
+ }
288
+
213
289
return ctrl.Result {}, err
214
290
}
215
291
}
216
292
217
293
log .Info ("DeploymentTargetClaim bound to DeploymentTarget" , "DeploymentTargetName" , dt .Name , "Namespace" , dt .Namespace )
218
294
295
+ // Update Status.Conditions field of DeploymentTargetClaim.
296
+ if err := updateStatusConditionOfDeploymentTargetClaim (ctx , r .Client , "" ,
297
+ & dtc , DeploymentTargetClaimConditionTypeErrorOccurred , metav1 .ConditionTrue , DeploymentTargetClaimReasonBound , log ); err != nil {
298
+ return ctrl.Result {}, fmt .Errorf ("unable to update deployment target claim status condition. %v" , err )
299
+ }
300
+
219
301
return ctrl.Result {}, nil
220
302
}
221
303
@@ -861,3 +943,28 @@ func createSpaceRequestForDTC(ctx context.Context, k8sClient client.Client, dtc
861
943
862
944
return & newSpaceRequest , nil
863
945
}
946
+
947
+ // updateStatusConditionOfDeploymentTargetClaim calls SetCondition() with DeploymentTargetClaim conditions
948
+ func updateStatusConditionOfDeploymentTargetClaim (ctx context.Context , client client.Client ,
949
+ message string , deploymentTargetClaim * applicationv1alpha1.DeploymentTargetClaim , conditionType string ,
950
+ status metav1.ConditionStatus , reason string , log logr.Logger ) error {
951
+
952
+ newCondition := metav1.Condition {
953
+ Type : conditionType ,
954
+ Message : message ,
955
+ Status : status ,
956
+ Reason : reason ,
957
+ }
958
+
959
+ changed , newConditions := insertOrUpdateConditionsInSlice (newCondition , deploymentTargetClaim .Status .Conditions )
960
+
961
+ if changed {
962
+ deploymentTargetClaim .Status .Conditions = newConditions
963
+
964
+ if err := client .Status ().Update (ctx , deploymentTargetClaim ); err != nil {
965
+ log .Error (err , "unable to update deploymentTargetClaim status condition." )
966
+ return err
967
+ }
968
+ }
969
+ return nil
970
+ }
0 commit comments