Skip to content

Commit 095bf63

Browse files
committed
remove Available() method from BareMetalHost
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>
1 parent f62d238 commit 095bf63

File tree

2 files changed

+0
-80
lines changed

2 files changed

+0
-80
lines changed

apis/metal3.io/v1alpha1/baremetalhost_types.go

-14
Original file line numberDiff line numberDiff line change
@@ -608,20 +608,6 @@ func (host *BareMetalHost) BootMode() BootMode {
608608
return mode
609609
}
610610

611-
// Available returns true if the host is available to be provisioned.
612-
func (host *BareMetalHost) Available() bool {
613-
if host.Spec.ConsumerRef != nil {
614-
return false
615-
}
616-
if host.GetDeletionTimestamp() != nil {
617-
return false
618-
}
619-
if host.HasError() {
620-
return false
621-
}
622-
return true
623-
}
624-
625611
// SetErrorMessage updates the ErrorMessage in the host Status struct
626612
// and increases the ErrorCount
627613
func (host *BareMetalHost) SetErrorMessage(errType ErrorType, message string) {

apis/metal3.io/v1alpha1/baremetalhost_types_test.go

-66
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,13 @@ package v1alpha1
22

33
import (
44
"testing"
5-
"time"
65

76
"github.com/stretchr/testify/assert"
87

98
corev1 "k8s.io/api/core/v1"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
)
1211

13-
func TestHostAvailable(t *testing.T) {
14-
hostWithError := BareMetalHost{
15-
ObjectMeta: metav1.ObjectMeta{
16-
Name: "myhost",
17-
Namespace: "myns",
18-
},
19-
}
20-
hostWithError.SetErrorMessage(RegistrationError, "oops something went wrong")
21-
22-
testCases := []struct {
23-
Host BareMetalHost
24-
Expected bool
25-
FailMessage string
26-
}{
27-
{
28-
Host: BareMetalHost{
29-
ObjectMeta: metav1.ObjectMeta{
30-
Name: "myhost",
31-
Namespace: "myns",
32-
},
33-
},
34-
Expected: true,
35-
FailMessage: "available host returned not available",
36-
},
37-
{
38-
Host: hostWithError,
39-
Expected: false,
40-
FailMessage: "host with error returned as available",
41-
},
42-
{
43-
Host: BareMetalHost{
44-
ObjectMeta: metav1.ObjectMeta{
45-
Name: "myhost",
46-
Namespace: "myns",
47-
},
48-
Spec: BareMetalHostSpec{
49-
ConsumerRef: &corev1.ObjectReference{
50-
Name: "mymachine",
51-
Namespace: "myns",
52-
},
53-
},
54-
},
55-
Expected: false,
56-
FailMessage: "host with consumerref returned as available",
57-
},
58-
{
59-
Host: BareMetalHost{
60-
ObjectMeta: metav1.ObjectMeta{
61-
Name: "myhost",
62-
Namespace: "myns",
63-
DeletionTimestamp: &metav1.Time{Time: time.Now()},
64-
},
65-
},
66-
Expected: false,
67-
FailMessage: "deleted host returned as available",
68-
},
69-
}
70-
71-
for _, tc := range testCases {
72-
if tc.Host.Available() != tc.Expected {
73-
t.Error(tc.FailMessage)
74-
}
75-
}
76-
}
77-
7812
func TestHostNeedsHardwareInspection(t *testing.T) {
7913

8014
testCases := []struct {

0 commit comments

Comments
 (0)