Skip to content

Commit

Permalink
remove Available() method from BareMetalHost
Browse files Browse the repository at this point in the history
It is up to the consumer, not the host, to decide when a host is ready
to have provisioning instructions added. The checks in the Available()
method will be inlined in cluster-api-provider-metal3.

Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
  • Loading branch information
dhellmann committed Dec 14, 2020
1 parent f62d238 commit 095bf63
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
14 changes: 0 additions & 14 deletions apis/metal3.io/v1alpha1/baremetalhost_types.go
Expand Up @@ -608,20 +608,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) {
Expand Down
66 changes: 0 additions & 66 deletions apis/metal3.io/v1alpha1/baremetalhost_types_test.go
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

0 comments on commit 095bf63

Please sign in to comment.