Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Prevent BMH from transitioning when an invalid BIOS setting is detected #1889

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions controllers/metal3.io/baremetalhost_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
preprovImageRetryDelay = time.Minute * 5
provisionerNotReadyRetryDelay = time.Second * 30
subResourceNotReadyRetryDelay = time.Second * 60
configurationErrRetryDelay = time.Second * 90
clarifySoftPoweroffFailure = "Continuing with hard poweroff after soft poweroff fails. More details: "
hardwareDataFinalizer = metal3api.BareMetalHostFinalizer + "/hardwareData"
)
Expand Down Expand Up @@ -1128,8 +1129,14 @@ func (r *BareMetalHostReconciler) actionPreparing(prov provisioner.Provisioner,
hfsDirty, hfs, err := r.getHostFirmwareSettings(info)

if err != nil {
// wait until hostFirmwareSettings are ready
return actionContinue{subResourceNotReadyRetryDelay}
switch {
case errors.As(err, &ConfigurationError{}):
// wait for the user to correct the error
return actionContinue{configurationErrRetryDelay}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it different from what we had before? You're only changing the retry delay for 1 to 1.5 minutes. Did you intend to you something else than actionContinue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the operation did not return an error, and there was no retry delay (see line 1892 below).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think on line 1132 the error would be returned in any case.

default:
// wait until hostFirmwareSettings are ready
return actionContinue{subResourceNotReadyRetryDelay}
}
}
if hfsDirty {
prepareData.ActualFirmwareSettings = hfs.Status.Settings.DeepCopy()
Expand Down Expand Up @@ -1882,7 +1889,7 @@ func (r *BareMetalHostReconciler) getHostFirmwareSettings(info *reconcileInfo) (
}

info.log.Info("hostFirmwareSettings not valid", "namespacename", info.request.NamespacedName)
return false, nil, nil
return false, nil, &ConfigurationError{message: "hostFirmwareSettings not valid"}
}

info.log.Info("hostFirmwareSettings no updates", "namespacename", info.request.NamespacedName)
Expand Down
61 changes: 59 additions & 2 deletions controllers/metal3.io/baremetalhost_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -2668,7 +2669,7 @@ func TestHostFirmwareSettings(t *testing.T) {
Scenario: "spec invalid",
Conditions: []metav1.Condition{
{Type: "ChangeDetected", Status: "True", Reason: "Success"},
{Type: "Valid", Status: "False", Reason: "Success"},
{Type: "Valid", Status: "False", Reason: "ConfigurationError"},
},
Dirty: false,
},
Expand All @@ -2687,7 +2688,11 @@ func TestHostFirmwareSettings(t *testing.T) {

dirty, _, err := r.getHostFirmwareSettings(i)
if err != nil {
t.Fatal(err)
if meta.IsStatusConditionFalse(tc.Conditions, string(metal3api.FirmwareSettingsValid)) {
assert.EqualError(t, err, "User configuration error: hostFirmwareSettings not valid")
} else {
t.Fatal(err)
}
}
assert.Equal(t, tc.Dirty, dirty, "dirty flag did not match")
})
Expand Down Expand Up @@ -2809,3 +2814,55 @@ func TestHFSEmptyStatusSettings(t *testing.T) {
},
)
}

// TestHFSInvalidSetting ensures that BMH does not move to the next state
// when a user provides an invalid BIOS settings.
func TestHFSInvalidSetting(t *testing.T) {
host := newDefaultHost(t)
host.Spec.Online = true
host.Spec.ConsumerRef = &corev1.ObjectReference{}
host.Spec.ExternallyProvisioned = false
r := newTestReconciler(host)

waitForProvisioningState(t, r, host, metal3api.StatePreparing)

// Update HFS so host will go through cleaning
hfs := &metal3api.HostFirmwareSettings{}
key := client.ObjectKey{
Namespace: host.ObjectMeta.Namespace, Name: host.ObjectMeta.Name}
if err := r.Get(context.TODO(), key, hfs); err != nil {
t.Fatal(err)
}

hfs.Status = metal3api.HostFirmwareSettingsStatus{
Conditions: []metav1.Condition{
{Type: "ChangeDetected", Status: "True", Reason: "Success"},
{Type: "Valid", Status: "False", Reason: "ConfigurationError"},
},
}

err := r.Update(context.TODO(), hfs)
assert.NoError(t, err)

tryReconcile(t, r, host,
func(host *metal3api.BareMetalHost, result reconcile.Result) bool {
return host.Status.Provisioning.State == metal3api.StatePreparing
},
)

// Correct the setting, it will no longer be blocked
hfs.Status = metal3api.HostFirmwareSettingsStatus{
Conditions: []metav1.Condition{
{Type: "ChangeDetected", Status: "False", Reason: "Success"},
{Type: "Valid", Status: "True", Reason: "Success"},
},
}

err = r.Update(context.TODO(), hfs)
assert.NoError(t, err)
tryReconcile(t, r, host,
func(host *metal3api.BareMetalHost, result reconcile.Result) bool {
return host.Status.Provisioning.State == metal3api.StateAvailable
},
)
}
9 changes: 9 additions & 0 deletions controllers/metal3.io/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ func (e ResolveBMCSecretRefError) Error() string {
e.message)
}

type ConfigurationError struct {
message string
}

func (e ConfigurationError) Error() string {
return fmt.Sprintf("User configuration error: %s",
e.message)
}

// NoDataInSecretError is returned when host configuration
// data were not found in referenced secret.
type NoDataInSecretError struct {
Expand Down