Skip to content

Commit

Permalink
Merge pull request #2085 from honza/webhook-template
Browse files Browse the repository at this point in the history
🐛 Add CustomDeploy to metal3machinetemplate webhook
  • Loading branch information
metal3-io-bot authored Nov 13, 2024
2 parents 2073b84 + cda3d94 commit 79aff95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/v1beta1/metal3machinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func (c *Metal3MachineTemplate) ValidateDelete() (admission.Warnings, error) {
func (c *Metal3MachineTemplate) validate() error {
var allErrs field.ErrorList

allErrs = append(allErrs, c.Spec.Template.Spec.Image.Validate(*field.NewPath("Spec", "Template", "Spec", "Image"))...)
if c.Spec.Template.Spec.CustomDeploy == nil || c.Spec.Template.Spec.CustomDeploy.Method == "" {
allErrs = append(allErrs, c.Spec.Template.Spec.Image.Validate(*field.NewPath("Spec", "Template", "Spec", "Image"))...)
}

if len(allErrs) == 0 {
return nil
Expand Down
20 changes: 20 additions & 0 deletions api/v1beta1/metal3machinetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ func TestMetal3MachineTemplateValidation(t *testing.T) {
validIso.Spec.Template.Spec.Image.Checksum = ""
validIso.Spec.Template.Spec.Image.DiskFormat = ptr.To(LiveISODiskFormat)

validCustomDeploy := &Metal3MachineTemplate{
ObjectMeta: metav1.ObjectMeta{
Namespace: "foo",
},
Spec: Metal3MachineTemplateSpec{
Template: Metal3MachineTemplateResource{
Spec: Metal3MachineSpec{
CustomDeploy: &CustomDeploy{
Method: "install_great_stuff",
},
},
},
},
}

tests := []struct {
name string
expectErr bool
Expand All @@ -83,6 +98,11 @@ func TestMetal3MachineTemplateValidation(t *testing.T) {
expectErr: false,
c: validIso,
},
{
name: "should succeed with customDeploy",
expectErr: false,
c: validCustomDeploy,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 79aff95

Please sign in to comment.