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

baremetal: Templating OSImage links through Tinkerbell workflow objects #1891

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const (
hardwareName = "{{.hardware_name}}"
ProvisionWorkerNodeTemplate = "provision-worker-node"
PartitionNumber = "{{.partition_number}}"
OSImageURL = "{{.os_image}}"
)

// TemplateClient handles interactions with the Tinkerbell Templates in the Tinkerbell cluster.
Expand Down Expand Up @@ -91,14 +92,14 @@ func (t *TemplateClient) Delete(ctx context.Context, namespacedName types.Namesp
}

// CreateTemplate creates a Tinkerbell Template in the Kubernetes cluster.
func (t *TemplateClient) CreateTemplate(ctx context.Context, namespace, osImageURL string) error {
func (t *TemplateClient) CreateTemplate(ctx context.Context, namespace string) error {
template := &tinkv1alpha1.Template{}
if err := t.tinkclient.Get(ctx, types.NamespacedName{
Name: ProvisionWorkerNodeTemplate,
Namespace: namespace,
}, template); err != nil {
if kerrors.IsNotFound(err) {
data, err := getTemplate(osImageURL)
data, err := getTemplate(OSImageURL)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewWorkflowClient(k8sClient client.Client) *WorkflowClient {
}

// CreateWorkflow creates a new Tinkerbell Workflow resource in the cluster.
func (w *WorkflowClient) CreateWorkflow(ctx context.Context, userData, templateRef string, hardware tink.Hardware) error {
func (w *WorkflowClient) CreateWorkflow(ctx context.Context, userData, templateRef, OSImageURL string, hardware tink.Hardware) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce confusion with the constant, can we name the parameter osImageURL? Otherwise it shadows the constant.

// Construct the Workflow object
ifaceConfig := hardware.Spec.Interfaces[0].DHCP
dnsNameservers := "1.1.1.1"
Expand Down Expand Up @@ -80,6 +80,7 @@ func (w *WorkflowClient) CreateWorkflow(ctx context.Context, userData, templateR
"ns": dnsNameservers,
"default_route": ifaceConfig.IP.Gateway,
"partition_number": w.getPartitionNumber(hardware),
"os_image": OSImageURL,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ func (d *driver) ProvisionServer(ctx context.Context, _ *zap.SugaredLogger, meta
}

// Create template if it doesn't exist
err = d.TemplateClient.CreateTemplate(ctx, d.HardwareRef.Namespace, d.OSImageURL)
err = d.TemplateClient.CreateTemplate(ctx, d.HardwareRef.Namespace)
if err != nil {
return nil, err
}

// Create Workflow to match the template and server
server := tinktypes.Hardware{Hardware: hardware}
if err = d.WorkflowClient.CreateWorkflow(ctx, userdata, client.ProvisionWorkerNodeTemplate, server); err != nil {
if err = d.WorkflowClient.CreateWorkflow(ctx, userdata, client.ProvisionWorkerNodeTemplate, d.OSImageURL, server); err != nil {
return nil, err
}

Expand Down