Skip to content

Commit

Permalink
WIP: add booting options to Workflow spec:
Browse files Browse the repository at this point in the history
Add spec field and functionality for
setting the allowPXE field in hardware.

Add spec field and functionality for
creating a job.bmc.tinkerbell.org object to
get the Hardware into a netboot state.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Sep 19, 2024
1 parent 9631f39 commit 4ebc9e5
Show file tree
Hide file tree
Showing 13 changed files with 512 additions and 1,200 deletions.
2 changes: 1 addition & 1 deletion Tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PROTOC_GEN_GO_GRPC := $(TOOLS_DIR)/protoc-gen-go-grpc
PROTOC_GEN_GO_VER := v1.28
PROTOC_GEN_GO := $(TOOLS_DIR)/protoc-gen-go

CONTROLLER_GEN_VER := v0.15
CONTROLLER_GEN_VER := v0.16.3
CONTROLLER_GEN := $(TOOLS_DIR)/controller-gen-$(CONTROLLER_GEN_VER)

KUSTOMIZE_VER := v4.5
Expand Down
64 changes: 59 additions & 5 deletions api/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
type WorkflowState string

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

// WorkflowSpec defines the desired state of Workflow.
Expand All @@ -24,6 +25,27 @@ type WorkflowSpec struct {

// A mapping of template devices to hadware mac addresses
HardwareMap map[string]string `json:"hardwareMap,omitempty"`

// ToggleNetworkBoot uses the HardwareRef and changes the all network interfaces to boot from network
// before running the workflow and sets all network interfaces to not boot from the network after a successful workflow.
// ToggleNetworkBoot bool `json:"toggleNetworkBoot,omitempty"`

// NetbootBeforeWorkflow uses the HardwareRef and the bmcRef in the hardware to boot the machine from the network before running the workflow.
// NetbootBeforeWorkflow bool `json:"netbootBeforeWorkflow,omitempty"`

// BootOpts is a set of options to be used when netbooting the hardware.
BootOpts BootOpts `json:"bootOpts,omitempty"`
}

type BootOpts struct {
// ToggleHardware indicates whether the controller should toggle the field in the associated hardware for allowing PXE booting.
// This will be enabled before a Workflow is executed and disabled after the Workflow has completed successfully.
// A HardwareRef must be provided.
ToggleHardware bool `json:"toggleHardware,omitempty"`
// OneTimeNetboot indicates whether the controller should create a job.bmc.tinkerbell.org object for getting the associated hardware
// into a netbooting state.
// A HardwareRef that contains a spec.BmcRef must be provided.
OneTimeNetboot bool `json:"oneTimeNetboot,omitempty"`
}

// WorkflowStatus defines the observed state of Workflow.
Expand All @@ -36,6 +58,38 @@ type WorkflowStatus struct {

// Tasks are the tasks to be completed
Tasks []Task `json:"tasks,omitempty"`

// ToggleHardware indicates whether the controller has successfully toggled the network boot setting
// in the associated hardware.
ToggleHardware *Status `json:"toggleHardware,omitempty"`

// OneTimeNetboot indicates whether the controller has successfully netbooted the associated hardware.
OneTimeNetboot *Status `json:"oneTimeNetboot,omitempty"`
}

// Wanted to use metav1.Status but kubebuilder errors with, "must apply listType to an array, found".
type Status struct {
// Status of the operation.
// One of: "Success" or "Failure".
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
// +optional
Status string `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"`
// A human-readable description of the status of this operation.
// +optional
Message string `json:"message,omitempty" protobuf:"bytes,3,opt,name=message"`
// A machine-readable description of why this operation is in the
// "Failure" status. If this value is empty there
// is no information available. A Reason clarifies an HTTP status
// code but does not override it.
// +optional
Reason metav1.StatusReason `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason,casttype=StatusReason"`
// Extended data associated with the reason. Each reason may define its
// own extended details. This field is optional and the data returned
// is not guaranteed to conform to any schema except that defined by
// the reason type.
// +optional
// +listType=atomic
// Details *metav1.StatusDetails `json:"details,omitempty" protobuf:"bytes,5,opt,name=details"`
}

