Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add templateOverride field to override the default workflowTemplate #130

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1beta1/tinkerbellmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ type TinkerbellMachineSpec struct {
// +optional
ImageLookupOSVersion string `json:"imageLookupOSVersion,omitempty"`

// TemplateOverride overrides the default Tinkerbell template used by CAPT.
// You can learn more about Tinkerbell templates here: https://docs.tinkerbell.org/templates/
// +optional
TemplateOverride string `json:"templateOverride,omitempty"`

// Those fields are set programmatically, but they cannot be re-constructed from "state of the world", so
// we put them in spec instead of status.
HardwareName string `json:"hardwareName,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ spec:
type: string
providerID:
type: string
templateOverride:
description: 'TemplateOverride overrides the default Tinkerbell template
used by CAPT. You can learn more about Tinkerbell templates here:
https://docs.tinkerbell.org/templates/'
type: string
type: object
status:
description: TinkerbellMachineStatus defines the observed state of TinkerbellMachine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ spec:
type: string
providerID:
type: string
templateOverride:
description: 'TemplateOverride overrides the default Tinkerbell
template used by CAPT. You can learn more about Tinkerbell
templates here: https://docs.tinkerbell.org/templates/'
type: string
type: object
required:
- spec
Expand Down
45 changes: 24 additions & 21 deletions controllers/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,35 @@ func (mrc *machineReconcileContext) createTemplate(hardware *tinkv1.Hardware) er
return ErrHardwareMissingDiskConfiguration
}

targetDisk := hardware.Status.Disks[0].Device
targetDevice := firstPartitionFromDevice(targetDisk)
templateData := mrc.tinkerbellMachine.Spec.TemplateOverride
if templateData == "" {
targetDisk := hardware.Status.Disks[0].Device
targetDevice := firstPartitionFromDevice(targetDisk)

imageURL, err := mrc.imageURL()
if err != nil {
return fmt.Errorf("failed to generate imageURL: %w", err)
}
imageURL, err := mrc.imageURL()
if err != nil {
return fmt.Errorf("failed to generate imageURL: %w", err)
}

metadataIP := os.Getenv("TINKERBELL_IP")
if metadataIP == "" {
metadataIP = "192.168.1.1"
}
metadataIP := os.Getenv("TINKERBELL_IP")
if metadataIP == "" {
metadataIP = "192.168.1.1"
}

metadataURL := fmt.Sprintf("http://%s:50061", metadataIP)
metadataURL := fmt.Sprintf("http://%s:50061", metadataIP)

workflowTemplate := templates.WorkflowTemplate{
Name: mrc.tinkerbellMachine.Name,
MetadataURL: metadataURL,
ImageURL: imageURL,
DestDisk: targetDisk,
DestPartition: targetDevice,
}
workflowTemplate := templates.WorkflowTemplate{
Name: mrc.tinkerbellMachine.Name,
MetadataURL: metadataURL,
ImageURL: imageURL,
DestDisk: targetDisk,
DestPartition: targetDevice,
}

templateData, err := workflowTemplate.Render()
if err != nil {
return fmt.Errorf("rendering template: %w", err)
templateData, err = workflowTemplate.Render()
if err != nil {
return fmt.Errorf("rendering template: %w", err)
}
}

templateObject := &tinkv1.Template{
Expand Down