diff --git a/api/v1/runtimecomponent_types.go b/api/v1/runtimecomponent_types.go index 9c875478..b23541d4 100644 --- a/api/v1/runtimecomponent_types.go +++ b/api/v1/runtimecomponent_types.go @@ -17,6 +17,7 @@ limitations under the License. package v1 import ( + "sort" "time" "github.com/application-stacks/runtime-component-operator/common" @@ -1278,6 +1279,17 @@ func (s *RuntimeComponentStatus) SetCondition(c common.StatusCondition) { if !found { s.Conditions = append(s.Conditions, *condition) } + + // Re-sort conditions to prioritize 'Ready' condition + sort.Slice(s.Conditions, func(i, j int) bool { + if s.Conditions[i].GetType() == common.StatusConditionTypeReady { + return true + } + if s.Conditions[j].GetType() == common.StatusConditionTypeReady { + return false + } + return s.Conditions[i].GetType() < s.Conditions[j].GetType() + }) } func (s *RuntimeComponentStatus) UnsetCondition(c common.StatusCondition) { diff --git a/api/v1beta2/runtimecomponent_types.go b/api/v1beta2/runtimecomponent_types.go index 6411a77b..62048ccc 100644 --- a/api/v1beta2/runtimecomponent_types.go +++ b/api/v1beta2/runtimecomponent_types.go @@ -17,6 +17,7 @@ limitations under the License. package v1beta2 import ( + "sort" "time" "github.com/application-stacks/runtime-component-operator/common" @@ -1026,6 +1027,16 @@ func (s *RuntimeComponentStatus) SetCondition(c common.StatusCondition) { if !found { s.Conditions = append(s.Conditions, *condition) } + // Re-sort conditions to prioritize 'Ready' condition + sort.Slice(s.Conditions, func(i, j int) bool { + if s.Conditions[i].GetType() == common.StatusConditionTypeReady { + return true + } + if s.Conditions[j].GetType() == common.StatusConditionTypeReady { + return false + } + return s.Conditions[i].GetType() < s.Conditions[j].GetType() + }) } func convertToCommonStatusConditionType(c StatusConditionType) common.StatusConditionType { diff --git a/utils/reconciler_test.go b/utils/reconciler_test.go index 35acf8f0..5cb68b0d 100644 --- a/utils/reconciler_test.go +++ b/utils/reconciler_test.go @@ -299,7 +299,7 @@ func TestManageError(t *testing.T) { testME := []Test{ {"ManageError Requeue", true, rec.Requeue}, - {"ManageError New Condition Status", corev1.ConditionFalse, runtimecomponent.Status.Conditions[0].Status}, + {"ManageError New Condition Status", corev1.ConditionFalse, runtimecomponent.Status.GetCondition(common.StatusConditionTypeReconciled).GetStatus()}, } verifyTests(testME, t) } @@ -318,7 +318,7 @@ func TestManageSuccess(t *testing.T) { r.ManageSuccess(common.StatusConditionTypeReconciled, runtimecomponent) testMS := []Test{ - {"ManageSuccess New Condition Status", corev1.ConditionTrue, runtimecomponent.Status.Conditions[0].Status}, + {"ManageSuccess New Condition Status", corev1.ConditionTrue, runtimecomponent.Status.GetCondition(common.StatusConditionTypeReconciled).GetStatus()}, } verifyTests(testMS, t) }