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 2, 2025
1 parent 049efb4 commit 8170a8a
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 @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
},
},
}
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 8170a8a

Please sign in to comment.