7 if [[ $EUID -ne 0 ]]; then
8 echo "confgiure script must be run as root"
12 function get_default_inteface_ipaddress() {
14 local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
15 local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
16 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 if [ "$1" == "offline" ]; then
30 cp $BUILD_DIR/87-podman-bridge.conflist /etc/cni/net.d/
34 if !(wget $PODMAN_CNI_CONFLIST -P /etc/cni/net.d/); then
40 function create_k8s_regular_user() {
41 if [ ! -d "$HOME/.kube" ]; then
45 if [ ! -f /etc/kubernetes/admin.conf]; then
49 cp -rf /etc/kubernetes/admin.conf $HOME/.kube/config
50 chown $(id -u):$(id -g) $HOME/.kube/config
53 function check_k8s_node_status(){
54 echo 'checking bootstrap cluster single node status'
59 check_node=$(kubectl get node -o \
60 jsonpath='{.items[0].status.conditions[?(@.reason == "KubeletReady")].status}')
61 if [ $check_node != "" ]; then
62 node_status=${check_node}
65 if [ $node_status == "True" ]; then
72 if [ $node_status != "True" ]; then
73 echo "bootstrap cluster single node status is not ready"
78 function install_podman() {
79 # set password for mariadb
80 mariadb_password=$(echo $(date;hostname)|sha256sum |cut -c-20)
83 podman pod create -n ironic-pod
85 # Start dnsmasq, http, mariadb, and ironic containers using same image
86 podman run -d --net host --privileged --name dnsmasq --pod ironic-pod \
87 -v $IRONIC_DATA_DIR:/shared --entrypoint /bin/rundnsmasq ${IRONIC_IMAGE}
89 podman run -d --net host --privileged --name httpd --pod ironic-pod \
90 -v $IRONIC_DATA_DIR:/shared --entrypoint /bin/runhttpd ${IRONIC_IMAGE}
92 podman run -d --net host --privileged --name mariadb --pod ironic-pod \
93 -v $IRONIC_DATA_DIR:/shared --entrypoint /bin/runmariadb \
94 --env MARIADB_PASSWORD=$mariadb_password ${IRONIC_IMAGE}
96 podman run -d --net host --privileged --name ironic --pod ironic-pod \
97 --env MARIADB_PASSWORD=$mariadb_password \
98 -v $IRONIC_DATA_DIR:/shared ${IRONIC_IMAGE}
100 # Start Ironic Inspector
101 podman run -d --net host --privileged --name ironic-inspector \
102 --pod ironic-pod "${IRONIC_INSPECTOR_IMAGE}"
105 function remove_k8s_noschedule_taint() {
106 #Bootstrap cluster is a single node
107 nodename=$(kubectl get node -o jsonpath='{.items[0].metadata.name}')
108 if !(kubectl taint node $nodename node-role.kubernetes.io/master:NoSchedule-); then
113 function install_k8s_single_node() {
114 get_default_inteface_ipaddress apiserver_advertise_addr
115 kubeadm_init="kubeadm init --kubernetes-version=$KUBE_VERSION \
116 --pod-network-cidr=$POD_NETWORK_CIDR \
117 --apiserver-advertise-address=$apiserver_advertise_addr"
118 if !(${kubeadm_init}); then
125 install_k8s_single_node
127 create_k8s_regular_user
128 check_k8s_node_status
129 remove_k8s_noschedule_taint
132 #Todo - error handling mechanism
136 if [ "$1" == "-o" ]; then