Skip to content

Commit

Permalink
Only set vmPathName when using ISO image
Browse files Browse the repository at this point in the history
The storage policy datastore query is only needed for ISO images.
  • Loading branch information
dougm committed Jul 18, 2024
1 parent ba73bb7 commit c1b683e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/providers/vsphere/vmprovider_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ func (vs *vSphereVMProvider) vmCreatePathName(
vcClient *vcclient.Client,
createArgs *VMCreateArgs) error {

if len(vmCtx.VM.Spec.Cdrom) == 0 {
return nil // only needed when deploying ISO library items
}
if createArgs.StorageProfileID == "" {
return nil
}
Expand All @@ -343,8 +346,6 @@ func (vs *vSphereVMProvider) vmCreatePathName(
return nil
}

// TODO: we should only do this when deploying ISO library items

vc := vcClient.VimClient()

pc, err := pbm.NewClient(vmCtx, vc)
Expand Down
18 changes: 18 additions & 0 deletions pkg/providers/vsphere/vmprovider_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func vmTests() {
propName = "config.name"
propPowerState = "runtime.powerState"
propExtraConfig = "config.extraConfig"
propPathName = "config.files.vmPathName"
)
var (
err error
Expand Down Expand Up @@ -382,6 +383,16 @@ func vmTests() {
}
})
})
When("getting "+propPathName, func() {
BeforeEach(func() {
propertyPaths = []string{propPathName}
})
It("should not be set", func() {
Expect(err).ToNot(HaveOccurred())
Expect(result).To(HaveLen(1))
Expect(result[propName]).To(BeNil()) // should only be set if cdrom is present
})
})
})

Context("VM Class has no ConfigSpec", func() {
Expand Down Expand Up @@ -2096,6 +2107,13 @@ func vmTests() {
vm.Spec.Image.Kind = cvmiKind
vm.Spec.Image.Name = clusterVMImage.Name
vm.Spec.StorageClass = ctx.StorageClassName
vm.Spec.Cdrom = []vmopv1.VirtualMachineCdromSpec{{
Name: "cdrom0",
Image: vmopv1.VirtualMachineImageRef{
Name: cvmiKind,
Kind: clusterVMImage.Name,
},
}}
})

Context("return config", func() {
Expand Down

0 comments on commit c1b683e

Please sign in to comment.