Skip to content

Commit

Permalink
Merge pull request #422 from jacobweinstock/fix-iso-url
Browse files Browse the repository at this point in the history
Handle ISO url properly:

## Description

<!--- Please describe what this PR is going to change -->
Workflows and Smee require the ISO url mac address in dash notation. CAPT needs to provide a placeholder for this value so that it can be added by the reconciler.

## Why is this needed

<!--- Link to issue you have raised -->

Fixes: #

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->


## How are existing users impacted? What migration steps/scripts do we need?

<!--- Fixes a bug, unblocks installation, removes a component of the stack etc -->
<!--- Requires a DB migration script, etc. -->


## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
jacobweinstock authored Nov 27, 2024
2 parents f39a5f6 + 23b88d6 commit fb1ed00
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions api/v1beta1/tinkerbellmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,19 @@ type BootOptions struct {
// When this field is set, the controller will create a job.bmc.tinkerbell.org object
// for getting the associated hardware into a CDROM booting state.
// A HardwareRef that contains a spec.BmcRef must be provided.
//
// The format of the ISOURL must be http://$IP:$Port/iso/:macAddress/hook.iso
// The name of the ISO file must have the .iso extension, but the name can be anything.
// The $IP and $Port should generally point to the IP and Port of the Smee server
// as this is where the ISO patching endpoint lives.
// The ":macAddress" is a placeholder for the MAC address of the hardware and
// should be provided exactly as is: ":macAddress".
// +optional
// +kubebuilder:validation:Format=url
ISOURL string `json:"isoURL,omitempty"`

// BootMode is the type of booting that will be done.
// Must be one of "none", "netboot", or "iso".
// +optional
// +kubebuilder:validation:Enum=none;netboot;iso
BootMode BootMode `json:"bootMode,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ spec:
description: BootOptions are options that control the booting of Hardware.
properties:
bootMode:
description: BootMode is the type of booting that will be done.
description: |-
BootMode is the type of booting that will be done.
Must be one of "none", "netboot", or "iso".
enum:
- none
- netboot
Expand All @@ -78,6 +80,13 @@ spec:
When this field is set, the controller will create a job.bmc.tinkerbell.org object
for getting the associated hardware into a CDROM booting state.
A HardwareRef that contains a spec.BmcRef must be provided.
The format of the ISOURL must be http://$IP:$Port/iso/:macAddress/hook.iso
The name of the ISO file must have the .iso extension, but the name can be anything.
The $IP and $Port should generally point to the IP and Port of the Smee server
as this is where the ISO patching endpoint lives.
The ":macAddress" is a placeholder for the MAC address of the hardware and
should be provided exactly as is: ":macAddress".
format: url
type: string
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ spec:
of Hardware.
properties:
bootMode:
description: BootMode is the type of booting that will
be done.
description: |-
BootMode is the type of booting that will be done.
Must be one of "none", "netboot", or "iso".
enum:
- none
- netboot
Expand All @@ -69,6 +70,13 @@ spec:
When this field is set, the controller will create a job.bmc.tinkerbell.org object
for getting the associated hardware into a CDROM booting state.
A HardwareRef that contains a spec.BmcRef must be provided.
The format of the ISOURL must be http://$IP:$Port/iso/:macAddress/hook.iso
The name of the ISO file must have the .iso extension, but the name can be anything.
The $IP and $Port should generally point to the IP and Port of the Smee server
as this is where the ISO patching endpoint lives.
The ":macAddress" is a placeholder for the MAC address of the hardware and
should be provided exactly as is: ":macAddress".
format: url
type: string
type: object
Expand Down
10 changes: 9 additions & 1 deletion controller/machine/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package machine
import (
"errors"
"fmt"
"net/url"
"strings"

"github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1"

Expand Down Expand Up @@ -75,8 +77,14 @@ func (scope *machineReconcileScope) createWorkflow(hw *tinkv1.Hardware) error {
return errISOBootURLRequired
}

u, err := url.Parse(scope.tinkerbellMachine.Spec.BootOptions.ISOURL)
if err != nil {
return fmt.Errorf("boot option isoURL is not parse-able: %w", err)
}

u.Path = strings.Replace(u.Path, ":macAddress", strings.Replace(hw.Spec.Metadata.Instance.ID, ":", "-", 5), 1)
workflow.Spec.BootOptions.ISOURL = u.String()
workflow.Spec.BootOptions.BootMode = tinkv1.BootMode("iso")
workflow.Spec.BootOptions.ISOURL = scope.tinkerbellMachine.Spec.BootOptions.ISOURL
}
}

Expand Down

0 comments on commit fb1ed00

Please sign in to comment.