Skip to content

Commit

Permalink
Merge pull request #626 from CecileRobertMichon/fix-image-validation
Browse files Browse the repository at this point in the history
🐛 fix: allow nil image in AzureMachine webhook validation
  • Loading branch information
k8s-ci-robot authored May 15, 2020
2 parents db93854 + b9b11aa commit edaee99
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha3/azureimage_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 2 additions & 5 deletions api/v1alpha3/azureimage_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit edaee99

Please sign in to comment.