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

🐛 Fix duplicate append of Image.Status fields #878

Merged
merged 1 commit into from
Feb 4, 2025
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: 4 additions & 0 deletions pkg/providers/vsphere/contentlibrary/content_library_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func UpdateVmiWithOvfEnvelope(obj client.Object, ovfEnvelope ovf.Envelope) {

if ovfEnvelope.Disk != nil && len(ovfEnvelope.Disk.Disks) > 0 {
populateImageStatusFromOVFDiskSection(status, ovfEnvelope.Disk)
} else {
status.Disks = nil
}
}

Expand Down Expand Up @@ -107,6 +109,7 @@ func initImageStatusFromOVFVirtualSystem(
}
}

imageStatus.OVFProperties = nil
for _, product := range ovfVirtualSystem.Product {
for _, prop := range product.Property {
// Only show user configurable properties
Expand All @@ -121,6 +124,7 @@ func initImageStatusFromOVFVirtualSystem(
}
}

imageStatus.VMwareSystemProperties = nil
ovfSystemProps := getVmwareSystemPropertiesFromOvf(ovfVirtualSystem)
if len(ovfSystemProps) > 0 {
for k, v := range ovfSystemProps {
Expand Down
10 changes: 10 additions & 0 deletions pkg/providers/vsphere/contentlibrary/content_library_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ var _ = Describe("UpdateVmiWithOvfEnvelope", func() {
Expect(image.Status.Disks[1].Capacity.String()).To(Equal("10Gi"))
})

It("Repeated UpdateVmiWithOvfEnvelope should not duplicated items", func() {
Expect(image.Status.Disks).ToNot(BeEmpty())
Expect(image.Status.OVFProperties).ToNot(BeEmpty())
Expect(image.Status.VMwareSystemProperties).ToNot(BeEmpty())

savedImage := image.DeepCopy()
contentlibrary.UpdateVmiWithOvfEnvelope(image, ovfEnvelope)
Expect(image).To(Equal(savedImage))
})

Context("Image is V1Alpha1Compatible", func() {
BeforeEach(func() {
ovfEnvelope.VirtualSystem.VirtualHardware[0].ExtraConfig = append(ovfEnvelope.VirtualSystem.VirtualHardware[0].ExtraConfig,
Expand Down