Skip to content

Commit e46dba4

Browse files
committed
baremetal: use ControlPlane.Replicas
`*installConfig.ControlPlane.Replicas` is the canonical source of this information and we don't want to rely on the `IsMaster()` function. We also change how that number gets to the master-bmh-update.sh script. We template the number into the systemd service instead of the shell script. This gives us shellcheck.
1 parent 523f573 commit e46dba4

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ until oc get baremetalhosts -n openshift-machine-api; do
1010
sleep 20
1111
done
1212

13-
N="{{ .PlatformData.BareMetal.MasterHostCount }}"
14-
echo "Waiting for $N masters to become provisioned"
15-
while [ "$(oc get bmh -n openshift-machine-api -l installer.openshift.io/role=control-plane -o json | jq '.items[].status.provisioning.state' | grep provisioned -c)" -lt "$N" ]; do
16-
echo "Waiting for $N masters to become provisioned"
13+
echo "Waiting for $CONTROL_PLANE_REPLICA_COUNT masters to become provisioned"
14+
while [ "$(oc get bmh -n openshift-machine-api -l installer.openshift.io/role=control-plane -o json | jq '.items[].status.provisioning.state' | grep provisioned -c)" -lt "$CONTROL_PLANE_REPLICA_COUNT" ]; do
15+
echo "Waiting for $CONTROL_PLANE_REPLICA_COUNT masters to become provisioned"
1716
oc get bmh -A || true
1817
sleep 20
1918
done

data/data/bootstrap/baremetal/systemd/units/master-bmh-update.service renamed to data/data/bootstrap/baremetal/systemd/units/master-bmh-update.service.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Before=progress.service
66

77
[Service]
88
Type=oneshot
9+
Environment="CONTROL_PLANE_REPLICA_COUNT={{.PlatformData.BareMetal.ControlPlaneReplicas}}"
910
ExecStart=/usr/local/bin/master-bmh-update.sh
1011
RemainAfterExit=true
1112
Restart=on-failure

pkg/asset/ignition/bootstrap/baremetal/template.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type TemplateData struct {
5959
Hosts []*baremetal.Host
6060

6161
// How many of the Hosts are control plane machines?
62-
MasterHostCount int
62+
ControlPlaneReplicas int64
6363

6464
// ProvisioningNetwork displays the type of provisioning network being used
6565
ProvisioningNetwork string
@@ -98,16 +98,11 @@ func externalURLs(apiVIPs []string) (externalURLv4 string, externalURLv6 string)
9898
}
9999

100100
// GetTemplateData returns platform-specific data for bootstrap templates.
101-
func GetTemplateData(config *baremetal.Platform, networks []types.MachineNetworkEntry, ironicUsername, ironicPassword string) *TemplateData {
101+
func GetTemplateData(config *baremetal.Platform, networks []types.MachineNetworkEntry, controlPlaneReplicaCount int64, ironicUsername, ironicPassword string) *TemplateData {
102102
var templateData TemplateData
103103

104104
templateData.Hosts = config.Hosts
105-
106-
for _, host := range config.Hosts {
107-
if host.IsMaster() {
108-
templateData.MasterHostCount++
109-
}
110-
}
105+
templateData.ControlPlaneReplicas = controlPlaneReplicaCount
111106

112107
templateData.ProvisioningIP = config.BootstrapProvisioningIP
113108
templateData.ProvisioningNetwork = string(config.ProvisioningNetwork)

pkg/asset/ignition/bootstrap/baremetal/template_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestTemplatingIPv4(t *testing.T) {
3535
},
3636
}
3737

38-
result := GetTemplateData(&bareMetalConfig, nil, "bootstrap-ironic-user", "passw0rd")
38+
result := GetTemplateData(&bareMetalConfig, nil, 3, "bootstrap-ironic-user", "passw0rd")
3939

4040
assert.Equal(t, result.ProvisioningDHCPRange, "172.22.0.10,172.22.0.100,24")
4141
assert.Equal(t, result.ProvisioningCIDR, 24)
@@ -54,7 +54,7 @@ func TestTemplatingManagedIPv6(t *testing.T) {
5454
ProvisioningNetwork: baremetal.ManagedProvisioningNetwork,
5555
}
5656

57-
result := GetTemplateData(&bareMetalConfig, nil, "bootstrap-ironic-user", "passw0rd")
57+
result := GetTemplateData(&bareMetalConfig, nil, 3, "bootstrap-ironic-user", "passw0rd")
5858

5959
assert.Equal(t, result.ProvisioningDHCPRange, "fd2e:6f44:5dd8:b856::1,fd2e:6f44:5dd8::ff,80")
6060
assert.Equal(t, result.ProvisioningCIDR, 80)
@@ -71,7 +71,7 @@ func TestTemplatingUnmanagedIPv6(t *testing.T) {
7171
ProvisioningNetwork: baremetal.UnmanagedProvisioningNetwork,
7272
}
7373

74-
result := GetTemplateData(&bareMetalConfig, nil, "bootstrap-ironic-user", "passw0rd")
74+
result := GetTemplateData(&bareMetalConfig, nil, 3, "bootstrap-ironic-user", "passw0rd")
7575

7676
assert.Equal(t, result.ProvisioningDHCPRange, "")
7777
assert.Equal(t, result.ProvisioningCIDR, 64)

pkg/asset/ignition/bootstrap/common.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,13 @@ func (a *Common) getTemplateData(dependencies asset.Parents, bootstrapInPlace bo
283283

284284
switch installConfig.Config.Platform.Name() {
285285
case baremetaltypes.Name:
286-
platformData.BareMetal = baremetal.GetTemplateData(installConfig.Config.Platform.BareMetal, installConfig.Config.MachineNetwork, ironicCreds.Username, ironicCreds.Password)
286+
platformData.BareMetal = baremetal.GetTemplateData(
287+
installConfig.Config.Platform.BareMetal,
288+
installConfig.Config.MachineNetwork,
289+
*installConfig.Config.ControlPlane.Replicas,
290+
ironicCreds.Username,
291+
ironicCreds.Password,
292+
)
287293
case vspheretypes.Name:
288294
platformData.VSphere = vsphere.GetTemplateData(installConfig.Config.Platform.VSphere)
289295
}

0 commit comments

Comments
 (0)