@@ -20,6 +20,7 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
"slices"
23
+ "sort"
23
24
"strings"
24
25
"time"
25
26
@@ -31,6 +32,7 @@ import (
31
32
appsv1 "k8s.io/api/apps/v1"
32
33
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
33
34
apierrors "k8s.io/apimachinery/pkg/api/errors"
35
+ "k8s.io/apimachinery/pkg/api/meta"
34
36
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35
37
"k8s.io/apimachinery/pkg/labels"
36
38
"k8s.io/apimachinery/pkg/runtime"
@@ -222,6 +224,8 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *kcm.Manag
222
224
requeue = true
223
225
}
224
226
227
+ setReadyCondition (management )
228
+
225
229
if err := r .Client .Status ().Update (ctx , management ); err != nil {
226
230
errs = errors .Join (errs , fmt .Errorf ("failed to update status for Management %s: %w" , management .Name , err ))
227
231
}
@@ -772,6 +776,33 @@ func updateComponentsStatus(
772
776
}
773
777
}
774
778
779
+ // setReadyCondition updates the Management resource's "Ready" condition based on whether
780
+ // all components are healthy.
781
+ func setReadyCondition (management * kcm.Management ) {
782
+ var failing []string
783
+ for name , comp := range management .Status .Components {
784
+ if ! comp .Success {
785
+ failing = append (failing , name )
786
+ }
787
+ }
788
+
789
+ readyCond := metav1.Condition {
790
+ Type : kcm .ReadyCondition ,
791
+ ObservedGeneration : management .Generation ,
792
+ Status : metav1 .ConditionTrue ,
793
+ Reason : kcm .AllComponentsHealthyReason ,
794
+ Message : "All components are successfully installed." ,
795
+ }
796
+ sort .Strings (failing )
797
+ if len (failing ) > 0 {
798
+ readyCond .Status = metav1 .ConditionFalse
799
+ readyCond .Reason = kcm .NotAllComponentsHealthyReason
800
+ readyCond .Message = fmt .Sprintf ("Components not ready: %v" , failing )
801
+ }
802
+
803
+ meta .SetStatusCondition (& management .Status .Conditions , readyCond )
804
+ }
805
+
775
806
// SetupWithManager sets up the controller with the Manager.
776
807
func (r * ManagementReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
777
808
dc , err := dynamic .NewForConfig (mgr .GetConfig ())
0 commit comments