Skip to content

Commit c9a2fa3

Browse files
committed
Add validation to ensure incompatable values arn't used
Web hook to ensure bmh.spec.Online can't be set to False if disablePowerOff is enabled Signed-off-by: Derek Higgins <derekh@redhat.com>
1 parent e812dd6 commit c9a2fa3

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

apis/metal3.io/v1alpha1/baremetalhost_validation.go

+11
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (host *BareMetalHost) validateHost() []error {
6767
errs = append(errs, annotationErrors...)
6868
}
6969

70+
if err := validatePowerStatus(host); err != nil {
71+
errs = append(errs, err)
72+
}
73+
7074
return errs
7175
}
7276

@@ -350,3 +354,10 @@ func (host *BareMetalHost) validateCrossNamespaceSecretReferences() []error {
350354
}
351355
return errs
352356
}
357+
358+
func validatePowerStatus(host *BareMetalHost) error {
359+
if host.Spec.DisablePowerOff && !host.Spec.Online {
360+
return fmt.Errorf("node can't simultaneously have online set to false and have power off disabled")
361+
}
362+
return nil
363+
}

apis/metal3.io/v1alpha1/baremetalhost_validation_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,26 @@ func TestValidateCreate(t *testing.T) {
770770
oldBMH: nil,
771771
wantedErr: "", // Should be valid
772772
},
773+
{
774+
name: "disablePowerOff",
775+
newBMH: &BareMetalHost{
776+
Spec: BareMetalHostSpec{
777+
DisablePowerOff: true,
778+
Online: true,
779+
},
780+
},
781+
wantedErr: "",
782+
},
783+
{
784+
name: "disablePowerOffErr",
785+
newBMH: &BareMetalHost{
786+
Spec: BareMetalHostSpec{
787+
DisablePowerOff: true,
788+
Online: false,
789+
},
790+
},
791+
wantedErr: "node can't simultaneously have online set to false and have power off disabled",
792+
},
773793
}
774794

775795
for _, tt := range tests {

0 commit comments

Comments
 (0)