Skip to content

Commit 507bc39

Browse files
adjust logic
1 parent 57b7c05 commit 507bc39

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

controllers/function_mesh.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -279,28 +279,33 @@ func (r *FunctionMeshReconciler) observeGenericResources(ctx context.Context, me
279279
return err
280280
}
281281

282-
statusFieldName := "status"
283-
if resource.StatusFieldName != "" {
284-
statusFieldName = resource.StatusFieldName
285-
}
286-
status, found, err := unstructured.NestedMap(obj.Object, statusFieldName)
287-
// if status field is not present, we consider the resource is ready
288-
if err != nil || !found {
289-
condition.SetCondition(v1alpha1.GenericResourceReady, v1alpha1.NoAction, metav1.ConditionTrue)
290-
}
282+
// check whether the resource is ready or not
283+
if len(resource.ReadyFields) > 0 {
284+
statusFieldName := "status"
285+
if resource.StatusFieldName != "" {
286+
statusFieldName = resource.StatusFieldName
287+
}
288+
status, found, err := unstructured.NestedMap(obj.Object, statusFieldName)
289+
// if status field is not present, we consider the resource is ready
290+
if err != nil || !found {
291+
condition.SetCondition(v1alpha1.GenericResourceReady, v1alpha1.NoAction, metav1.ConditionTrue)
292+
}
291293

292-
componentReady := true
293-
for _, readyField := range resource.ReadyFields {
294-
readyValue, ok := status[readyField].(metav1.ConditionStatus)
295-
if !ok || readyValue != metav1.ConditionTrue {
296-
componentReady = false
297-
break
294+
componentReady := true
295+
for _, readyField := range resource.ReadyFields {
296+
readyValue, ok := status[readyField].(metav1.ConditionStatus)
297+
if !ok || readyValue != metav1.ConditionTrue {
298+
componentReady = false
299+
break
300+
}
298301
}
299-
}
300-
if componentReady {
302+
if componentReady {
303+
condition.SetCondition(v1alpha1.GenericResourceReady, v1alpha1.NoAction, metav1.ConditionTrue)
304+
} else {
305+
condition.SetCondition(v1alpha1.GenericResourceReady, v1alpha1.Wait, metav1.ConditionFalse)
306+
}
307+
} else { // if `readyFields` is not set, we assume the resource is ready
301308
condition.SetCondition(v1alpha1.GenericResourceReady, v1alpha1.NoAction, metav1.ConditionTrue)
302-
} else {
303-
condition.SetCondition(v1alpha1.GenericResourceReady, v1alpha1.Wait, metav1.ConditionFalse)
304309
}
305310
}
306311

0 commit comments

Comments
 (0)