diff --git a/pkg/providers/vsphere/vmlifecycle/bootstrap_linuxprep.go b/pkg/providers/vsphere/vmlifecycle/bootstrap_linuxprep.go index 998f175ae..15597fbad 100644 --- a/pkg/providers/vsphere/vmlifecycle/bootstrap_linuxprep.go +++ b/pkg/providers/vsphere/vmlifecycle/bootstrap_linuxprep.go @@ -44,7 +44,7 @@ func BootStrapLinuxPrep( var configSpec *vimtypes.VirtualMachineConfigSpec if vAppConfigSpec != nil { configSpec = &vimtypes.VirtualMachineConfigSpec{} - configSpec.VAppConfig = GetOVFVAppConfigForConfigSpec( + configSpec.VAppConfig, err = GetOVFVAppConfigForConfigSpec( config, vAppConfigSpec, bsArgs.BootstrapData.VAppData, @@ -52,5 +52,5 @@ func BootStrapLinuxPrep( bsArgs.TemplateRenderFn) } - return configSpec, customSpec, nil + return configSpec, customSpec, err } diff --git a/pkg/providers/vsphere/vmlifecycle/bootstrap_sysprep.go b/pkg/providers/vsphere/vmlifecycle/bootstrap_sysprep.go index 261010dab..39f69846e 100644 --- a/pkg/providers/vsphere/vmlifecycle/bootstrap_sysprep.go +++ b/pkg/providers/vsphere/vmlifecycle/bootstrap_sysprep.go @@ -76,7 +76,7 @@ func BootstrapSysPrep( var configSpec *vimtypes.VirtualMachineConfigSpec if vAppConfigSpec != nil { configSpec = &vimtypes.VirtualMachineConfigSpec{} - configSpec.VAppConfig = GetOVFVAppConfigForConfigSpec( + configSpec.VAppConfig, err = GetOVFVAppConfigForConfigSpec( config, vAppConfigSpec, bsArgs.BootstrapData.VAppData, @@ -84,7 +84,7 @@ func BootstrapSysPrep( bsArgs.TemplateRenderFn) } - return configSpec, customSpec, nil + return configSpec, customSpec, err } func convertTo(from *vmopv1sysprep.Sysprep, bsArgs *BootstrapArgs) *vimtypes.CustomizationSysprep { diff --git a/pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig.go b/pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig.go index 0873cd93a..5c46b492b 100644 --- a/pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig.go +++ b/pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig.go @@ -5,6 +5,7 @@ package vmlifecycle import ( "context" + "errors" vimtypes "github.com/vmware/govmomi/vim25/types" @@ -17,15 +18,19 @@ func BootstrapVAppConfig( vAppConfigSpec *vmopv1.VirtualMachineBootstrapVAppConfigSpec, bsArgs *BootstrapArgs) (*vimtypes.VirtualMachineConfigSpec, *vimtypes.CustomizationSpec, error) { - configSpec := &vimtypes.VirtualMachineConfigSpec{} - configSpec.VAppConfig = GetOVFVAppConfigForConfigSpec( + var ( + err error + configSpec vimtypes.VirtualMachineConfigSpec + ) + + configSpec.VAppConfig, err = GetOVFVAppConfigForConfigSpec( config, vAppConfigSpec, bsArgs.BootstrapData.VAppData, bsArgs.BootstrapData.VAppExData, bsArgs.TemplateRenderFn) - return configSpec, nil, nil + return &configSpec, nil, err } func GetOVFVAppConfigForConfigSpec( @@ -33,16 +38,15 @@ func GetOVFVAppConfigForConfigSpec( vAppConfigSpec *vmopv1.VirtualMachineBootstrapVAppConfigSpec, vAppData map[string]string, vAppExData map[string]map[string]string, - templateRenderFn TemplateRenderFunc) vimtypes.BaseVmConfigSpec { + templateRenderFn TemplateRenderFunc) (vimtypes.BaseVmConfigSpec, error) { - if config.VAppConfig == nil { - // BMV: Should we really silently return here and below? - return nil + var vAppConfigInfo *vimtypes.VmConfigInfo + if config.VAppConfig != nil { + vAppConfigInfo = config.VAppConfig.GetVmConfigInfo() } - vAppConfigInfo := config.VAppConfig.GetVmConfigInfo() if vAppConfigInfo == nil { - return nil + return nil, errors.New("vAppConfig is not yet available") } if len(vAppConfigSpec.Properties) > 0 { @@ -65,7 +69,7 @@ func GetOVFVAppConfigForConfigSpec( } } - return GetMergedvAppConfigSpec(vAppData, vAppConfigInfo.Property) + return GetMergedvAppConfigSpec(vAppData, vAppConfigInfo.Property), nil } // GetMergedvAppConfigSpec prepares a vApp VmConfigSpec which will set the provided key/value fields. diff --git a/pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig_test.go b/pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig_test.go index c10974352..d53bf1f3e 100644 --- a/pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig_test.go +++ b/pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig_test.go @@ -21,6 +21,7 @@ var _ = Describe("VAppConfig Bootstrap", func() { const key, value = "fooKey", "fooValue" var ( + err error configInfo *vimtypes.VirtualMachineConfigInfo vAppConfigSpec *vmopv1.VirtualMachineBootstrapVAppConfigSpec bsArgs vmlifecycle.BootstrapArgs @@ -53,7 +54,7 @@ var _ = Describe("VAppConfig Bootstrap", func() { Context("GetOVFVAppConfigForConfigSpec", func() { JustBeforeEach(func() { - baseVMConfigSpec = vmlifecycle.GetOVFVAppConfigForConfigSpec( + baseVMConfigSpec, err = vmlifecycle.GetOVFVAppConfigForConfigSpec( configInfo, vAppConfigSpec, bsArgs.VAppData, @@ -61,6 +62,16 @@ var _ = Describe("VAppConfig Bootstrap", func() { bsArgs.TemplateRenderFn) }) + When("config.vAppConfig is nil", func() { + BeforeEach(func() { + configInfo.VAppConfig = nil + }) + It("Should return an error", func() { + Expect(err).To(MatchError("vAppConfig is not yet available")) + Expect(baseVMConfigSpec).To(BeNil()) + }) + }) + Context("Empty input", func() { It("No changes", func() { Expect(baseVMConfigSpec).To(BeNil())