From 8170a8aed050aa56eac5bc573ab5f52616092465 Mon Sep 17 00:00:00 2001 From: Mohamed Rafraf Date: Thu, 2 Jan 2025 16:01:39 +0100 Subject: [PATCH] templating the OSImageURL --- .../provider/baremetal/plugins/tinkerbell/client/template.go | 5 +++-- .../provider/baremetal/plugins/tinkerbell/client/workflow.go | 3 ++- .../provider/baremetal/plugins/tinkerbell/driver.go | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/template.go b/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/template.go index c5baf8ad1..a72e914a5 100644 --- a/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/template.go +++ b/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/template.go @@ -60,6 +60,7 @@ const ( hardwareDisk1 = "{{ index .Hardware.Disks 0 }}" hardwareName = "{{.hardware_name}}" ProvisionWorkerNodeTemplate = "provision-worker-node" + OSImageURL = "{{.os_image}}" ) // TemplateClient handles interactions with the Tinkerbell Templates in the Tinkerbell cluster. @@ -90,14 +91,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 } diff --git a/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/workflow.go b/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/workflow.go index da3d4bd3c..8c9eb88fb 100644 --- a/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/workflow.go +++ b/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/workflow.go @@ -44,7 +44,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" @@ -73,6 +73,7 @@ func (w *WorkflowClient) CreateWorkflow(ctx context.Context, userData, templateR "cidr": convertNetmaskToCIDR(ifaceConfig.IP), "ns": dnsNameservers, "default_route": ifaceConfig.IP.Gateway, + "os_image": OSImageURL, }, }, } diff --git a/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/driver.go b/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/driver.go index 575063852..4b1e162a4 100644 --- a/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/driver.go +++ b/pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/driver.go @@ -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 }