@@ -24,6 +24,7 @@ import (
2424 bootv1alpha1 "github.com/ironcore-dev/boot-operator/api/v1alpha1"
2525 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626 "k8s.io/apimachinery/pkg/runtime"
27+ "k8s.io/client-go/util/retry"
2728 ctrl "sigs.k8s.io/controller-runtime"
2829 "sigs.k8s.io/controller-runtime/pkg/client"
2930 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -90,9 +91,16 @@ func (r *ServerBootConfigurationHTTPReconciler) reconcile(ctx context.Context, l
9091 ukiURL , err := r .constructUKIURL (ctx , config .Spec .Image )
9192 if err != nil {
9293 log .Error (err , "Failed to construct UKI URL" )
93- if patchErr := PatchServerBootConfigWithError (ctx , r .Client ,
94- types.NamespacedName {Name : config .Name , Namespace : config .Namespace }, err ); patchErr != nil {
95- return ctrl.Result {}, fmt .Errorf ("failed to patch state to error: %w (original error: %w)" , patchErr , err )
94+ if patchErr := PatchServerBootConfigCondition (ctx , r .Client ,
95+ types.NamespacedName {Name : config .Name , Namespace : config .Namespace },
96+ metav1.Condition {
97+ Type : HTTPBootReadyConditionType ,
98+ Status : metav1 .ConditionFalse ,
99+ Reason : "UKIURLConstructionFailed" ,
100+ Message : err .Error (),
101+ ObservedGeneration : config .Generation ,
102+ }); patchErr != nil {
103+ return ctrl.Result {}, fmt .Errorf ("failed to patch %s condition: %w (original error: %w)" , HTTPBootReadyConditionType , patchErr , err )
96104 }
97105 return ctrl.Result {}, err
98106 }
@@ -135,37 +143,46 @@ func (r *ServerBootConfigurationHTTPReconciler) reconcile(ctx context.Context, l
135143 return ctrl.Result {}, fmt .Errorf ("failed to get HTTPBoot config: %w" , err )
136144 }
137145
138- if err := r .patchConfigStateFromHTTPState (ctx , httpBootConfig , config ); err != nil {
139- return ctrl.Result {}, fmt .Errorf ("failed to patch server boot config state to %s: %w" , httpBootConfig .Status .State , err )
146+ if err := r .patchHTTPBootReadyConditionFromHTTPState (ctx , httpBootConfig , config ); err != nil {
147+ return ctrl.Result {}, fmt .Errorf ("failed to patch %s condition from HTTPBootConfig state %s: %w" , HTTPBootReadyConditionType , httpBootConfig .Status .State , err )
140148 }
141- log .V (1 ).Info ("Patched server boot config state" )
149+ log .V (1 ).Info ("Patched server boot config condition" , "condition" , HTTPBootReadyConditionType )
142150
143151 log .V (1 ).Info ("Reconciled ServerBootConfiguration" )
144152 return ctrl.Result {}, nil
145153}
146154
147- func (r * ServerBootConfigurationHTTPReconciler ) patchConfigStateFromHTTPState (ctx context.Context , httpBootConfig * bootv1alpha1.HTTPBootConfig , cfg * metalv1alpha1.ServerBootConfiguration ) error {
155+ func (r * ServerBootConfigurationHTTPReconciler ) patchHTTPBootReadyConditionFromHTTPState (ctx context.Context , httpBootConfig * bootv1alpha1.HTTPBootConfig , cfg * metalv1alpha1.ServerBootConfiguration ) error {
148156 key := types.NamespacedName {Name : cfg .Name , Namespace : cfg .Namespace }
149- var cur metalv1alpha1.ServerBootConfiguration
150- if err := r .Get (ctx , key , & cur ); err != nil {
151- return err
152- }
153- base := cur .DeepCopy ()
154-
155- switch httpBootConfig .Status .State {
156- case bootv1alpha1 .HTTPBootConfigStateReady :
157- cur .Status .State = metalv1alpha1 .ServerBootConfigurationStateReady
158- // Remove ImageValidation condition when transitioning to Ready
159- apimeta .RemoveStatusCondition (& cur .Status .Conditions , "ImageValidation" )
160- case bootv1alpha1 .HTTPBootConfigStateError :
161- cur .Status .State = metalv1alpha1 .ServerBootConfigurationStateError
162- }
157+ return retry .RetryOnConflict (retry .DefaultRetry , func () error {
158+ var cur metalv1alpha1.ServerBootConfiguration
159+ if err := r .Get (ctx , key , & cur ); err != nil {
160+ return err
161+ }
162+ base := cur .DeepCopy ()
163163
164- for _ , c := range httpBootConfig .Status .Conditions {
165- apimeta .SetStatusCondition (& cur .Status .Conditions , c )
166- }
164+ cond := metav1.Condition {
165+ Type : HTTPBootReadyConditionType ,
166+ ObservedGeneration : cur .Generation ,
167+ }
168+ switch httpBootConfig .Status .State {
169+ case bootv1alpha1 .HTTPBootConfigStateReady :
170+ cond .Status = metav1 .ConditionTrue
171+ cond .Reason = "BootConfigReady"
172+ cond .Message = "HTTP boot configuration is ready."
173+ case bootv1alpha1 .HTTPBootConfigStateError :
174+ cond .Status = metav1 .ConditionFalse
175+ cond .Reason = "BootConfigError"
176+ cond .Message = "HTTPBootConfig reported an error."
177+ default :
178+ cond .Status = metav1 .ConditionUnknown
179+ cond .Reason = "BootConfigPending"
180+ cond .Message = "Waiting for HTTPBootConfig to become Ready."
181+ }
167182
168- return r .Status ().Patch (ctx , & cur , client .MergeFrom (base ))
183+ apimeta .SetStatusCondition (& cur .Status .Conditions , cond )
184+ return r .Status ().Patch (ctx , & cur , client .MergeFrom (base ))
185+ })
169186}
170187
171188// getSystemUUIDFromServer fetches the UUID from the referenced Server object.
0 commit comments