Skip to content

Commit 62ba5ab

Browse files
Move from labels to annotations:
Labels were used to be able to query hardware. This is not something CAPT is doing. As such, moved to annotations. Signed-off-by: Jacob Weinstock <[email protected]>
1 parent 666d364 commit 62ba5ab

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

controller/machine/hardware.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const (
2525
// that given hardware takes part of at least one workflow.
2626
HardwareOwnerNamespaceLabel = "v1alpha1.tinkerbell.org/ownerNamespace"
2727

28-
// HardwareInUseLabel signifies that the Hardware with this label has be provisioned by CAPT.
29-
HardwareInUseLabel = "v1alpha1.tinkerbell.org/inUse"
28+
// HardwareProvisionedAnnotation signifies that the Hardware with this annotation has be provisioned by CAPT.
29+
HardwareProvisionedAnnotation = "v1alpha1.tinkerbell.org/provisioned"
3030
)
3131

3232
var (
@@ -74,14 +74,18 @@ func hardwareIP(hardware *tinkv1.Hardware) (string, error) {
7474
}
7575

7676
// patchHardwareStates patches a hardware's metadata and instance states.
77-
func (scope *machineReconcileScope) patchHardwareLabel(hw *tinkv1.Hardware, labels map[string]string) error {
77+
func (scope *machineReconcileScope) patchHardwareAnnotations(hw *tinkv1.Hardware, annotations map[string]string) error {
7878
patchHelper, err := patch.NewHelper(hw, scope.client)
7979
if err != nil {
8080
return fmt.Errorf("initializing patch helper for selected hardware: %w", err)
8181
}
8282

83-
for k, v := range labels {
84-
hw.ObjectMeta.Labels[k] = v
83+
if hw.ObjectMeta.Annotations == nil {
84+
hw.ObjectMeta.Annotations = map[string]string{}
85+
}
86+
87+
for k, v := range annotations {
88+
hw.ObjectMeta.Annotations[k] = v
8589
}
8690

8791
if err := patchHelper.Patch(scope.ctx, hw); err != nil {
@@ -274,7 +278,7 @@ func (scope *machineReconcileScope) releaseHardware(hw *tinkv1.Hardware) error {
274278

275279
delete(hw.ObjectMeta.Labels, HardwareOwnerNameLabel)
276280
delete(hw.ObjectMeta.Labels, HardwareOwnerNamespaceLabel)
277-
delete(hw.ObjectMeta.Labels, HardwareInUseLabel)
281+
delete(hw.ObjectMeta.Annotations, HardwareProvisionedAnnotation)
278282
/*
279283
// setting the AllowPXE=true indicates to Smee that this hardware should be allowed
280284
// to netboot. FYI, this is not authoritative.

controller/machine/scope.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,21 @@ func (scope *machineReconcileScope) Reconcile() error {
127127

128128
func (scope *machineReconcileScope) reconcile(hw *tinkv1.Hardware) error {
129129
// If the workflow has completed the TinkerbellMachine is ready.
130-
if v, found := hw.ObjectMeta.Labels[HardwareInUseLabel]; found && v == "true" {
130+
if v, found := hw.ObjectMeta.GetAnnotations()[HardwareProvisionedAnnotation]; found && v == "true" {
131131
scope.log.Info("Marking TinkerbellMachine as Ready")
132132
scope.tinkerbellMachine.Status.Ready = true
133133
}
134134

135135
wf, err := scope.ensureTemplateAndWorkflow(hw)
136+
if err != nil {
137+
if errors.Is(err, &errRequeueRequested{}) {
138+
return nil
139+
}
136140

137-
switch {
138-
case errors.Is(err, &errRequeueRequested{}):
139-
return nil
140-
case err != nil:
141141
return fmt.Errorf("ensure template and workflow returned: %w", err)
142142
}
143143

144-
s := wf.GetCurrentActionState()
145-
if s == tinkv1.WorkflowStateFailed || s == tinkv1.WorkflowStateTimeout {
144+
if wf.Status.State == tinkv1.WorkflowStateFailed || wf.Status.State == tinkv1.WorkflowStateTimeout {
146145
return errWorkflowFailed
147146
}
148147

@@ -153,7 +152,7 @@ func (scope *machineReconcileScope) reconcile(hw *tinkv1.Hardware) error {
153152
scope.log.Info("Marking TinkerbellMachine as Ready")
154153
scope.tinkerbellMachine.Status.Ready = true
155154

156-
if err := scope.patchHardwareLabel(hw, map[string]string{HardwareInUseLabel: "true"}); err != nil {
155+
if err := scope.patchHardwareAnnotations(hw, map[string]string{HardwareProvisionedAnnotation: "true"}); err != nil {
157156
return fmt.Errorf("failed to patch hardware: %w", err)
158157
}
159158

controller/machine/workflow.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package machine
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1"
@@ -12,7 +13,10 @@ import (
1213
)
1314

1415
// errWorkflowFailed is the error returned when the workflow fails.
15-
var errWorkflowFailed = fmt.Errorf("workflow failed")
16+
var errWorkflowFailed = errors.New("workflow failed")
17+
18+
// errISOBootURLRequired is the error returned when the isoURL is required for iso boot mode.
19+
var errISOBootURLRequired = errors.New("iso boot mode requires an isoURL")
1620

1721
func (scope *machineReconcileScope) getWorkflow() (*tinkv1.Workflow, error) {
1822
namespacedName := types.NamespacedName{
@@ -68,8 +72,9 @@ func (scope *machineReconcileScope) createWorkflow(hw *tinkv1.Hardware) error {
6872
workflow.Spec.BootOptions.BootMode = tinkv1.BootMode("netboot")
6973
case v1beta1.BootMode("iso"):
7074
if scope.tinkerbellMachine.Spec.BootOptions.ISOURL == "" {
71-
return fmt.Errorf("iso boot mode requires an isoURL")
75+
return errISOBootURLRequired
7276
}
77+
7378
workflow.Spec.BootOptions.BootMode = tinkv1.BootMode("iso")
7479
workflow.Spec.BootOptions.ISOURL = scope.tinkerbellMachine.Spec.BootOptions.ISOURL
7580
}

0 commit comments

Comments
 (0)