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 ISO mounting to Workflow boot options #1008

Merged
merged 13 commits into from
Oct 14, 2024
46 changes: 32 additions & 14 deletions api/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ type (
WorkflowState string
WorkflowConditionType string
TemplateRendering string
BootMode string
)

const (
WorkflowStateWaiting = WorkflowState("STATE_WAITING")
WorkflowStatePending = WorkflowState("STATE_PENDING")
WorkflowStateRunning = WorkflowState("STATE_RUNNING")
WorkflowStateSuccess = WorkflowState("STATE_SUCCESS")
WorkflowStateFailed = WorkflowState("STATE_FAILED")
WorkflowStateTimeout = WorkflowState("STATE_TIMEOUT")
WorkflowStatePreparing = WorkflowState("STATE_PREPARING")
WorkflowStatePending = WorkflowState("STATE_PENDING")
WorkflowStateRunning = WorkflowState("STATE_RUNNING")
WorkflowStatePost = WorkflowState("STATE_POST")
WorkflowStateSuccess = WorkflowState("STATE_SUCCESS")
WorkflowStateFailed = WorkflowState("STATE_FAILED")
WorkflowStateTimeout = WorkflowState("STATE_TIMEOUT")

NetbootJobFailed WorkflowConditionType = "NetbootJobFailed"
NetbootJobComplete WorkflowConditionType = "NetbootJobComplete"
Expand All @@ -34,6 +36,9 @@ const (

TemplateRenderingSuccessful TemplateRendering = "successful"
TemplateRenderingFailed TemplateRendering = "failed"

BootModeNetboot BootMode = "netboot"
BootModeISO BootMode = "iso"
)

// +kubebuilder:subresource:status
Expand Down Expand Up @@ -86,18 +91,31 @@ type BootOptions struct {
// A HardwareRef must be provided.
// +optional
ToggleAllowNetboot bool `json:"toggleAllowNetboot,omitempty"`
// OneTimeNetboot indicates whether the controller should create a job.bmc.tinkerbell.org object for getting the associated hardware
// into a netbooting state.

// ISOURL is the URL of the ISO that will be one-time booted. 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.
// +optional
OneTimeNetboot bool `json:"oneTimeNetboot,omitempty"`
// +kubebuilder:validation:Format=url
ISOURL string `json:"isoURL,omitempty"`

// BootMode is the type of booting that will be done.
// +optional
// +kubebuilder:validation:Enum=netboot;iso
BootMode BootMode `json:"bootMode,omitempty"`
}

// BootOptionsStatus holds the state of any boot options.
type BootOptionsStatus struct {
// OneTimeNetboot holds the state of a specific job.bmc.tinkerbell.org object created.
// Only used when BootOptions.OneTimeNetboot is true.
OneTimeNetboot OneTimeNetbootStatus `json:"netbootJob,omitempty"`
// AllowNetboot holds the state of the the controller's interactions with the allowPXE field in a Hardware object.
AllowNetboot AllowNetbootStatus `json:"allowNetboot,omitempty"`
// Jobs holds the state of any job.bmc.tinkerbell.org objects created.
Jobs map[string]JobStatus `json:"jobs,omitempty"`
}

type AllowNetbootStatus struct {
ToggledTrue bool `json:"toggledTrue,omitempty"`
ToggledFalse bool `json:"toggledFalse,omitempty"`
}

// WorkflowStatus defines the observed state of a Workflow.
Expand Down Expand Up @@ -130,8 +148,8 @@ type WorkflowStatus struct {
Conditions []WorkflowCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

// OneTimeNetbootStatus holds the state of a specific job.bmc.tinkerbell.org object created.
type OneTimeNetbootStatus struct {
// JobStatus holds the state of a specific job.bmc.tinkerbell.org object created.
type JobStatus struct {
// UID is the UID of the job.bmc.tinkerbell.org object associated with this workflow.
// This is used to uniquely identify the job.bmc.tinkerbell.org object, as
// all objects for a specific Hardware/Machine.bmc.tinkerbell.org are created with the same name.
Expand Down
56 changes: 39 additions & 17 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions cmd/tink-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"github.com/spf13/viper"
"github.com/tinkerbell/tink/internal/deprecated/controller"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -27,6 +28,7 @@
MetricsAddr string
ProbeAddr string
EnableLeaderElection bool
LogLevel int
}

func (c *Config) AddFlags(fs *pflag.FlagSet) {
Expand All @@ -40,6 +42,7 @@
fs.BoolVar(&c.EnableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
fs.IntVar(&c.LogLevel, "log-level", 0, "Log level (0: info, 1: debug)")

Check warning on line 45 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L45

Added line #L45 was not covered by tests
}

func main() {
Expand All @@ -52,22 +55,34 @@
func NewRootCommand() *cobra.Command {
var config Config

zlog, err := zap.NewProduction()
if err != nil {
panic(err)
}
logger := zapr.NewLogger(zlog).WithName("github.com/tinkerbell/tink")

cmd := &cobra.Command{
Use: "tink-controller",
PreRunE: func(cmd *cobra.Command, _ []string) error {
zlog, err := zap.NewProduction()
if err != nil {
panic(err)

Check warning on line 63 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L61-L63

Added lines #L61 - L63 were not covered by tests
}
logger := zapr.NewLogger(zlog).WithName("github.com/tinkerbell/tink")

Check warning on line 65 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L65

Added line #L65 was not covered by tests
viper, err := createViper(logger)
if err != nil {
return fmt.Errorf("config init: %w", err)
}
return applyViper(viper, cmd)
},
RunE: func(cmd *cobra.Command, _ []string) error {
zc := zap.NewProductionConfig()
switch config.LogLevel {
case 1:
zc.Level = zap.NewAtomicLevelAt(zapcore.Level(-1))
default:
zc.Level = zap.NewAtomicLevelAt(zapcore.Level(0))

Check warning on line 78 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L73-L78

Added lines #L73 - L78 were not covered by tests
}
zlog, err := zc.Build()
if err != nil {
panic(err)

Check warning on line 82 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L80-L82

Added lines #L80 - L82 were not covered by tests
}

logger := zapr.NewLogger(zlog).WithName("github.com/tinkerbell/tink")

Check warning on line 85 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L85

Added line #L85 was not covered by tests
logger.Info("Starting controller version " + version)

ccfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
Expand Down
60 changes: 38 additions & 22 deletions config/crd/bases/tinkerbell.org_workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@
bootOptions:
description: BootOptions are options that control the booting of Hardware.
properties:
oneTimeNetboot:
bootMode:
description: BootMode is the type of booting that will be done.
enum:
- netboot
- iso
type: string
isoURL:
description: |-
OneTimeNetboot indicates whether the controller should create a job.bmc.tinkerbell.org object for getting the associated hardware
into a netbooting state.
ISOURL is the URL of the ISO that will be one-time booted. When this field is set, the controller will create a job.bmc.tinkerbell.org object

Check warning on line 69 in config/crd/bases/tinkerbell.org_workflows.yaml

View workflow job for this annotation

GitHub Actions / Verify

[line-length] line too long (165 > 160 characters)
for getting the associated hardware into a CDROM booting state.
A HardwareRef that contains a spec.BmcRef must be provided.
type: boolean
format: url
type: string
toggleAllowNetboot:
description: |-
ToggleAllowNetboot indicates whether the controller should toggle the field in the associated hardware for allowing PXE booting.
Expand All @@ -89,27 +96,36 @@
bootOptions:
description: BootOptions holds the state of any boot options.
properties:
netbootJob:
description: |-
OneTimeNetboot holds the state of a specific job.bmc.tinkerbell.org object created.
Only used when BootOptions.OneTimeNetboot is true.
allowNetboot:
description: AllowNetboot holds the state of the the controller's interactions with the allowPXE field in a Hardware object.
properties:
complete:
description: Complete indicates whether the created job.bmc.tinkerbell.org has reported its conditions as complete.
toggledFalse:
type: boolean
existingJobDeleted:
description: |-
ExistingJobDeleted indicates whether any existing job.bmc.tinkerbell.org was deleted.
The name of each job.bmc.tinkerbell.org object created by the controller is the same, so only one can exist at a time.
Using the same name was chosen so that there is only ever 1 job.bmc.tinkerbell.org per Hardware/Machine.bmc.tinkerbell.org.
This makes clean up easier and we dont just orphan jobs every time.
toggledTrue:
type: boolean
uid:
description: |-
UID is the UID of the job.bmc.tinkerbell.org object associated with this workflow.
This is used to uniquely identify the job.bmc.tinkerbell.org object, as
all objects for a specific Hardware/Machine.bmc.tinkerbell.org are created with the same name.
type: string
type: object
jobs:
additionalProperties:
description: JobStatus holds the state of a specific job.bmc.tinkerbell.org object created.
properties:
complete:
description: Complete indicates whether the created job.bmc.tinkerbell.org has reported its conditions as complete.
type: boolean
existingJobDeleted:
description: |-
ExistingJobDeleted indicates whether any existing job.bmc.tinkerbell.org was deleted.
The name of each job.bmc.tinkerbell.org object created by the controller is the same, so only one can exist at a time.
Using the same name was chosen so that there is only ever 1 job.bmc.tinkerbell.org per Hardware/Machine.bmc.tinkerbell.org.
This makes clean up easier and we dont just orphan jobs every time.
type: boolean
uid:
description: |-
UID is the UID of the job.bmc.tinkerbell.org object associated with this workflow.
This is used to uniquely identify the job.bmc.tinkerbell.org object, as
all objects for a specific Hardware/Machine.bmc.tinkerbell.org are created with the same name.
type: string
type: object
description: Jobs holds the state of any job.bmc.tinkerbell.org objects created.
type: object
type: object
conditions:
Expand Down Expand Up @@ -369,7 +385,7 @@
volumes:
description: Volumes defines the volumes to mount into the container.
items:
description: "Volume is a specification for mounting a volume in an action. Volumes take the form\n{SRC-VOLUME-NAME | SRC-HOST-DIR}:TGT-CONTAINER-DIR:OPTIONS. When specifying a VOLUME-NAME that\ndoes not exist it will be created for you. Examples:\n\nRead-only bind mount bound to /data\n\n\t/etc/data:/data:ro\n\nWritable volume name bound to /data\n\n\tshared_volume:/data\n\nSee https://docs.docker.com/storage/volumes/ for additional details."

Check warning on line 388 in config/crd/bases/tinkerbell.org_workflows.yaml

View workflow job for this annotation

GitHub Actions / Verify

[line-length] line too long (477 > 160 characters)
type: string
type: array
required:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.22.2
require (
github.com/Masterminds/sprig/v3 v3.3.0
github.com/avast/retry-go v3.0.0+incompatible
github.com/cenkalti/backoff/v4 v4.3.0
github.com/distribution/reference v0.6.0
github.com/docker/docker v27.3.1+incompatible
github.com/equinix-labs/otel-init-go v0.0.9
Expand Down Expand Up @@ -36,7 +37,6 @@ require (
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
knative.dev/pkg v0.0.0-20240917091217-aaab500c26c4
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/yaml v1.4.0
Expand All @@ -48,7 +48,6 @@ require (
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand Down Expand Up @@ -134,6 +133,7 @@ require (
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
Loading
Loading