From 559b04c4af24169efa4580e4b62d7bb29f168ceb Mon Sep 17 00:00:00 2001 From: Sai Diliyaer Date: Fri, 20 Dec 2024 15:29:17 -0500 Subject: [PATCH] Skip ISO images in unified storage quota validator --- .../validation/unifiedstoragequota_validator.go | 5 +++++ .../unifiedstoragequota_validator_unit_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/webhooks/unifiedstoragequota/validation/unifiedstoragequota_validator.go b/webhooks/unifiedstoragequota/validation/unifiedstoragequota_validator.go index 5119dd451..938c9bec9 100644 --- a/webhooks/unifiedstoragequota/validation/unifiedstoragequota_validator.go +++ b/webhooks/unifiedstoragequota/validation/unifiedstoragequota_validator.go @@ -178,6 +178,11 @@ func (h *RequestedCapacityHandler) HandleCreate(ctx *pkgctx.WebhookRequestContex return CapacityResponse{Response: webhook.Errored(http.StatusBadRequest, fmt.Errorf("unsupported image kind %s", vm.Spec.Image.Kind))} } + // Skip ISO images as they don't have boot disks. + if imageStatus.Type == "ISO" { + return CapacityResponse{Response: webhook.Allowed("")} + } + if len(imageStatus.Disks) < 1 || imageStatus.Disks[0].Capacity == nil { return CapacityResponse{Response: webhook.Errored(http.StatusNotFound, errors.New("boot disk not found in image status"))} } diff --git a/webhooks/unifiedstoragequota/validation/unifiedstoragequota_validator_unit_test.go b/webhooks/unifiedstoragequota/validation/unifiedstoragequota_validator_unit_test.go index 391fcad89..367473b10 100644 --- a/webhooks/unifiedstoragequota/validation/unifiedstoragequota_validator_unit_test.go +++ b/webhooks/unifiedstoragequota/validation/unifiedstoragequota_validator_unit_test.go @@ -682,6 +682,17 @@ func testRequestedCapacityHandlerHandleCreate() { }) }) + When("image type is ISO", func() { + BeforeEach(func() { + vmi.Status.Type = "ISO" + }) + + It("should write StatusOK code and an empty RequestedCapacity to the response", func() { + Expect(resp.Allowed).To(BeTrue()) + Expect(int(resp.Result.Code)).To(Equal(http.StatusOK)) + }) + }) + When("disks section is empty in image status", func() { It("should write StatusNotFound code and an empty RequestedCapacity to the response", func() { Expect(resp.Allowed).To(BeFalse())