-#!/bin/bash
-set -xe
+#!/usr/bin/env bash
+set -eux -o pipefail
# shellcheck disable=SC1091
source lib/logging.sh
}
function launch_baremetal_operator {
- docker pull integratedcloudnative/baremetal-operator:v1.0-icn
+ 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/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 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 read -r name address user password mac; do
+ 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
}