X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=deploy%2Fmetal3%2Fscripts%2F01_metal3.sh;h=27a668536e6dcfee5187dc742cfc2c8b2389f359;hb=99ab423be0ac03c1c23e1129a96b75b3ce7269ce;hp=75719e33525bebeb9ec7e97b31081236a4733640;hpb=71033a920680e2495f14948c347e99ed2558f6d7;p=icn.git diff --git a/deploy/metal3/scripts/01_metal3.sh b/deploy/metal3/scripts/01_metal3.sh index 75719e3..27a6685 100755 --- a/deploy/metal3/scripts/01_metal3.sh +++ b/deploy/metal3/scripts/01_metal3.sh @@ -1,5 +1,5 @@ -#!/bin/bash -set +ex +#!/usr/bin/env bash +set -eu -o pipefail LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")" @@ -15,7 +15,23 @@ fi IMAGE_URL=http://172.22.0.1/images/${BM_IMAGE} IMAGE_CHECKSUM=http://172.22.0.1/images/${BM_IMAGE}.md5sum -function get_default_inteface_ipaddress { +function clone_repos { + mkdir -p "${M3PATH}" + if [[ -d ${BMOPATH} && "${FORCE_REPO_UPDATE}" == "true" ]]; then + rm -rf "${BMOPATH}" + fi + if [ ! -d "${BMOPATH}" ] ; then + pushd "${M3PATH}" + git clone "${BMOREPO}" + popd + fi + pushd "${BMOPATH}" + git checkout "${BMOBRANCH}" + git pull -r || true + popd +} + +function get_default_interface_ipaddress { local _ip=$1 local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route) local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }') @@ -48,7 +64,7 @@ function deprovision_compute_node { } function set_compute_ssh_config { - get_default_inteface_ipaddress default_addr + get_default_interface_ipaddress default_addr cat << EOF - path: /root/.ssh/config owner: root:root @@ -66,25 +82,49 @@ function set_compute_ssh_config { EOF } +# documentation for the values below may be found at +# https://cloudinit.readthedocs.io/en/latest/topics/modules.html function create_userdata { name="$1" + username="$2" + password="$3" COMPUTE_NODE_FQDN="$name.akraino.icn.org" + + # validate that the user isn't expecting the deprecated + # COMPUTE_NODE_PASSWORD to be used + if [ "$password" != "${COMPUTE_NODE_PASSWORD:-$password}" ]; then + cat < $name-userdata.yaml - if [ -n "$COMPUTE_NODE_PASSWORD" ]; then - printf "password: ""%s" "$COMPUTE_NODE_PASSWORD" >> $name-userdata.yaml - printf "\nchpasswd: {expire: False}\n" >> $name-userdata.yaml - printf "ssh_pwauth: True\n" >> $name-userdata.yaml + if [ -n "$password" ]; then + if [ -n "$username" ]; then + passwd=$(mkpasswd --method=SHA-512 --rounds 4096 "$password") + printf "users:" >> $name-userdata.yaml + printf "\n - name: ""%s" "$username" >> $name-userdata.yaml + printf "\n lock_passwd: False" >> $name-userdata.yaml # necessary to allow password login + printf "\n passwd: ""%s" "$passwd" >> $name-userdata.yaml + printf "\n sudo: \"ALL=(ALL) NOPASSWD:ALL\"" >> $name-userdata.yaml + else + printf "password: ""%s" "$password" >> $name-userdata.yaml + fi + printf "\nchpasswd: {expire: False}\n" >> $name-userdata.yaml + printf "ssh_pwauth: True\n" >> $name-userdata.yaml fi if [ -n "$COMPUTE_NODE_FQDN" ]; then - printf "fqdn: ""%s" "$COMPUTE_NODE_FQDN" >> $name-userdata.yaml - printf "\n" >> $name-userdata.yaml + printf "fqdn: ""%s" "$COMPUTE_NODE_FQDN" >> $name-userdata.yaml + printf "\n" >> $name-userdata.yaml fi printf "disable_root: false\n" >> $name-userdata.yaml printf "ssh_authorized_keys:\n - " >> $name-userdata.yaml if [ ! -f $HOME/.ssh/id_rsa.pub ]; then - yes y | ssh-keygen -t rsa -N "" -f $HOME/.ssh/id_rsa + yes y | ssh-keygen -t rsa -N "" -f $HOME/.ssh/id_rsa fi cat $HOME/.ssh/id_rsa.pub >> $name-userdata.yaml @@ -93,32 +133,22 @@ function create_userdata { } function launch_baremetal_operator { - if [ ! -d $GOPATH/src/github.com/metal3-io/baremetal-operator ]; then - go get github.com/metal3-io/baremetal-operator - git checkout 3d40caa29dce82878d83aeb7f8dab4dc4a856160 - fi - - pushd $GOPATH/src/github.com/metal3-io/baremetal-operator - docker pull quay.io/metal3-io/baremetal-operator:master - make deploy - popd + docker pull $IRONIC_BAREMETAL_IMAGE + kubectl apply -f bmo/namespace/namespace.yaml + kubectl apply -f bmo/rbac/service_account.yaml -n metal3 + kubectl apply -f bmo/rbac/role.yaml -n metal3 + kubectl apply -f bmo/rbac/role_binding.yaml + kubectl apply -f bmo/crds/metal3.io_baremetalhosts_crd.yaml + kubectl apply -f bmo/operator/no_ironic/operator.yaml -n metal3 } function remove_baremetal_operator { - if [ ! -d $GOPATH/src/github.com/metal3-io/baremetal-operator ]; then - go get github.com/metal3-io/baremetal-operator - git checkout 3d40caa29dce82878d83aeb7f8dab4dc4a856160 - fi - - pushd $GOPATH/src/github.com/metal3-io/baremetal-operator - kubectl delete -f deploy/operator.yaml -n metal3 - kubectl delete -f deploy/crds/metal3_v1alpha1_baremetalhost_crd.yaml - kubectl delete -f deploy/role_binding.yaml - kubectl delete -f deploy/role.yaml -n metal3 - kubectl delete -f deploy/service_account.yaml -n metal3 - kubectl delete ns metal3 - docker rmi quay.io/metal3-io/baremetal-operator:master - popd + kubectl delete -f bmo/operator/no_ironic/operator.yaml -n metal3 + kubectl delete -f bmo/crds/metal3.io_baremetalhosts_crd.yaml + kubectl delete -f bmo/rbac/role_binding.yaml + kubectl delete -f bmo/rbac/role.yaml -n metal3 + kubectl delete -f bmo/rbac/service_account.yaml -n metal3 + kubectl delete -f bmo/namespace/namespace.yaml } function network_config_files { @@ -168,14 +198,14 @@ EOF } function make_bm_hosts { - while read -r name username password address; do - create_userdata $name + while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do + create_userdata $name $os_username $os_password apply_userdata_credential $name go run $GOPATH/src/github.com/metal3-io/baremetal-operator/cmd/make-bm-worker/main.go \ - -address "ipmi://$address" \ - -password "$password" \ - -user "$username" \ + -address "ipmi://$ipmi_address" \ + -password "$ipmi_password" \ + -user "$ipmi_username" \ "$name" > $name-bm-node.yaml printf " image:" >> $name-bm-node.yaml @@ -183,7 +213,9 @@ function make_bm_hosts { 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 rootDeviceHints:" >> $name-bm-node.yaml + printf "\n minSizeGigabytes: 48\n" >> $name-bm-node.yaml kubectl apply -f $name-bm-node.yaml -n metal3 done } @@ -200,21 +232,35 @@ function configure_nodes { } function remove_bm_hosts { - while read -r name username password address; do + while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do deprovision_compute_node $name done } function cleanup { - while read -r name username password address; do + while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do kubectl delete bmh $name -n metal3 kubectl delete secrets $name-bmc-secret -n metal3 kubectl delete secrets $name-user-data -n metal3 + if [ -f $name-bm-node.yaml ]; then + rm -rf $name-bm-node.yaml + fi + + if [ -f $name-user-data-credential.yaml ]; then + rm -rf $name-user-data-credential.yaml + fi + + if [ -f $name-userdata.yaml ]; then + rm -rf $name-userdata.yaml + fi done } function clean_all { list_nodes | cleanup + if [ -f $IRONIC_DATA_DIR/nodes.json ]; then + rm -rf $IRONIC_DATA_DIR/nodes.json + fi } function apply_bm_hosts { @@ -226,6 +272,7 @@ function deprovision_all_hosts { } if [ "$1" == "launch" ]; then + clone_repos launch_baremetal_operator exit 0 fi