Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Wait on vAppConfig during async create #817

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/providers/vsphere/vmlifecycle/bootstrap_linuxprep.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func BootStrapLinuxPrep(
var configSpec *vimtypes.VirtualMachineConfigSpec
if vAppConfigSpec != nil {
configSpec = &vimtypes.VirtualMachineConfigSpec{}
configSpec.VAppConfig = GetOVFVAppConfigForConfigSpec(
configSpec.VAppConfig, err = GetOVFVAppConfigForConfigSpec(
config,
vAppConfigSpec,
bsArgs.BootstrapData.VAppData,
bsArgs.BootstrapData.VAppExData,
bsArgs.TemplateRenderFn)
}

return configSpec, customSpec, nil
return configSpec, customSpec, err
}
4 changes: 2 additions & 2 deletions pkg/providers/vsphere/vmlifecycle/bootstrap_sysprep.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ func BootstrapSysPrep(
var configSpec *vimtypes.VirtualMachineConfigSpec
if vAppConfigSpec != nil {
configSpec = &vimtypes.VirtualMachineConfigSpec{}
configSpec.VAppConfig = GetOVFVAppConfigForConfigSpec(
configSpec.VAppConfig, err = GetOVFVAppConfigForConfigSpec(
config,
vAppConfigSpec,
bsArgs.BootstrapData.VAppData,
bsArgs.BootstrapData.VAppExData,
bsArgs.TemplateRenderFn)
}

return configSpec, customSpec, nil
return configSpec, customSpec, err
}

func convertTo(from *vmopv1sysprep.Sysprep, bsArgs *BootstrapArgs) *vimtypes.CustomizationSysprep {
Expand Down
24 changes: 14 additions & 10 deletions pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vmlifecycle

import (
"context"
"errors"

vimtypes "github.com/vmware/govmomi/vim25/types"

Expand All @@ -17,32 +18,35 @@ 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(
config *vimtypes.VirtualMachineConfigInfo,
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 {
Expand All @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion pkg/providers/vsphere/vmlifecycle/bootstrap_vappconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,14 +54,24 @@ var _ = Describe("VAppConfig Bootstrap", func() {
Context("GetOVFVAppConfigForConfigSpec", func() {

JustBeforeEach(func() {
baseVMConfigSpec = vmlifecycle.GetOVFVAppConfigForConfigSpec(
baseVMConfigSpec, err = vmlifecycle.GetOVFVAppConfigForConfigSpec(
configInfo,
vAppConfigSpec,
bsArgs.VAppData,
bsArgs.VAppExData,
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())
Expand Down
Loading