Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cb79aee
remove Available() method from BareMetalHost
dhellmann Dec 7, 2020
3e04aaf
remove HasError method from host type
dhellmann Dec 8, 2020
5ef617a
move error handling methods from host to private functions
dhellmann Dec 8, 2020
9b5f914
Filter out status updates from the reconcile loop
andfasano Dec 9, 2020
16fc1d5
ironic provisioner de-duplicate image options
Dec 14, 2020
65ce67f
Clear ErrorCount independently of ErrorType/Message
zaneb Dec 11, 2020
3460c8e
Add force flag to ValidateManagementAccess()
zaneb Dec 10, 2020
bcda3be
Delay retry on inspect failed
zaneb Dec 4, 2020
e859a75
Ironic: Handle Error state correctly
zaneb Dec 11, 2020
9e8e885
Delay retry on deprovision failed
zaneb Dec 11, 2020
d5b715f
provisioner: Fix copy-paste error in docs
zaneb Dec 11, 2020
048a448
Ironic: Use retryAfterDelay() to handle conflicts
zaneb Jan 5, 2021
693b4fd
Ironic: Use retryAfterDelay() for other retries
zaneb Jan 5, 2021
829c119
Ironic: Use operationComplete() when complete
zaneb Jan 7, 2021
74b5da4
Ironic: Return operationContinuing() for delays
zaneb Jan 5, 2021
1feeb9f
Ironic: Use transientError() to return errors
zaneb Jan 7, 2021
db6f278
Ironic: Use operationFailed() to handle failures
zaneb Jan 7, 2021
0f15f63
Ironic: Use hostUpdated() to handle Status updates
zaneb Jan 5, 2021
3705a6b
Return provisioner ID from ValidateManagementAccess()
zaneb Jan 8, 2021
260f79b
Return power status from UpdateHardwareState()
zaneb Jan 8, 2021
ab894f5
Fixture: store state separately to provisioner
zaneb Jan 9, 2021
d20781c
Prevent provisioners modifying the Host
zaneb Jan 8, 2021
24f0659
Make actionRegistering() logs less chatty
zaneb Jan 12, 2021
19c72b1
Don't write Status on every actionContinue
zaneb Jan 9, 2021
4e60bf6
Stop treating actionRegistering() like a state action
zaneb Jan 14, 2021
7bfc8a2
Handle deploy failed state when deprovisioning
zaneb Dec 8, 2020
39aecec
Don't adopt in deprovisioning if provisioning didn't complete
zaneb Dec 8, 2020
07ffe19
Ensure adoption is retried upon failure
stbenjam Jan 18, 2021
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
53 changes: 4 additions & 49 deletions apis/metal3.io/v1alpha1/baremetalhost_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ const (
type ErrorType string

const (
// ProvisionedRegistrationError is an error condition occurring when the controller
// is unable to re-register an already provisioned host.
ProvisionedRegistrationError ErrorType = "provisioned registration error"
// RegistrationError is an error condition occurring when the
// controller is unable to connect to the Host's baseboard management
// controller.
Expand Down Expand Up @@ -521,7 +524,7 @@ type BareMetalHostStatus struct {

// ErrorType indicates the type of failure encountered when the
// OperationalStatus is OperationalStatusError
// +kubebuilder:validation:Enum=registration error;inspection error;provisioning error;power management error
// +kubebuilder:validation:Enum=provisioned registration error;registration error;inspection error;provisioning error;power management error
ErrorType ErrorType `json:"errorType,omitempty"`

// LastUpdated identifies when this status was last observed.
Expand Down Expand Up @@ -608,48 +611,6 @@ func (host *BareMetalHost) BootMode() BootMode {
return mode
}

// Available returns true if the host is available to be provisioned.
func (host *BareMetalHost) Available() bool {
if host.Spec.ConsumerRef != nil {
return false
}
if host.GetDeletionTimestamp() != nil {
return false
}
if host.HasError() {
return false
}
return true
}

// SetErrorMessage updates the ErrorMessage in the host Status struct
// and increases the ErrorCount
func (host *BareMetalHost) SetErrorMessage(errType ErrorType, message string) {
host.Status.OperationalStatus = OperationalStatusError
host.Status.ErrorType = errType
host.Status.ErrorMessage = message
host.Status.ErrorCount++
}

// ClearError removes any existing error message.
func (host *BareMetalHost) ClearError() (dirty bool) {
dirty = host.SetOperationalStatus(OperationalStatusOK)
var emptyErrType ErrorType = ""
if host.Status.ErrorType != emptyErrType {
host.Status.ErrorType = emptyErrType
dirty = true
}
if host.Status.ErrorMessage != "" {
host.Status.ErrorMessage = ""
dirty = true
}
if host.Status.ErrorCount != 0 {
host.Status.ErrorCount = 0
dirty = true
}
return dirty
}

// setLabel updates the given label when necessary and returns true
// when a change is made or false when no change is made.
func (host *BareMetalHost) setLabel(name, value string) bool {
Expand Down Expand Up @@ -713,12 +674,6 @@ func (host *BareMetalHost) OperationalStatus() OperationalStatus {
return host.Status.OperationalStatus
}

// HasError returns a boolean indicating whether there is an error
// set for the host.
func (host *BareMetalHost) HasError() bool {
return host.Status.ErrorMessage != ""
}

// CredentialsKey returns a NamespacedName suitable for loading the
// Secret containing the credentials associated with the host.
func (host *BareMetalHost) CredentialsKey() types.NamespacedName {
Expand Down
102 changes: 0 additions & 102 deletions apis/metal3.io/v1alpha1/baremetalhost_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,13 @@ package v1alpha1

import (
"testing"
"time"

"github.com/stretchr/testify/assert"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestHostAvailable(t *testing.T) {
hostWithError := BareMetalHost{
ObjectMeta: metav1.ObjectMeta{
Name: "myhost",
Namespace: "myns",
},
}
hostWithError.SetErrorMessage(RegistrationError, "oops something went wrong")

testCases := []struct {
Host BareMetalHost
Expected bool
FailMessage string
}{
{
Host: BareMetalHost{
ObjectMeta: metav1.ObjectMeta{
Name: "myhost",
Namespace: "myns",
},
},
Expected: true,
FailMessage: "available host returned not available",
},
{
Host: hostWithError,
Expected: false,
FailMessage: "host with error returned as available",
},
{
Host: BareMetalHost{
ObjectMeta: metav1.ObjectMeta{
Name: "myhost",
Namespace: "myns",
},
Spec: BareMetalHostSpec{
ConsumerRef: &corev1.ObjectReference{
Name: "mymachine",
Namespace: "myns",
},
},
},
Expected: false,
FailMessage: "host with consumerref returned as available",
},
{
Host: BareMetalHost{
ObjectMeta: metav1.ObjectMeta{
Name: "myhost",
Namespace: "myns",
DeletionTimestamp: &metav1.Time{Time: time.Now()},
},
},
Expected: false,
FailMessage: "deleted host returned as available",
},
}

for _, tc := range testCases {
if tc.Host.Available() != tc.Expected {
t.Error(tc.FailMessage)
}
}
}

func TestHostNeedsHardwareInspection(t *testing.T) {

testCases := []struct {
Expand Down Expand Up @@ -554,39 +488,3 @@ func TestBootMode(t *testing.T) {
})
}
}

func TestErrorCountIncrementsAlways(t *testing.T) {

b := &BareMetalHost{}
assert.Equal(t, b.Status.ErrorCount, 0)

b.SetErrorMessage(RegistrationError, "An error message")
assert.Equal(t, b.Status.ErrorCount, 1)

b.SetErrorMessage(InspectionError, "Another error message")
assert.Equal(t, b.Status.ErrorCount, 2)
}

func TestClearErrorCount(t *testing.T) {

b := &BareMetalHost{
Status: BareMetalHostStatus{
ErrorCount: 5,
},
}

assert.True(t, b.ClearError())
assert.Equal(t, 0, b.Status.ErrorCount)
}

func TestClearErrorCountOnlyIfNotZero(t *testing.T) {

b := &BareMetalHost{
Status: BareMetalHostStatus{
ErrorCount: 5,
},
}

assert.True(t, b.ClearError())
assert.False(t, b.ClearError())
}
1 change: 1 addition & 0 deletions config/crd/bases/metal3.io_baremetalhosts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ spec:
errorType:
description: ErrorType indicates the type of failure encountered when the OperationalStatus is OperationalStatusError
enum:
- provisioned registration error
- registration error
- inspection error
- provisioning error
Expand Down
1 change: 1 addition & 0 deletions config/render/capm3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ spec:
errorType:
description: ErrorType indicates the type of failure encountered when the OperationalStatus is OperationalStatusError
enum:
- provisioned registration error
- registration error
- inspection error
- provisioning error
Expand Down
22 changes: 11 additions & 11 deletions controllers/metal3.io/action_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ type actionResult interface {
Dirty() bool
}

// actionContinueNoWrite is a result indicating that the current action is still
// in progress, and that the resource should remain in the same provisioning
// state without writing the status
type actionContinueNoWrite struct {
actionContinue
}

func (r actionContinueNoWrite) Dirty() bool {
return false
}

// actionContinue is a result indicating that the current action is still
// in progress, and that the resource should remain in the same provisioning
// state.
Expand All @@ -51,6 +40,17 @@ func (r actionContinue) Result() (result reconcile.Result, err error) {
}

func (r actionContinue) Dirty() bool {
return false
}

// actionUpdate is a result indicating that the current action is still
// in progress, and that the resource should remain in the same provisioning
// state but write new Status data.
type actionUpdate struct {
actionContinue
}

func (r actionUpdate) Dirty() bool {
return true
}

Expand Down
Loading