Skip to content

Commit 799b460

Browse files
committed
bootstrap: use oc to query host readiness
1 parent 227c9c2 commit 799b460

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

data/data/bootstrap/baremetal/files/usr/local/bin/master-bmh-update.sh

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,21 @@ export KUBECONFIG=/opt/openshift/auth/kubeconfig-loopback
66

77
# Wait till the baremetalhosts are populated
88
until oc get baremetalhosts -n openshift-machine-api; do
9-
echo Waiting for BareMetalHosts to appear...
9+
echo Waiting for BareMetalHosts CRD to appear...
1010
sleep 20
1111
done
1212

13-
AUTH_DIR=/opt/metal3/auth
14-
set +x
15-
ironic_url="$(printf 'http://%s:%s@localhost:6385/v1' "$(cat "${AUTH_DIR}/ironic/username")" "$(cat "${AUTH_DIR}/ironic/password")")"
16-
17-
# Wait for a master to appear.
18-
while [ "$(curl -s "${ironic_url}/nodes" | jq '.nodes[] | .uuid' | wc -l)" -lt 1 ]; do
19-
echo waiting for a master node to show up
13+
while [ "$(oc get bmh -n openshift-machine-api -o name | wc -l)" -lt 1 ]; do
14+
echo "Waiting for bmh"
2015
sleep 20
2116
done
2217

23-
# Wait for the nodes to become active after introspection.
24-
# Probably don't need this but I want to be 100% sure.
25-
while curl -s "${ironic_url}/nodes" | jq '.nodes[] | .provision_state' | grep -v active; do
26-
echo Waiting for nodes to become active
18+
while [ "$(oc get bmh -n openshift-machine-api -l installer.openshift.io/role=master -o json | jq '.items[].status.provisioning.state' | grep -v provisioned -c)" -gt 0 ]; do
19+
echo "Waiting for masters to become provisioned"
20+
oc get bmh -A
2721
sleep 20
2822
done
2923

30-
echo Nodes are all active
31-
3224
# Shut down ironic containers so that the API VIP can fail over to the control
3325
# plane.
3426
echo "Stopping provisioning services..."

pkg/asset/machines/baremetal/hosts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ func Hosts(config *types.InstallConfig, machines []machineapi.Machine, userDataS
143143
Method: "install_coreos",
144144
}
145145

