@@ -106,9 +106,16 @@ func (r *ServerBootConfigurationPXEReconciler) reconcile(ctx context.Context, lo
106106
107107 kernelURL , initrdURL , squashFSURL , err := r .getImageDetailsFromConfig (ctx , bootConfig )
108108 if err != nil {
109- if patchErr := PatchServerBootConfigWithError (ctx , r .Client ,
110- types.NamespacedName {Name : bootConfig .Name , Namespace : bootConfig .Namespace }, err ); patchErr != nil {
111- return ctrl.Result {}, fmt .Errorf ("failed to patch server boot config state: %w (original error: %w)" , patchErr , err )
109+ if patchErr := PatchServerBootConfigCondition (ctx , r .Client ,
110+ types.NamespacedName {Name : bootConfig .Name , Namespace : bootConfig .Namespace },
111+ metav1.Condition {
112+ Type : IPXEBootReadyConditionType ,
113+ Status : metav1 .ConditionFalse ,
114+ Reason : "ImageDetailsFailed" ,
115+ Message : err .Error (),
116+ ObservedGeneration : bootConfig .Generation ,
117+ }); patchErr != nil {
118+ return ctrl.Result {}, fmt .Errorf ("failed to patch %s condition: %w (original error: %w)" , IPXEBootReadyConditionType , patchErr , err )
112119 }
113120 return ctrl.Result {}, err
114121 }
@@ -153,32 +160,44 @@ func (r *ServerBootConfigurationPXEReconciler) reconcile(ctx context.Context, lo
153160 return ctrl.Result {}, fmt .Errorf ("failed to get IPXE config: %w" , err )
154161 }
155162
156- if err := r .patchConfigStateFromIPXEState (ctx , config , bootConfig ); err != nil {
157- return ctrl.Result {}, fmt .Errorf ("failed to patch server boot config state to %s: %w" , config .Status .State , err )
163+ if err := r .patchIPXEBootReadyConditionFromIPXEState (ctx , config , bootConfig ); err != nil {
164+ return ctrl.Result {}, fmt .Errorf ("failed to patch %s condition from IPXEBootConfig state %s: %w" , IPXEBootReadyConditionType , config .Status .State , err )
158165 }
159- log .V (1 ).Info ("Patched server boot config state" )
166+ log .V (1 ).Info ("Patched server boot config condition" , "condition" , IPXEBootReadyConditionType )
160167
161168 log .V (1 ).Info ("Reconciled ServerBootConfiguration" )
162169 return ctrl.Result {}, nil
163170}
164171
165- func (r * ServerBootConfigurationPXEReconciler ) patchConfigStateFromIPXEState (ctx context.Context , config * v1alpha1.IPXEBootConfig , bootConfig * metalv1alpha1.ServerBootConfiguration ) error {
166- bootConfigBase := bootConfig .DeepCopy ()
172+ func (r * ServerBootConfigurationPXEReconciler ) patchIPXEBootReadyConditionFromIPXEState (ctx context.Context , config * v1alpha1.IPXEBootConfig , bootConfig * metalv1alpha1.ServerBootConfiguration ) error {
173+ key := types.NamespacedName {Name : bootConfig .Name , Namespace : bootConfig .Namespace }
174+ var cur metalv1alpha1.ServerBootConfiguration
175+ if err := r .Get (ctx , key , & cur ); err != nil {
176+ return err
177+ }
178+ base := cur .DeepCopy ()
167179
180+ cond := metav1.Condition {
181+ Type : IPXEBootReadyConditionType ,
182+ ObservedGeneration : cur .Generation ,
183+ }
168184 switch config .Status .State {
169185 case v1alpha1 .IPXEBootConfigStateReady :
170- bootConfig .Status . State = metalv1alpha1 . ServerBootConfigurationStateReady
171- // Remove ImageValidation condition when transitioning to Ready
172- apimeta . RemoveStatusCondition ( & bootConfig . Status . Conditions , "ImageValidation" )
186+ cond .Status = metav1 . ConditionTrue
187+ cond . Reason = "BootConfigReady"
188+ cond . Message = "IPXE boot configuration is ready."
173189 case v1alpha1 .IPXEBootConfigStateError :
174- bootConfig .Status .State = metalv1alpha1 .ServerBootConfigurationStateError
175- }
176-
177- for _ , c := range config .Status .Conditions {
178- apimeta .SetStatusCondition (& bootConfig .Status .Conditions , c )
190+ cond .Status = metav1 .ConditionFalse
191+ cond .Reason = "BootConfigError"
192+ cond .Message = "IPXEBootConfig reported an error."
193+ default :
194+ cond .Status = metav1 .ConditionUnknown
195+ cond .Reason = "BootConfigPending"
196+ cond .Message = "Waiting for IPXEBootConfig to become Ready."
179197 }
180198
181- return r .Status ().Patch (ctx , bootConfig , client .MergeFrom (bootConfigBase ))
199+ apimeta .SetStatusCondition (& cur .Status .Conditions , cond )
200+ return r .Status ().Patch (ctx , & cur , client .MergeFrom (base ))
182201}
183202
184203func (r * ServerBootConfigurationPXEReconciler ) getSystemUUIDFromBootConfig (ctx context.Context , config * metalv1alpha1.ServerBootConfiguration ) (string , error ) {
0 commit comments