@@ -28,6 +28,7 @@ import (
28
28
"text/template"
29
29
30
30
"k8s.io/apimachinery/pkg/labels"
31
+ "k8s.io/utils/ptr"
31
32
"sigs.k8s.io/controller-runtime/pkg/client"
32
33
33
34
corev1 "k8s.io/api/core/v1"
@@ -49,8 +50,6 @@ import (
49
50
50
51
const (
51
52
providerIDPlaceholder = "PROVIDER_ID"
52
- inUse = "in_use"
53
- provisioned = "provisioned"
54
53
)
55
54
56
55
var (
@@ -107,7 +106,20 @@ func (scope *machineReconcileScope) addFinalizer() error {
107
106
}
108
107
109
108
func 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
111
123
}
112
124
113
125
type errRequeueRequested struct {}
@@ -184,7 +196,7 @@ func (scope *machineReconcileScope) reconcile(hw *tinkv1.Hardware) error {
184
196
return nil
185
197
}
186
198
187
- if err := scope .patchHardwareStates (hw , inUse , provisioned ); err != nil {
199
+ if err := scope .patchHardwareStates (hw , false ); err != nil {
188
200
return fmt .Errorf ("failed to patch hardware: %w" , err )
189
201
}
190
202
@@ -195,14 +207,17 @@ func (scope *machineReconcileScope) reconcile(hw *tinkv1.Hardware) error {
195
207
}
196
208
197
209
// 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 {
199
211
patchHelper , err := patch .NewHelper (hw , scope .client )
200
212
if err != nil {
201
213
return fmt .Errorf ("initializing patch helper for selected hardware: %w" , err )
202
214
}
203
215
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
+ }
206
221
207
222
if err := patchHelper .Patch (scope .ctx , hw ); err != nil {
208
223
return fmt .Errorf ("patching Hardware object: %w" , err )
@@ -716,12 +731,15 @@ func (scope *machineReconcileScope) releaseHardware(hardware *tinkv1.Hardware) e
716
731
717
732
delete (hardware .ObjectMeta .Labels , HardwareOwnerNameLabel )
718
733
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.
721
736
// 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
+ }
725
743
726
744
controllerutil .RemoveFinalizer (hardware , infrastructurev1 .MachineFinalizer )
727
745
0 commit comments