Skip to content

Commit

Permalink
Add DHCP info to available template data:
Browse files Browse the repository at this point in the history
This enables improved templating of templates.
This was requested by quite a few folks in the
community.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Oct 6, 2023
1 parent b656eeb commit f93f0f9
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion internal/workflow/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,22 @@ func (r *Reconciler) processNewWorkflow(ctx context.Context, logger logr.Logger,

// templateHardwareData defines the data exposed for a Hardware instance to a Template.
type templateHardwareData struct {
Disks []string
Disks []string
Interfaces []netInterface
}

// netInterface defines a network interface for a Hardware instance.
// It is different than v1alpha1.Interface so that we don't couple ourselves to the API,
// especially when we already have a v1alpha2.
type netInterface struct {
MAC string
IP string
Netmask string
Gateway string
Hostname string
VLANID string
Nameservers []string
Timeservers []string
}

// toTemplateHardwareData converts a Hardware instance of templateHardwareData for use in template
Expand All @@ -136,9 +151,33 @@ func toTemplateHardwareData(hardware v1alpha1.Hardware) templateHardwareData {
for _, disk := range hardware.Spec.Disks {
contract.Disks = append(contract.Disks, disk.Device)
}
contract.Interfaces = toNetworkInterface(hardware.Spec.Interfaces)

return contract
}

// toNetworkInterface converts a v1alpha1.Interface to a NetworkInterface.
func toNetworkInterface(h []v1alpha1.Interface) []netInterface {
ni := []netInterface{}
for _, i := range h {
if i.DHCP != nil {
v := netInterface{}
v.MAC = i.DHCP.MAC
if i.DHCP.IP != nil {
v.IP = i.DHCP.IP.Address
v.Netmask = i.DHCP.IP.Netmask
v.Gateway = i.DHCP.IP.Gateway
}
v.Hostname = i.DHCP.Hostname
v.VLANID = i.DHCP.VLANID
v.Nameservers = i.DHCP.NameServers
v.Timeservers = i.DHCP.TimeServers
ni = append(ni, v)
}
}
return ni
}

func (r *Reconciler) processRunningWorkflow(_ context.Context, stored *v1alpha1.Workflow) reconcile.Result {
// Check for global timeout expiration
if r.nowFunc().After(stored.GetStartTime().Add(time.Duration(stored.Status.GlobalTimeout) * time.Second)) {
Expand Down

0 comments on commit f93f0f9

Please sign in to comment.