X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=deploy%2Fmetal3%2Fscripts%2F01_metal3.sh;h=bd7be780c5199fc9697877db01a7e33b266eebfc;hb=7b08cb3771bb25a9263e57b20f80b73bacaefbe0;hp=563a92459f860815f64170d0c575fee5c9773284;hpb=b84fbfeb7c5b41bd6cf096f16ed9f7d82e800aa5;p=icn.git diff --git a/deploy/metal3/scripts/01_metal3.sh b/deploy/metal3/scripts/01_metal3.sh index 563a924..bd7be78 100755 --- a/deploy/metal3/scripts/01_metal3.sh +++ b/deploy/metal3/scripts/01_metal3.sh @@ -59,8 +59,10 @@ EOF function deprovision_compute_node { name="$1" - kubectl patch baremetalhost $name -n metal3 --type merge \ - -p '{"spec":{"image":{"url":"","checksum":""}}}' + if kubectl get baremetalhost $name -n metal3 &>/dev/null; then + kubectl patch baremetalhost $name -n metal3 --type merge \ + -p '{"spec":{"image":{"url":"","checksum":""}}}' + fi } function set_compute_ssh_config { @@ -132,6 +134,11 @@ EOF printf "\n" >> $name-userdata.yaml } +create_networkdata() { + name="$1" + node_networkdata $name > $name-networkdata.json +} + function launch_baremetal_operator { docker pull $IRONIC_BAREMETAL_IMAGE kubectl apply -f bmo/namespace/namespace.yaml @@ -152,10 +159,26 @@ function remove_baremetal_operator { } function cloud_init_scripts { - # The "intel_iommu=on iommu=pt" kernel command line is necessary - # for QAT support. + # 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' @@ -167,30 +190,6 @@ write_files: 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 - cat << 'EOF' -- path: /var/lib/cloud/scripts/per-boot/run_dhclient.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 -EOF - cat << EOF -- path: /var/lib/cloud/scripts/per-boot/set_provider_network.sh - owner: root:root - permissions: '0777' - content: | - #!/usr/bin/env bash - set -xe - route add default gw $PROVIDER_NETWORK_GATEWAY - sed -i -e 's/^#DNS=.*/DNS=$PROVIDER_NETWORK_DNS/g' /etc/systemd/resolved.conf - systemctl daemon-reload - systemctl restart systemd-resolved EOF } @@ -209,12 +208,29 @@ 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 { 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 + create_networkdata $name + apply_networkdata_credential $name - go run $GOPATH/src/github.com/metal3-io/baremetal-operator/cmd/make-bm-worker/main.go \ + GO111MODULE=auto go run $GOPATH/src/github.com/metal3-io/baremetal-operator/cmd/make-bm-worker/main.go \ -address "ipmi://$ipmi_address" \ -password "$ipmi_password" \ -user "$ipmi_username" \ @@ -226,6 +242,9 @@ function make_bm_hosts { 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 @@ -251,9 +270,9 @@ function remove_bm_hosts { function cleanup { 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 + 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