@@ -28,6 +28,7 @@ import (
2828 "text/template"
2929
3030 "k8s.io/apimachinery/pkg/labels"
31+ "k8s.io/utils/ptr"
3132 "sigs.k8s.io/controller-runtime/pkg/client"
3233
3334 corev1 "k8s.io/api/core/v1"
@@ -49,8 +50,6 @@ import (
4950
5051const (
5152 providerIDPlaceholder = "PROVIDER_ID"
52- inUse = "in_use"
53- provisioned = "provisioned"
5453)
5554
5655var (
@@ -107,7 +106,20 @@ func (scope *machineReconcileScope) addFinalizer() error {
107106}
108107
109108func isHardwareReady (hw * tinkv1.Hardware ) bool {
110- return hw .Spec .Metadata .State == inUse && hw .Spec .Metadata .Instance .State == provisioned
109+ // if allowpxe false for all interface, hardware ready
110+ if len (hw .Spec .Interfaces ) == 0 {
111+ return false
112+ }
113+
114+ for _ , ifc := range hw .Spec .Interfaces {
115+ if ifc .Netboot != nil {
116+ if * ifc .Netboot .AllowPXE {
117+ return false
118+ }
119+ }
120+ }
121+
122+ return true
111123}
112124
113125type errRequeueRequested struct {}
@@ -184,7 +196,7 @@ func (scope *machineReconcileScope) reconcile(hw *tinkv1.Hardware) error {
184196 return nil
185197 }
186198
187- if err := scope .patchHardwareStates (hw , inUse , provisioned ); err != nil {
199+ if err := scope .patchHardwareStates (hw , false ); err != nil {
188200 return fmt .Errorf ("failed to patch hardware: %w" , err )
189201 }
190202
@@ -195,14 +207,17 @@ func (scope *machineReconcileScope) reconcile(hw *tinkv1.Hardware) error {
195207}
196208
197209// patchHardwareStates patches a hardware's metadata and instance states.
198- func (scope * machineReconcileScope ) patchHardwareStates (hw * tinkv1.Hardware , mdState , iState string ) error {
210+ func (scope * machineReconcileScope ) patchHardwareStates (hw * tinkv1.Hardware , allowpxe bool ) error {
199211 patchHelper , err := patch .NewHelper (hw , scope .client )
200212 if err != nil {
201213 return fmt .Errorf ("initializing patch helper for selected hardware: %w" , err )
202214 }
203215
204- hw .Spec .Metadata .State = mdState
205- hw .Spec .Metadata .Instance .State = iState
216+ for _ , ifc := range hw .Spec .Interfaces {
217+ if ifc .Netboot != nil {
218+ ifc .Netboot .AllowPXE = ptr .To (allowpxe )
219+ }
220+ }
206221
207222 if err := patchHelper .Patch (scope .ctx , hw ); err != nil {
208223 return fmt .Errorf ("patching Hardware object: %w" , err )
@@ -716,12 +731,15 @@ func (scope *machineReconcileScope) releaseHardware(hardware *tinkv1.Hardware) e
716731
717732 delete (hardware .ObjectMeta .Labels , HardwareOwnerNameLabel )
718733 delete (hardware .ObjectMeta .Labels , HardwareOwnerNamespaceLabel )
719- // setting these Metadata.State and Metadata.Instance.State = "" indicates to Boots
720- // that this hardware should be allowed to netboot. FYI, this is not authoritative.
734+ // setting the AllowPXE=true indicates to Smee that this hardware should be allowed
735+ // to netboot. FYI, this is not authoritative.
721736 // Other hardware values can be set to prohibit netbooting of a machine.
722- // See this Boots function for the logic around this: https://github.com/tinkerbell/boots/blob/main/job/dhcp.go#L115
723- hardware .Spec .Metadata .State = ""
724- hardware .Spec .Metadata .Instance .State = ""
737+ // See this Boots function for the logic around this: https://github.com/tinkerbell/smee/blob/main/internal/ipxe/script/ipxe.go#L112
738+ for _ , ifc := range hardware .Spec .Interfaces {
739+ if ifc .Netboot != nil {
740+ ifc .Netboot .AllowPXE = ptr .To (true )
741+ }
742+ }
725743
726744 controllerutil .RemoveFinalizer (hardware , infrastructurev1 .MachineFinalizer )
727745
0 commit comments