Skip to content

Commit

Permalink
Add CustomDeploy to metal3machinetemplate webhook
Browse files Browse the repository at this point in the history
This mirrors the code in metal3machine webhook.  We are loosening
the requirement on Image: when using CustomDeploy, Image is optional.

Signed-off-by: Honza Pokorny <honza@redhat.com>
  • Loading branch information
honza committed Nov 12, 2024
1 parent 2073b84 commit cda3d94
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 cda3d94

Please sign in to comment.