146+
newHost.ObjectMeta.Labels = map[string]string{
147+
"installer.openshift.io/role": "master",
148+
}
149+
146150
// Link the new host to the currently available machine
147151
machine := machines[numMasters]
148152
newHost.Spec.ConsumerRef = &corev1.ObjectReference{

pkg/asset/machines/baremetal/hosts_test.go

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ routes:
6161

6262
ExpectedSetting: settings().
6363
secrets(secret("master-0-bmc-secret").creds("usr0", "pwd0")).
64-
hosts(host("master-0").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy()).build(),
64+
hosts(host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy()).build(),
6565
},
6666
{
6767
Scenario: "default-norole",
@@ -70,7 +70,7 @@ routes:
7070

7171
ExpectedSetting: settings().
7272
secrets(secret("master-0-bmc-secret").creds("usr0", "pwd0")).
73-
hosts(host("master-0").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy()).build(),
73+
hosts(host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy()).build(),
7474
},
7575
{
7676
Scenario: "network-config",
@@ -85,6 +85,7 @@ routes:
8585
networkConfigSecrets(secret("master-0-network-config-secret").nmstate(nmstate)).
8686
hosts(
8787
host("master-0").
88+
label("installer.openshift.io/role", "master").
8889
consumerRef("machine-0").
8990
userDataRef("user-data-secret").
9091
preprovisioningNetworkDataName("master-0-network-config-secret").
@@ -107,9 +108,9 @@ routes:
107108
secret("master-1-bmc-secret").creds("usr1", "pwd1"),
108109
secret("master-2-bmc-secret").creds("usr2", "pwd2")).
109110
hosts(
110-
host("master-0").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
111-
host("master-1").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
112-
host("master-2").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy()).build(),
111+
host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
112+
host("master-1").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
113+
host("master-2").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy()).build(),
113114
},
114115
{
115116
Scenario: "4-hosts-3-machines",
@@ -130,9 +131,9 @@ routes:
130131
secret("master-2-bmc-secret").creds("usr2", "pwd2"),
131132
secret("worker-0-bmc-secret").creds("usr3", "pwd3")).
132133
hosts(
133-
host("master-0").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
134-
host("master-1").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
135-
host("master-2").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy(),
134+
host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
135+
host("master-1").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
136+
host("master-2").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy(),
136137
host("worker-0").annotation("baremetalhost.metal3.io/paused", ""),
137138
).build(),
138139
},
@@ -155,9 +156,9 @@ routes:
155156
secret("master-2-bmc-secret").creds("usr2", "pwd2"),
156157
secret("worker-0-bmc-secret").creds("wrk0", "pwd0")).
157158
hosts(
158-
host("master-0").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
159-
host("master-1").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
160-
host("master-2").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy(),
159+
host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
160+
host("master-1").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
161+
host("master-2").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy(),
161162
host("worker-0").annotation("baremetalhost.metal3.io/paused", ""),
162163
).build(),
163164
},
@@ -182,9 +183,9 @@ routes:
182183
secret("worker-0-bmc-secret").creds("wrk0", "pwd0"),
183184
secret("worker-1-bmc-secret").creds("wrk1", "pwd1")).
184185
hosts(
185-
host("master-0").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
186-
host("master-1").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
187-
host("master-2").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy(),
186+
host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
187+
host("master-1").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
188+
host("master-2").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy(),
188189
host("worker-0").annotation("baremetalhost.metal3.io/paused", ""),
189190
host("worker-1").annotation("baremetalhost.metal3.io/paused", ""),
190191
).build(),
@@ -210,11 +211,11 @@ routes:
210211
secret("master-0-bmc-secret").creds("usr0", "pwd0"),
211212
secret("master-2-bmc-secret").creds("usr2", "pwd2")).
212213
hosts(
213-
host("master-1").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
214+
host("master-1").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
214215
host("worker-0").annotation("baremetalhost.metal3.io/paused", ""),
215216
host("worker-1").annotation("baremetalhost.metal3.io/paused", ""),
216-
host("master-0").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
217-
host("master-2").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy()).build(),
217+
host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
218+
host("master-2").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy()).build(),
218219
},
219220
{
220221
Scenario: "4-hosts-3-machines-norole-master",
@@ -236,9 +237,9 @@ routes:
236237
secret("master-2-bmc-secret").creds("usr2", "pwd2")).
237238
hosts(
238239
host("worker-0").annotation("baremetalhost.metal3.io/paused", ""),
239-
host("master-0").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
240-
host("master-1").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
241-
host("master-2").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy()).build(),
240+
host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
241+
host("master-1").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
242+
host("master-2").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy()).build(),
242243
},
243244
{
244245
Scenario: "4-hosts-3-machines-norole-worker",
@@ -259,9 +260,9 @@ routes:
259260
secret("master-2-bmc-secret").creds("usr2", "pwd2"),
260261
secret("worker-0-bmc-secret").creds("wrk0", "pwd0")).
261262
hosts(
262-
host("master-0").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
263-
host("master-1").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
264-
host("master-2").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy(),
263+
host("master-0").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-0").customDeploy(),
264+
host("master-1").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-1").customDeploy(),
265+
host("master-2").label("installer.openshift.io/role", "master").userDataRef("user-data-secret").consumerRef("machine-2").customDeploy(),
265266
host("worker-0").annotation("baremetalhost.metal3.io/paused", "")).build(),
266267
},
267268
}
@@ -449,6 +450,15 @@ func (hb *hostBuilder) annotation(key, value string) *hostBuilder {
449450
return hb
450451
}
451452

453+
func (hb *hostBuilder) label(key, value string) *hostBuilder {
454+
if hb.Labels == nil {
455+
hb.Labels = map[string]string{}
456+
}
457+
458+
hb.Labels[key] = value
459+
return hb
460+
}
461+
452462
func (hb *hostBuilder) consumerRef(name string) *hostBuilder {
453463
hb.Spec.ConsumerRef = &corev1.ObjectReference{
454464
APIVersion: "v1",

0 commit comments

Comments
 (0)