-#!/bin/bash
-set -xe
+#!/usr/bin/env bash
+set -eux -o pipefail
# shellcheck disable=SC1091
source lib/logging.sh
eval "$(go env)"
export GOPATH
+DEPLOYDIR="$(dirname "$PWD")"
+BMODIR=$DEPLOYDIR/metal3/scripts/bmo
# Environment variables
# M3PATH : Path to clone the metal3 dev env repo
BMOPATH="${M3PATH}/baremetal-operator"
BMOREPO="${BMOREPO:-https://github.com/metal3-io/baremetal-operator.git}"
-BMOBRANCH="${BMOBRANCH:-3d40caa29dce82878d83aeb7f8dab4dc4a856160}"
-FORCE_REPO_UPDATE="${FORCE_REPO_UPDATE:-false}"
+BMOBRANCH="${BMOBRANCH:-10eb5aa3e614d0fdc6315026ebab061cbae6b929}"
+FORCE_REPO_UPDATE="${FORCE_REPO_UPDATE:-true}"
BMO_RUN_LOCAL="${BMO_RUN_LOCAL:-false}"
COMPUTE_NODE_PASSWORD="${COMPUTE_NODE_PASSWORD:-mypasswd}"
IMAGE_URL=http://172.22.0.1/images/${BM_IMAGE}
IMAGE_CHECKSUM=http://172.22.0.1/images/${BM_IMAGE}.md5sum
-function clone_repos() {
+function clone_repos {
mkdir -p "${M3PATH}"
if [[ -d ${BMOPATH} && "${FORCE_REPO_UPDATE}" == "true" ]]; then
rm -rf "${BMOPATH}"
popd
}
-function launch_baremetal_operator() {
- pushd "${BMOPATH}"
- if [ "${BMO_RUN_LOCAL}" = true ]; then
- touch bmo.out.log
- touch bmo.err.log
- make deploy
- kubectl scale deployment metal3-baremetal-operator -n metal3 --replicas=0
- nohup make run >> bmo.out.log 2>>bmo.err.log &
- else
- make deploy
- fi
- popd
+function launch_baremetal_operator {
+ docker pull $IRONIC_BAREMETAL_IMAGE
+ kubectl apply -f $BMODIR/namespace/namespace.yaml
+ kubectl apply -f $BMODIR/rbac/service_account.yaml -n metal3
+ kubectl apply -f $BMODIR/rbac/role.yaml -n metal3
+ kubectl apply -f $BMODIR/rbac/role_binding.yaml
+ kubectl apply -f $BMODIR/crds/metal3.io_baremetalhosts_crd.yaml
+ kubectl apply -f $BMODIR/operator/no_ironic/operator.yaml -n metal3
}
-network_config_files() {
-cat << 'EOF'
-write_files:
-- path: /opt/ironic_net.sh
- owner: root:root
- permissions: '0777'
- content: |
- #!/usr/bin/env bash
- set -xe
- for intf in /sys/class/net/*; do
- sudo ifconfig `basename $intf` up
- sudo dhclient -nw `basename $intf`
- done
-runcmd:
- - [ /opt/ironic_net.sh ]
-EOF
-}
-
-create_userdata() {
+# documentation for the values below may be found at
+# https://cloudinit.readthedocs.io/en/latest/topics/modules.html
+function create_userdata {
name="$1"
COMPUTE_NODE_FQDN="$name.akraino.icn.org"
printf "#cloud-config\n" > $name-userdata.yaml
fi
cat $HOME/.ssh/id_rsa.pub >> $name-userdata.yaml
- network_config_files >> $name-userdata.yaml
+ cloud_init_scripts >> $name-userdata.yaml
printf "\n" >> $name-userdata.yaml
}
-apply_userdata_credential() {
+function cloud_init_scripts {
+ # set_dhcp_indentifier.sh:
+ # The IP address assigned to the provisioning NIC will change
+ # due to IPA using the MAC address as the client ID and systemd
+ # using a different ID. Tell systemd to use the MAC as the
+ # client ID. We can't do this in the network data as only the
+ # JSON format is supported by metal3, and the JSON format does
+ # not support the dhcp-identifier field.
+ cat << 'EOF'
+write_files:
+- path: /var/lib/cloud/scripts/per-instance/set_dhcp_identifier.sh
+ owner: root:root
+ permissions: '0777'
+ content: |
+ #!/usr/bin/env bash
+ set -eux -o pipefail
+ sed -i -e '/dhcp4: true$/!b' -e 'h;s/\S.*/dhcp-identifier: mac/;H;g' /etc/netplan/50-cloud-init.yaml
+ netplan apply
+EOF
+}
+
+function apply_userdata_credential {
name="$1"
cat <<EOF > ./$name-user-data-credential.yaml
apiVersion: v1
kubectl apply -n metal3 -f $name-user-data-credential.yaml
}
-function make_bm_hosts() {
- while read -r name address user password mac; do
+function create_networkdata {
+ name="$1"
+ node_networkdata $name > $name-networkdata.json
+}
+
+function apply_networkdata_credential {
+ name="$1"
+ cat <<EOF > ./$name-network-data-credential.yaml
+apiVersion: v1
+data:
+ networkData: $(base64 -w 0 $name-networkdata.json)
+kind: Secret
+metadata:
+ name: $name-network-data
+ namespace: metal3
+type: Opaque
+EOF
+ kubectl apply -n metal3 -f $name-network-data-credential.yaml
+}
+
+function make_bm_hosts {
+ while IFS=',' read -r name address user password mac; do
create_userdata $name
apply_userdata_credential $name
- go run "${BMOPATH}"/cmd/make-bm-worker/main.go \
+ create_networkdata $name
+ apply_networkdata_credential $name
+ GO111MODULE=auto go run "${BMOPATH}"/cmd/make-bm-worker/main.go \
-address "$address" \
-password "$password" \
-user "$user" \
printf "\n checksum: ""%s" "${IMAGE_CHECKSUM}" >> $name-bm-node.yaml
printf "\n userData:" >> $name-bm-node.yaml
printf "\n name: ""%s" "$name""-user-data" >> $name-bm-node.yaml
- printf "\n namespace: metal3\n" >> $name-bm-node.yaml
+ printf "\n namespace: metal3" >> $name-bm-node.yaml
+ printf "\n networkData:" >> $name-bm-node.yaml
+ printf "\n name: ""%s" "$name""-network-data" >> $name-bm-node.yaml
+ printf "\n namespace: metal3" >> $name-bm-node.yaml
+ printf "\n rootDeviceHints:" >> $name-bm-node.yaml
+ printf "\n minSizeGigabytes: 48\n" >> $name-bm-node.yaml
kubectl apply -f $name-bm-node.yaml -n metal3
done
}
-function apply_bm_hosts() {
+function apply_bm_hosts {
list_nodes | make_bm_hosts
}
-
clone_repos
launch_baremetal_operator
apply_bm_hosts