Skip to content

Commit

Permalink
templating the OSImageURL
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-rafraf committed Jan 6, 2025
1 parent fadb8b7 commit 6bd4b2c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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 {
// 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

0 comments on commit 6bd4b2c

Please sign in to comment.