Skip to content

Commit

Permalink
Make ignitionISOInjector overridable (like isoInjector already is) to…
Browse files Browse the repository at this point in the history
… make it mockable for testing
  • Loading branch information
rybnico authored and wikkyk committed Jan 16, 2025
1 parent 00485cd commit e5c1dff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions internal/service/vmservice/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func injectIgnition(ctx context.Context, machineScope *scope.MachineScope, boots
Network: nicData,
}

injector := ignitionISOInjector(machineScope.VirtualMachine, metadata, enricher)
injector := getIgnitionISOInjector(machineScope.VirtualMachine, metadata, enricher)
if err := injector.Inject(ctx, inject.IgnitionFormat); err != nil {
conditions.MarkFalse(machineScope.ProxmoxMachine, infrav1alpha1.VMProvisionedCondition, infrav1alpha1.VMProvisionFailedReason, clusterv1.ConditionSeverityWarning, err.Error())
return errors.Wrap(err, "ignition iso inject failed")
Expand All @@ -140,15 +140,18 @@ func defaultISOInjector(vm *proxmox.VirtualMachine, bootStrapData []byte, metada
}
}

func ignitionISOInjector(vm *proxmox.VirtualMachine, metadata cloudinit.Renderer, enricher *ignition.Enricher) isoInjector {
func defaultIgnitionISOInjector(vm *proxmox.VirtualMachine, metadata cloudinit.Renderer, enricher *ignition.Enricher) isoInjector {
return &inject.ISOInjector{
VirtualMachine: vm,
IgnitionEnricher: enricher,
MetaRenderer: metadata,
}
}

var getISOInjector = defaultISOInjector
var (
getISOInjector = defaultISOInjector
getIgnitionISOInjector = defaultIgnitionISOInjector
)

// getBootstrapData obtains a machine's bootstrap data from the relevant K8s secret and returns the data.
// TODO: Add format return if ignition will be supported.
Expand Down
2 changes: 1 addition & 1 deletion internal/service/vmservice/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func TestDefaultISOInjector(t *testing.T) {
}

func TestIgnitionISOInjector(t *testing.T) {
injector := ignitionISOInjector(newRunningVM(), cloudinit.NewMetadata(biosUUID, "test", "1.2.3", true), &ignition.Enricher{
injector := defaultIgnitionISOInjector(newRunningVM(), cloudinit.NewMetadata(biosUUID, "test", "1.2.3", true), &ignition.Enricher{
BootstrapData: []byte("data"),
Hostname: "test",
})
Expand Down

0 comments on commit e5c1dff

Please sign in to comment.