Skip to content

Commit

Permalink
Update naming and organization of status struct:
Browse files Browse the repository at this point in the history
Make the spec and status fields for boot options
the same so they are logically correlated.

Change global state from WorkflowStatePreparing to
WorkflowStateWaiting. This follows Kubernetes Pod
container states.
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-states

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Sep 26, 2024
1 parent 2975038 commit 7084d48
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 271 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/workflow_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (w *Workflow) getTaskActionInfo() taskInfo {
INNER:
for ai, action := range task.Actions {
// Find the first non-successful action
switch action.Status { //nolint:exhaustive // WorkflowStatePreparing is only used in Workflows not Actions.
switch action.Status { //nolint:exhaustive // WorkflowStateWaiting is only used in Workflows not Actions.
case WorkflowStateSuccess:
actionIndex++
continue
Expand Down
41 changes: 26 additions & 15 deletions api/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ func init() {
type (
WorkflowState string
WorkflowConditionType string
TemplateRendering string
)

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

NetbootJobFailed WorkflowConditionType = "NetbootJobFailed"
NetbootJobComplete WorkflowConditionType = "NetbootJobComplete"
Expand All @@ -30,6 +31,9 @@ const (
ToggleAllowNetbootTrue WorkflowConditionType = "AllowNetbootTrue"
ToggleAllowNetbootFalse WorkflowConditionType = "AllowNetbootFalse"
TemplateRenderedSuccess WorkflowConditionType = "TemplateRenderedSuccess"

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

// +kubebuilder:subresource:status
Expand Down Expand Up @@ -71,12 +75,12 @@ type WorkflowSpec struct {
// A mapping of template devices to hadware mac addresses.
HardwareMap map[string]string `json:"hardwareMap,omitempty"`

// BootOpts are options that control the booting of Hardware.
BootOpts BootOpts `json:"bootOpts,omitempty"`
// BootOptions are options that control the booting of Hardware.
BootOptions BootOptions `json:"bootOptions,omitempty"`
}

// BootOpts are options that control the booting of Hardware.
type BootOpts struct {
// BootOptions are options that control the booting of Hardware.
type BootOptions struct {
// ToggleAllowNetboot 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.
Expand All @@ -89,6 +93,13 @@ type BootOpts struct {
OneTimeNetboot bool `json:"oneTimeNetboot,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"`
}

// WorkflowStatus defines the observed state of a Workflow.
type WorkflowStatus struct {
// State is the current overall state of the Workflow.
Expand All @@ -97,13 +108,12 @@ type WorkflowStatus struct {
// CurrentAction is the action that is currently in the running state.
CurrentAction string `json:"currentAction,omitempty"`

// Job holds the state of a specific job.bmc.tinkerbell.org object created.
// Only used when BootOpts.OneTimeNetboot is true.
Job JobStatus `json:"jobStatus,omitempty"`
// BootOptions holds the state of any boot options.
BootOptions BootOptionsStatus `json:"bootOptions,omitempty"`

// TemplateRendering indicates whether the template was rendered successfully.
// Possible values are "successful" or "failed" or "unknown".
TemplateRendering string `json:"templateRending,omitempty"`
TemplateRendering TemplateRendering `json:"templateRending,omitempty"`

// GlobalTimeout represents the max execution time.
GlobalTimeout int64 `json:"globalTimeout,omitempty"`
Expand All @@ -120,7 +130,8 @@ type WorkflowStatus struct {
Conditions []WorkflowCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

type JobStatus struct {
// OneTimeNetbootStatus holds the state of a specific job.bmc.tinkerbell.org object created.
type OneTimeNetbootStatus 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
58 changes: 37 additions & 21 deletions api/v1alpha1/zz_generated.deepcopy.go

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

52 changes: 28 additions & 24 deletions config/crd/bases/tinkerbell.org_workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ spec:
spec:
description: WorkflowSpec defines the desired state of Workflow.
properties:
bootOpts:
description: BootOpts are options that control the booting of Hardware.
bootOptions:
description: BootOptions are options that control the booting of Hardware.
properties:
oneTimeNetboot:
description: |-
Expand Down Expand Up @@ -86,6 +86,32 @@ spec:
status:
description: WorkflowStatus defines the observed state of a Workflow.
properties:
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.
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
type: object
conditions:
description: Conditions are the latest available observations of an object's current state.
items:
Expand Down Expand Up @@ -120,28 +146,6 @@ spec:
description: GlobalTimeout represents the max execution time.
format: int64
type: integer
jobStatus:
description: |-
Job holds the state of a specific job.bmc.tinkerbell.org object created.
Only used when BootOpts.OneTimeNetboot is true.
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
state:
description: State is the current overall state of the Workflow.
type: string
Expand Down
12 changes: 6 additions & 6 deletions internal/deprecated/workflow/bootops.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (

// handleExistingJob ensures that an existing job.bmc.tinkerbell.org is removed.
func handleExistingJob(ctx context.Context, cc client.Client, wf *v1alpha1.Workflow) (reconcile.Result, error) {
if wf.Status.Job.ExistingJobDeleted {
if wf.Status.BootOptions.OneTimeNetboot.ExistingJobDeleted {
return reconcile.Result{}, nil
}
name := fmt.Sprintf(bmcJobName, wf.Spec.HardwareRef)
Expand All @@ -36,16 +36,16 @@ func handleExistingJob(ctx context.Context, cc client.Client, wf *v1alpha1.Workf
}
return reconcile.Result{Requeue: true}, nil
}
wf.Status.Job.ExistingJobDeleted = true
wf.Status.BootOptions.OneTimeNetboot.ExistingJobDeleted = true

return reconcile.Result{Requeue: true}, nil
}

func handleJobCreation(ctx context.Context, cc client.Client, wf *v1alpha1.Workflow) (reconcile.Result, error) {
if wf.Status.Job.UID == "" && wf.Status.Job.ExistingJobDeleted {
if wf.Status.BootOptions.OneTimeNetboot.UID == "" && wf.Status.BootOptions.OneTimeNetboot.ExistingJobDeleted {
existingJob := &rufio.Job{}
if err := cc.Get(ctx, client.ObjectKey{Name: fmt.Sprintf(bmcJobName, wf.Spec.HardwareRef), Namespace: wf.Namespace}, existingJob); err == nil {
wf.Status.Job.UID = existingJob.GetUID()
wf.Status.BootOptions.OneTimeNetboot.UID = existingJob.GetUID()
return reconcile.Result{Requeue: true}, nil

Check warning on line 49 in internal/deprecated/workflow/bootops.go

View check run for this annotation

Codecov / codecov/patch

internal/deprecated/workflow/bootops.go#L48-L49

Added lines #L48 - L49 were not covered by tests
}
hw := &v1alpha1.Hardware{ObjectMeta: metav1.ObjectMeta{Name: wf.Spec.HardwareRef, Namespace: wf.Namespace}}
Expand Down Expand Up @@ -80,7 +80,7 @@ func handleJobCreation(ctx context.Context, cc client.Client, wf *v1alpha1.Workf
}

func handleJobComplete(ctx context.Context, cc client.Client, wf *v1alpha1.Workflow) (reconcile.Result, error) {
if !wf.Status.Job.Complete && wf.Status.Job.UID != "" && wf.Status.Job.ExistingJobDeleted {
if !wf.Status.BootOptions.OneTimeNetboot.Complete && wf.Status.BootOptions.OneTimeNetboot.UID != "" && wf.Status.BootOptions.OneTimeNetboot.ExistingJobDeleted {
existingJob := &rufio.Job{}
jobName := fmt.Sprintf(bmcJobName, wf.Spec.HardwareRef)
if err := cc.Get(ctx, client.ObjectKey{Name: jobName, Namespace: wf.Namespace}, existingJob); err != nil {
Expand All @@ -105,7 +105,7 @@ func handleJobComplete(ctx context.Context, cc client.Client, wf *v1alpha1.Workf
Time: &metav1.Time{Time: metav1.Now().UTC()},
})
wf.Status.State = v1alpha1.WorkflowStatePending
wf.Status.Job.Complete = true
wf.Status.BootOptions.OneTimeNetboot.Complete = true
return reconcile.Result{Requeue: true}, nil
}
if !wf.Status.HasCondition(v1alpha1.NetbootJobRunning, metav1.ConditionTrue) {
Expand Down
Loading

0 comments on commit 7084d48

Please sign in to comment.