- Derived from the following access article
https://access.redhat.com/solutions/7130140#ocp_step_10
export NODE_NAME="" # Node name from "oc get nodes"
export NEW_MACHINE_NAME="" # Typically same as NODE_NAME
export BOOT_MAC="" # MAC address of boot NICE
export BOOT_MODE="" # UEFI vs legacy
export CLUSTER_NAME=$(oc get infrastructure cluster -o=jsonpath='{.status.infrastructureName}{"\n"}')
export ROLE="worker" # master or worker- Bare Metal Host Template
cat <<EOF > bare-metal-host-object.yaml
apiVersion: metal3.io/v1alpha1
kind: BareMetalHost
metadata:
name: bmh-name
namespace: openshift-machine-api
spec:
automatedCleaningMode: metadata
bootMACAddress: 00:00:00:00:00:00
bootMode: legacy
customDeploy:
method: install_coreos
externallyProvisioned: true
online: true
userData:
name: worker-user-data-managed
namespace: openshift-machine-api
EOF- Machine Template
cat <<EOF > machine-object.yaml
apiVersion: machine.openshift.io/v1beta1
kind: Machine
metadata:
annotations:
machine.openshift.io/instance-state: unmanaged
metal3.io/BareMetalHost: openshift-machine-api/node-name
finalizers:
- machine.machine.openshift.io
labels:
machine.openshift.io/cluster-api-cluster: cluster-id
machine.openshift.io/cluster-api-machine-role: worker
machine.openshift.io/cluster-api-machine-type: worker
name: node-name
namespace: openshift-machine-api
spec:
metadata: {}
providerSpec:
value:
apiVersion: baremetal.cluster.k8s.io/v1alpha1
customDeploy:
method: install_coreos
hostSelector: {}
image:
checksum: ''
url: ''
kind: BareMetalMachineProviderSpec
metadata:
creationTimestamp: null
userData:
name: worker-user-data-managed
EOFyq -y -i --arg val ${NODE_NAME} '.metadata.name = $val' bare-metal-host-object.yaml
yq -y -i --arg val ${BOOT_MAC} '.spec.bootMACAddress = $val' bare-metal-host-object.yaml
yq -y -i --arg val ${BOOT_MODE} '.spec.bootMode = $val' bare-metal-host-object.yaml
user_data="${ROLE}-user-data-managed"
yq -y -i --arg val ${user_data} '.spec.userData.name = $val' bare-metal-host-object.yaml
oc create -f bare-metal-host-object.yamlbmh="openshift-machine-api/${NODE_NAME}"
yq -y -i --arg val ${bmh} '.metadata.annotations."metal3.io/BareMetalHost" = $val' machine-object.yaml
yq -y -i --arg val ${CLUSTER_NAME} '.metadata.labels."machine.openshift.io/cluster-api-cluster" = $val' machine-object.yaml
yq -y -i --arg val ${ROLE} '.metadata.labels."machine.openshift.io/cluster-api-machine-role" = $val' machine-object.yaml
yq -y -i --arg val ${ROLE} '.metadata.labels."machine.openshift.io/cluster-api-machine-type" = $val' machine-object.yaml
yq -y -i --arg val ${NODE_NAME} '.metadata.name = $val' machine-object.yaml
user_data="${ROLE}-user-data-managed"
yq -y -i --arg val ${user_data} '.spec.providerSpec.value.userData.name = $val' machine-object.yaml
oc create -f machine-object.yamlexport BMH_UID=$(oc get -n openshift-machine-api bmh $NODE_NAME -ojson | jq -r .metadata.uid)
echo $BMH_UIDoc patch -n openshift-machine-api bmh $NODE_NAME --type merge --patch '{"spec":{"consumerRef":{"apiVersion":"machine.openshift.io/v1beta1","kind":"Machine","name":"'$NEW_MACHINE_NAME'","namespace":"openshift-machine-api"}}}'oc patch node $NODE_NAME --type merge --patch '{"spec":{"providerID":"baremetalhost:///openshift-machine-api/'$NODE_NAME'/'$BMH_UID'"}}'oc get node -l node-role.kubernetes.io/${ROLE} -ojson | jq -r '.items[] | .metadata.name + " " + .spec.providerID'oc patch -n openshift-machine-api bmh $NODE_NAME --subresource status --type json -p '[{"op":"replace","path":"/status/poweredOn","value":true}]'
oc get bmh -n openshift-machine-api -ojson | jq -r '.items[] | .metadata.name + " PoweredOn:" + (.status.poweredOn | tostring)'
oc get bmh -n openshift-machine-api -ojson | jq -r '.items[] | .metadata.name + " ProvsioningState:" + .status.provisioning.state'oc patch -n openshift-machine-api bmh $NODE_NAME --subresource status --type json -p '[{"op":"replace","path":"/status/provisioning/state","value":"unmanaged"}]'oc patch -n openshift-machine-api machines.machine.openshift.io $NEW_MACHINE_NAME -n openshift-machine-api --subresource status --type json -p '[{"op":"replace","path":"/status/phase","value":"Provisioned"}]'
- Generate the providerID lines for control plane nodes
oc get -n openshift-machine-api baremetalhost -l installer.openshift.io/role=control-plane -ojson | jq -r '.items[] | "baremetalhost:///openshift-machine-api/" + .metadata.name + "/" + .metadata.uid'- Identify the cluster
oc get machines.machine.openshift.io -n openshift-machine-api -l machine.openshift.io/cluster-api-machine-role=master -L machine.openshift.io/cluster-api-cluster