#!/bin/bash
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
# For your reference only.
# It's better to run the below scripts step by step.

export deploy_k8s=true

[[ $CCI_SRC ]] || export CCI_SRC=/c/cbs
cd $CCI_SRC/sparrow || exit

kubectl_create()
{
	nodename=$(kubectl get no | grep master|awk '{print $1}')
	sed -i "s#NODENAME#${nodename}#g" $CCI_SRC/container/storageclass.yaml
	sed -i "s#NODENAME#${nodename}#g" $CCI_SRC/container/*/k8s/*deployment.yaml

	kubectl create ns ems1
	kubectl create -f $CCI_SRC/container/ -n ems1
}

kubectl_label()
{
	for node in $(cat /etc/compass-ci/remote-hosts|grep -v "^#"|awk '{print $1}') 
	do
		kubectl label no $node type=testbox
	done
}

install_master()
{
	0-package/install
	1-storage/tiny
	1-storage/permission
	2-network/iptables
	3-code/git
	3-code/dev-env "ems1"
	. /etc/profile.d/compass.sh
	kubectl_create
	kubectl_label
	4-docker/buildall
	find $CCI_SRC/sbin/ -name "es-*-mapping.sh" -exec sh {} \;
}

install_master
k8s/remote-install-worker "/etc/compass-ci/setup.yaml"
k8s/remote-install-multi-docker "/etc/compass-ci/remote-hosts" "$HOSTNAME"
k8s/pack-lkp
