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_inteface_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'"
23 function check_cni_network {
24 #since bootstrap cluster is a single node cluster,
25 #podman and bootstap cluster have same network configuration to avoid the cni network conf conflicts
26 if [ ! -d "/etc/cni/net.d" ]; then
27 mkdir -p "/etc/cni/net.d"
30 if [ ! -f "/etc/cni/net.d/87-podman-bridge.conflist" ]; then
31 if [ "$1" == "offline" ]; then
32 cp $BUILD_DIR/87-podman-bridge.conflist /etc/cni/net.d/
36 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_podman {
80 # set password for mariadb
81 mariadb_password=$(echo $(date;hostname)|sha256sum |cut -c-20)
84 podman pod create -n ironic-pod
86 # Start dnsmasq, http, mariadb, and ironic containers using same image
87 podman run -d --net host --privileged --name dnsmasq --pod ironic-pod \
88 -v $IRONIC_DATA_DIR:/shared --entrypoint /bin/rundnsmasq ${IRONIC_IMAGE}
90 podman run -d --net host --privileged --name httpd --pod ironic-pod \
91 -v $IRONIC_DATA_DIR:/shared --entrypoint /bin/runhttpd ${IRONIC_IMAGE}
93 podman run -d --net host --privileged --name mariadb --pod ironic-pod \
94 -v $IRONIC_DATA_DIR:/shared --entrypoint /bin/runmariadb \
95 --env MARIADB_PASSWORD=$mariadb_password ${IRONIC_IMAGE}
97 podman run -d --net host --privileged --name ironic --pod ironic-pod \
98 --env MARIADB_PASSWORD=$mariadb_password \
99 -v $IRONIC_DATA_DIR:/shared ${IRONIC_IMAGE}
101 # Start Ironic Inspector
102 podman run -d --net host --privileged --name ironic-inspector \
103 --pod ironic-pod "${IRONIC_INSPECTOR_IMAGE}"
106 function remove_k8s_noschedule_taint {
107 #Bootstrap cluster is a single node
108 nodename=$(kubectl get node -o jsonpath='{.items[0].metadata.name}')
109 if !(kubectl taint node $nodename node-role.kubernetes.io/master:NoSchedule-); then
114 function install_k8s_single_node {
115 get_default_inteface_ipaddress apiserver_advertise_addr
116 kubeadm_init="kubeadm init --kubernetes-version=$KUBE_VERSION \
117 --pod-network-cidr=$POD_NETWORK_CIDR \
118 --apiserver-advertise-address=$apiserver_advertise_addr"
119 if !(${kubeadm_init}); then
126 install_k8s_single_node
128 create_k8s_regular_user
129 check_k8s_node_status
130 remove_k8s_noschedule_taint
133 #Todo - error handling mechanism
137 if [ "$1" == "-o" ]; then