Skip to content

Commit 5483611

Browse files
Merge pull request #367 from ahreehong/use-allowpxe
2 parents e27df5d + 2a14073 commit 5483611

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

controllers/machine_reconcile_scope.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5051
const (
5152
providerIDPlaceholder = "PROVIDER_ID"
52-
inUse = "in_use"
53-
provisioned = "provisioned"
5453
)
5554

5655
var (
@@ -107,7 +106,20 @@ func (scope *machineReconcileScope) addFinalizer() error {
107106
}
108107

109108
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
111123
}
112124

113125
type 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

controllers/tinkerbellmachine_controller_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ func validHardware(name, uuid, ip string, options ...testOptions) *tinkv1.Hardwa
190190
Address: ip,
191191
},
192192
},
193+
Netboot: &tinkv1.Netboot{
194+
AllowPXE: ptr.To(true),
195+
},
193196
},
194197
},
195198
Metadata: &tinkv1.HardwareMetadata{
@@ -417,7 +420,7 @@ func Test_Machine_reconciliation_with_available_hardware(t *testing.T) {
417420
g.Expect(updatedMachine.Status.Addresses).NotTo(BeEmpty(), "Machine status should be updated on every reconciliation")
418421
})
419422

420-
t.Run("in_use_states_are_not_set", func(t *testing.T) {
423+
t.Run("allowPXE_is_not_updated", func(t *testing.T) {
421424
t.Parallel()
422425
g := NewWithT(t)
423426

@@ -428,10 +431,7 @@ func Test_Machine_reconciliation_with_available_hardware(t *testing.T) {
428431

429432
updatedHardware := &tinkv1.Hardware{}
430433
g.Expect(client.Get(ctx, hardwareNamespacedName, updatedHardware)).To(Succeed())
431-
if diff := cmp.Diff(updatedHardware.Spec.Metadata.State, ""); diff != "" {
432-
t.Errorf(diff)
433-
}
434-
if diff := cmp.Diff(updatedHardware.Spec.Metadata.Instance.State, ""); diff != "" {
434+
if diff := cmp.Diff(updatedHardware.Spec.Interfaces[0].Netboot.AllowPXE, ptr.To(true)); diff != "" {
435435
t.Errorf(diff)
436436
}
437437
})
@@ -554,7 +554,7 @@ func Test_Machine_reconciliation_workflow_complete(t *testing.T) {
554554
g.Expect(updatedMachine.Status.Addresses).NotTo(BeEmpty(), "Machine status should be updated on every reconciliation")
555555
})
556556

557-
t.Run("in_use_states_are_set", func(t *testing.T) {
557+
t.Run("allowPXE_is_updated", func(t *testing.T) {
558558
t.Parallel()
559559
g := NewWithT(t)
560560

@@ -565,10 +565,7 @@ func Test_Machine_reconciliation_workflow_complete(t *testing.T) {
565565

566566
updatedHardware := &tinkv1.Hardware{}
567567
g.Expect(client.Get(ctx, hardwareNamespacedName, updatedHardware)).To(Succeed())
568-
if diff := cmp.Diff(updatedHardware.Spec.Metadata.State, "in_use"); diff != "" {
569-
t.Errorf(diff)
570-
}
571-
if diff := cmp.Diff(updatedHardware.Spec.Metadata.Instance.State, "provisioned"); diff != "" {
568+
if diff := cmp.Diff(updatedHardware.Spec.Interfaces[0].Netboot.AllowPXE, ptr.To(false)); diff != "" {
572569
t.Errorf(diff)
573570
}
574571
})

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/tinkerbell/cluster-api-provider-tinkerbell
22

3-
go 1.21
3+
go 1.21.0
44

55
toolchain go1.21.2
66

0 commit comments

Comments
 (0)