From 835d14998450b46b383daac848639dc733d3f08c Mon Sep 17 00:00:00 2001 From: Cecile Robert-Michon Date: Fri, 15 May 2020 13:24:17 -0700 Subject: [PATCH 1/2] :bug: fix: allow nil image in AzureMachine webhook validation --- api/v1alpha3/azureimage_validation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1alpha3/azureimage_validation.go b/api/v1alpha3/azureimage_validation.go index 82e44795776..bc3651162e3 100644 --- a/api/v1alpha3/azureimage_validation.go +++ b/api/v1alpha3/azureimage_validation.go @@ -25,7 +25,7 @@ func ValidateImage(image *Image, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} if image == nil { - allErrs = append(allErrs, field.Required(fldPath, "an image must be specified")) + // allow empty image as it is defaulted in the AzureMachine controller return allErrs } From b9b11aae33fe293e2b19a7d2f8cc781e1b130547 Mon Sep 17 00:00:00 2001 From: Cecile Robert-Michon Date: Fri, 15 May 2020 13:36:34 -0700 Subject: [PATCH 2/2] Update azureimage_validation_test.go --- api/v1alpha3/azureimage_validation_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/api/v1alpha3/azureimage_validation_test.go b/api/v1alpha3/azureimage_validation_test.go index 5a198be1f2b..bf1b7ef3cbb 100644 --- a/api/v1alpha3/azureimage_validation_test.go +++ b/api/v1alpha3/azureimage_validation_test.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" ) -func TestImageRequired(t *testing.T) { +func TestImageOptional(t *testing.T) { g := NewWithT(t) type test struct { @@ -34,10 +34,7 @@ func TestImageRequired(t *testing.T) { extension := test{} errs := ValidateImage(extension.Image, field.NewPath("image")) - g.Expect(errs).To(HaveLen(1)) - g.Expect(errs[0].Type).To(Equal(field.ErrorTypeRequired)) - g.Expect(errs[0].Field).To(Equal("image")) - g.Expect(errs[0].Detail).NotTo(BeEmpty()) + g.Expect(errs).To(HaveLen(0)) } func TestImageTooManyDetails(t *testing.T) {