4 LIBDIR="$(dirname "$PWD")"
6 source $LIBDIR/lib/logging.sh
7 source $LIBDIR/lib/common.sh
9 if [[ $EUID -ne 0 ]]; then
10 echo "launch script must be run as root"
14 function get_default_interface_ipaddress {
16 local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
17 local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
18 eval $_ip="'$_ipv4address'"
21 function check_cni_network {
22 #since bootstrap cluster is a single node cluster,
23 #podman and bootstap cluster have same network configuration to avoid the cni network conf conflicts
24 if [ ! -d "/etc/cni/net.d" ]; then
25 mkdir -p "/etc/cni/net.d"
28 if [ -f "/etc/cni/net.d/87-podman-bridge.conflist" ]; then
29 rm -rf /etc/cni/net.d/87-podman-bridge.conflist
32 if [ "$1" == "offline" ]; then
33 cp $BUILD_DIR/87-podman-bridge.conflist /etc/cni/net.d/
37 if !(wget $PODMAN_CNI_CONFLIST -P /etc/cni/net.d/); then
42 function create_k8s_regular_user {
43 if [ ! -d "$HOME/.kube" ]; then
47 if [ ! -f /etc/kubernetes/admin.conf]; then
51 cp -rf /etc/kubernetes/admin.conf $HOME/.kube/config
52 chown $(id -u):$(id -g) $HOME/.kube/config
55 function check_k8s_node_status {
56 echo 'checking bootstrap cluster single node status'
60 check_node=$(kubectl get node -o \
61 jsonpath='{.items[0].status.conditions[?(@.reason == "KubeletReady")].status}')
62 if [ $check_node != "" ]; then
63 node_status=${check_node}
66 if [ $node_status == "True" ]; then
73 if [ $node_status != "True" ]; then
74 echo "bootstrap cluster single node status is not ready"
79 function install_ironic_container {
80 # set password for mariadb
81 mariadb_password=$(echo $(date;hostname)|sha256sum |cut -c-20)
83 # Start image downloader container
84 docker run -d --net host --privileged --name ipa-downloader \
85 --env-file "${PWD}/ironic.env" \
86 -v "$IRONIC_DATA_DIR:/shared" "${IPA_DOWNLOADER_IMAGE}" /usr/local/bin/get-resource.sh
88 docker wait ipa-downloader
90 if [ ! -e "$IRONIC_DATA_DIR/html/images/ironic-python-agent.kernel" ] ||
91 [ ! -e "$IRONIC_DATA_DIR/html/images/ironic-python-agent.initramfs" ]; then
92 echo "Failed to get ironic-python-agent"
96 # Start dnsmasq, http, mariadb, and ironic containers using same image
97 # See this file for env vars you can set, like IP, DHCP_RANGE, INTERFACE
98 docker run -d --net host --privileged --name dnsmasq \
99 --env-file "${PWD}/ironic.env" \
100 -v "$IRONIC_DATA_DIR:/shared" --entrypoint /bin/rundnsmasq "${IRONIC_IMAGE}"
102 # For available env vars, see:
103 docker run -d --net host --privileged --name httpd \
104 --env-file "${PWD}/ironic.env" \
105 -v "$IRONIC_DATA_DIR:/shared" --entrypoint /bin/runhttpd "${IRONIC_IMAGE}"
107 # https://github.com/metal3-io/ironic/blob/master/runmariadb.sh
108 docker run -d --net host --privileged --name mariadb \
109 --env-file "${PWD}/ironic.env" \
110 -v "$IRONIC_DATA_DIR:/shared" --entrypoint /bin/runmariadb \
111 --env "MARIADB_PASSWORD=$mariadb_password" "${IRONIC_IMAGE}"
113 # See this file for additional env vars you may want to pass, like IP and INTERFACE
114 docker run -d --net host --privileged --name ironic \
115 --env-file "${PWD}/ironic.env" \
116 --env "MARIADB_PASSWORD=$mariadb_password" \
117 -v "$IRONIC_DATA_DIR:/shared" "${IRONIC_IMAGE}"
119 # Start Ironic Inspector
120 docker run -d --net host --privileged --name ironic-inspector \
121 --env-file "${PWD}/ironic.env" \
122 -v "$IRONIC_DATA_DIR:/shared" "${IRONIC_INSPECTOR_IMAGE}"
125 function remove_k8s_noschedule_taint {
126 #Bootstrap cluster is a single node
127 nodename=$(kubectl get node -o jsonpath='{.items[0].metadata.name}')
128 if !(kubectl taint node $nodename node-role.kubernetes.io/master:NoSchedule-); then
133 function install_k8s_single_node {
134 get_default_interface_ipaddress apiserver_advertise_addr
135 kubeadm_init="kubeadm init --kubernetes-version=$KUBE_VERSION \
136 --pod-network-cidr=$POD_NETWORK_CIDR \
137 --apiserver-advertise-address=$apiserver_advertise_addr"
138 if !(${kubeadm_init}); then
143 function install_dhcp {
144 if [ ! -d $BS_DHCP_DIR ]; then
145 mkdir -p $BS_DHCP_DIR
148 #make sure the dhcp conf sample are configured
149 if [ ! -f $BS_DHCP_DIR/dhcpd.conf ]; then
150 cp $PWD/05_dhcp.conf.sample $BS_DHCP_DIR/dhcpd.conf
153 kubectl create -f $PWD/04_dhcp.yaml
156 function reset_dhcp {
157 kubectl delete --ignore-not-found=true -f $PWD/04_dhcp.yaml
158 if [ -d $BS_DHCP_DIR ]; then
163 function create_ironic_env {
164 cat <<EOF > ${PWD}/ironic.env
165 PROVISIONING_INTERFACE=provisioning
166 DHCP_RANGE=172.22.0.10,172.22.0.100
167 IPA_BASEURI=https://images.rdoproject.org/train/rdo_trunk/current-tripleo
168 DEPLOY_KERNEL_URL=http://172.22.0.1/images/ironic-python-agent.kernel
169 DEPLOY_RAMDISK_URL=http://172.22.0.1/images/ironic-python-agent.initramfs
170 IRONIC_ENDPOINT=http://172.22.0.1:6385/v1/
171 IRONIC_INSPECTOR_ENDPOINT=http://172.22.0.1:5050/v1/
172 CACHEURL=http://172.22.0.1/images
173 IRONIC_FAST_TRACK=false
178 #Kubeadm usage is deprecated in v1,0,0 version
180 #install_k8s_single_node
181 #check_cni_network $1
182 #create_k8s_regular_user
183 #check_k8s_node_status
184 #remove_k8s_noschedule_taint
187 #Todo - error handling mechanism
189 install_ironic_container
192 if [ "$#" -eq 0 ]; then
194 elif [ "$1" == "-o" ]; then
196 elif [ "$1" == "--dhcp-start" ]; then
198 echo "wait for 320s for nodes to be assigned"
200 elif [ "$1" == "--dhcp-reset" ]; then
202 echo "wait for 320s for nodes to be re-assigned"