X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=deploy%2Fmetal3%2Fscripts%2F01_metal3.sh;h=0b0d5642beaeb50f65f0228c0f7027fc3bfca2c5;hb=818ebd97b869309fefa0cc102ab0a9f067f9a51d;hp=8d0fc1b541a1548806ff7ff81e7dff9bacd9e9ad;hpb=3132fc5e4d956ad3181a9ec0c5f234581f8947b1;p=icn.git diff --git a/deploy/metal3/scripts/01_metal3.sh b/deploy/metal3/scripts/01_metal3.sh index 8d0fc1b..0b0d564 100755 --- a/deploy/metal3/scripts/01_metal3.sh +++ b/deploy/metal3/scripts/01_metal3.sh @@ -1,20 +1,18 @@ #!/usr/bin/env bash set -eu -o pipefail -LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")" +SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))" +LIBDIR="$(dirname $(dirname $(dirname ${SCRIPTDIR})))/env/lib" eval "$(go env)" -source $LIBDIR/env/lib/common.sh +source $LIBDIR/common.sh if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" exit 1 fi -IMAGE_URL=http://172.22.0.1:6180/images/${BM_IMAGE} -IMAGE_CHECKSUM=http://172.22.0.1:6180/images/${BM_IMAGE}.md5sum - function deprovision_compute_node { name="$1" if kubectl get baremetalhost $name -n metal3 &>/dev/null; then @@ -23,154 +21,11 @@ function deprovision_compute_node { fi } -# 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 "$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 - 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 - fi - - cat $HOME/.ssh/id_rsa.pub >> $name-userdata.yaml - cloud_init_scripts >> $name-userdata.yaml - printf "\n" >> $name-userdata.yaml -} - -create_networkdata() { - name="$1" - node_networkdata $name > $name-networkdata.json -} - -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. - # set_kernel_cmdline.sh: - # The "intel_iommu=on iommu=pt" kernel command line is necessary - # for QAT support. - 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 -- path: /var/lib/cloud/scripts/per-instance/set_kernel_cmdline.sh - owner: root:root - permissions: '0777' - content: | - #!/usr/bin/env bash - set -eux -o pipefail - grub_file=${1:-"/etc/default/grub"} - kernel_parameters="intel_iommu=on iommu=pt" - sed -i~ "/^GRUB_CMDLINE_LINUX=/{h;s/\(=\".*\)\"/\1 ${kernel_parameters}\"/};\${x;/^$/{s//GRUB_CMDLINE_LINUX=\"${kernel_parameters}\"/;H};x}" "$grub_file" - update-grub - reboot -EOF -} - -function apply_userdata_credential { - name="$1" - cat < ./$name-user-data-credential.yaml -apiVersion: v1 -data: - userData: $(base64 -w 0 $name-userdata.yaml) -kind: Secret -metadata: - name: $name-user-data - namespace: metal3 -type: Opaque -EOF - kubectl apply -n metal3 -f $name-user-data-credential.yaml -} - -apply_networkdata_credential() { - name="$1" - cat < ./$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 { - kubectl create namespace metal3 --dry-run=client -o yaml | kubectl apply -f - while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do - create_userdata $name $os_username $os_password - apply_userdata_credential $name - create_networkdata $name - apply_networkdata_credential $name - - GOPATH=$GOPATH:$(echo ${BMOPATH} | cut -d/ -f-2) GO111MODULE=auto \ - go run ${BMOPATH}/cmd/make-bm-worker/main.go \ - -address "ipmi://$ipmi_address" \ - -password "$ipmi_password" \ - -user "$ipmi_username" \ - -boot-mac "$boot_mac" \ - "$name" > $name-bm-node.yaml - - printf " image:" >> $name-bm-node.yaml - printf "\n url: ""%s" "$IMAGE_URL" >> $name-bm-node.yaml - 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" >> $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 + node_machine_values >${SCRIPTDIR}/${name}-values.yaml + helm -n metal3 install ${name} ${SCRIPTDIR}/../../machine --create-namespace -f ${SCRIPTDIR}/${name}-values.yaml + done } @@ -180,40 +35,28 @@ function configure_nodes { fi #make sure nodes.json file in /opt/ironic/ are configured - if [ ! -f $IRONIC_DATA_DIR/nodes.json ]; then - cp $PWD/nodes.json.sample $IRONIC_DATA_DIR/nodes.json + if [ ! -f $NODES_FILE ]; then + cp ${SCRIPTDIR}/nodes.json.sample $NODES_FILE fi } -function remove_bm_hosts { +function deprovision_bm_hosts { while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do deprovision_compute_node $name done } -function cleanup { +function clean_bm_hosts { while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do - kubectl delete --ignore-not-found=true bmh $name -n metal3 - kubectl delete --ignore-not-found=true secrets $name-bmc-secret -n metal3 - kubectl delete --ignore-not-found=true 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 + helm -n metal3 uninstall ${name} + rm -rf ${SCRIPTDIR}/${name}-values.yaml done } function clean_all { - list_nodes | cleanup - if [ -f $IRONIC_DATA_DIR/nodes.json ]; then - rm -rf $IRONIC_DATA_DIR/nodes.json + list_nodes | clean_bm_hosts + if [ -f $NODES_FILE ]; then + rm -rf $NODES_FILE fi } @@ -222,7 +65,7 @@ function apply_bm_hosts { } function deprovision_all_hosts { - list_nodes | remove_bm_hosts + list_nodes | deprovision_bm_hosts } if [ "$1" == "deprovision" ]; then