// Task represents a series of actions to be completed by a worker.
Expand Down
41 changes: 41 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: ee48893a270147348e3edc6c1a03de0e
commit: e7f8d366f5264595bcc4cd4139af9973
8 changes: 2 additions & 6 deletions config/crd/bases/tinkerbell.org_hardware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
controller-gen.kubebuilder.io/version: v0.16.3
name: hardware.tinkerbell.org
spec:
group: tinkerbell.org
Expand Down Expand Up @@ -421,9 +421,7 @@ spec:
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand Down Expand Up @@ -530,16 +528,14 @@ spec:
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
storageDevices:
description: StorageDevices is a list of storage devices that will be available in the OSIE.
items:
description: "StorageDevice describes a storage device path that will be present in the OSIE.\nStorageDevices must be valid Linux paths. They should not contain partitions.\n\n\nGood\n\n\n\t/dev/sda\n\t/dev/nvme0n1\n\n\nBad (contains partitions)\n\n\n\t/dev/sda1\n\t/dev/nvme0n1p1\n\n\nBad (invalid Linux path)\n\n\n\t\\dev\\sda"
description: "StorageDevice describes a storage device path that will be present in the OSIE.\nStorageDevices must be valid Linux paths. They should not contain partitions.\n\nGood\n\n\t/dev/sda\n\t/dev/nvme0n1\n\nBad (contains partitions)\n\n\t/dev/sda1\n\t/dev/nvme0n1p1\n\nBad (invalid Linux path)\n\n\t\\dev\\sda"
pattern: ^(/[^/ ]*)+/?$
type: string
type: array
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/tinkerbell.org_osies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
controller-gen.kubebuilder.io/version: v0.16.3
name: osies.tinkerbell.org
spec:
group: tinkerbell.org
Expand Down
6 changes: 3 additions & 3 deletions config/crd/bases/tinkerbell.org_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
controller-gen.kubebuilder.io/version: v0.16.3
name: templates.tinkerbell.org
spec:
group: tinkerbell.org
Expand Down Expand Up @@ -134,7 +134,7 @@ spec:
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\n\nRead-only bind mount bound to /data\n\n\n\t/etc/data:/data:ro\n\n\nWritable volume name bound to /data\n\n\n\tshared_volume:/data\n\n\nSee https://docs.docker.com/storage/volumes/ for additional details."
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."
type: string
type: array
required:
Expand All @@ -155,7 +155,7 @@ spec:
Volumes to be mounted on all actions. If an action specifies the same volume it will take
precedence.
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\n\nRead-only bind mount bound to /data\n\n\n\t/etc/data:/data:ro\n\n\nWritable volume name bound to /data\n\n\n\tshared_volume:/data\n\n\nSee https://docs.docker.com/storage/volumes/ for additional details."
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."
type: string
type: array
type: object
Expand Down
67 changes: 60 additions & 7 deletions config/crd/bases/tinkerbell.org_workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
controller-gen.kubebuilder.io/version: v0.16.3
name: workflows.tinkerbell.org
spec:
group: tinkerbell.org
Expand Down Expand Up @@ -49,6 +49,22 @@ spec:
spec:
description: WorkflowSpec defines the desired state of Workflow.
properties:
bootOpts:
description: BootOpts is a set of options to be used when netbooting the hardware.
properties:
oneTimeNetboot:
description: |-
OneTimeNetboot indicates whether the controller should create a job.bmc.tinkerbell.org object for getting the associated hardware
into a netbooting state.
A HardwareRef that contains a spec.BmcRef must be provided.
type: boolean
toggleHardware:
description: |-
ToggleHardware indicates whether the controller should toggle the field in the associated hardware for allowing PXE booting.
This will be enabled before a Workflow is executed and disabled after the Workflow has completed successfully.
A HardwareRef must be provided.
type: boolean
type: object
hardwareMap:
additionalProperties:
type: string
Expand All @@ -68,6 +84,26 @@ spec:
description: GlobalTimeout represents the max execution time
format: int64
type: integer
oneTimeNetboot:
description: OneTimeNetboot indicates whether the controller has successfully netbooted the associated hardware.
properties:
message:
description: A human-readable description of the status of this operation.
type: string
reason:
description: |-
A machine-readable description of why this operation is in the
"Failure" status. If this value is empty there
is no information available. A Reason clarifies an HTTP status
code but does not override it.
type: string
status:
description: |-
Status of the operation.
One of: "Success" or "Failure".
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
type: string
type: object
state:
description: State is the state of the workflow in Tinkerbell.
type: string
Expand Down Expand Up @@ -131,6 +167,28 @@ spec:
- worker
type: object
type: array
toggleHardware:
description: |-
ToggleHardware indicates whether the controller has successfully toggled the network boot setting
in the associated hardware.
properties:
message:
description: A human-readable description of the status of this operation.
type: string
reason:
description: |-
A machine-readable description of why this operation is in the
"Failure" status. If this value is empty there
is no information available. A Reason clarifies an HTTP status
code but does not override it.
type: string
status:
description: |-
Status of the operation.
One of: "Success" or "Failure".
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
type: string
type: object
type: object
type: object
served: true
Expand Down Expand Up @@ -186,9 +244,7 @@ spec:
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand All @@ -199,7 +255,6 @@ spec:
TemplateParams are a list of key-value pairs that are injected into templates at render
time. TemplateParams are exposed to templates using a top level .Params key.
For example, TemplateParams = {"foo": "bar"}, the foo key can be accessed via .Params.foo.
type: object
templateRef:
Expand All @@ -212,9 +267,7 @@ spec:
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand Down Expand Up @@ -291,7 +344,7 @@ spec:
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\n\nRead-only bind mount bound to /data\n\n\n\t/etc/data:/data:ro\n\n\nWritable volume name bound to /data\n\n\n\tshared_volume:/data\n\n\nSee https://docs.docker.com/storage/volumes/ for additional details."
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."
type: string
type: array
required:
Expand Down
Loading

0 comments on commit 4ebc9e5

Please sign in to comment.