aboutsummaryrefslogtreecommitdiffstats
path: root/csit/run-k8s-csit.sh
blob: 63df5dc2c6f176785a5ab4f437a267151f4dc7cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
#
# ============LICENSE_START====================================================
#  Copyright (C) 2022 Nordix Foundation.
# =============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END======================================================

# This script spins up kubernetes cluster in Microk8s for deploying policy helm charts.

function spin_microk8s_cluster () {
    echo "Verify if Microk8s cluster is running.."
    microk8s version
    exitcode="${?}"

    if [ "$exitcode" -ne 0 ];  then
        echo "Microk8s cluster not available, Spinning up the cluster.."
        sudo snap install microk8s --classic --channel=1.25/stable

	      if [ "${?}" -ne 0 ];  then
	          echo "Failed to install kubernetes cluster. Aborting.."
		        return 1
        fi
        echo "Microk8s cluster installed successfully"
        sudo usermod -a -G microk8s $USER
        echo "Enabling DNS and helm3"
        microk8s.enable dns helm3
        echo "Creating configuration file for Microk8s"
        microk8s kubectl config view --raw > $HOME/.kube/config
        chmod 600 $HOME/.kube/config
        echo "K8s installation completed"
    else
        echo "K8s cluster is already running"
	      return 0
    fi

}

function teardown_cluster () {
    echo "Removing k8s cluster and k8s configuration file"
    sudo snap remove microk8s;rm -rf $HOME/.kube/config
    echo "K8s Cluster removed"
}


if [ $1 == "install" ];  then
    spin_microk8s_cluster
    if [ "${?}" -eq 0 ];  then
        echo "Installing policy helm charts in the default namespace"
        cd ../helm/;helm dependency build policy;microk8s helm install dev-policy policy;
        echo "Policy chart installation completed"
    fi

elif [ $1 == "uninstall" ];  then
    teardown_cluster
else
    echo "Invalid arguments provided. Usage: $0 [option..] {install | uninstall}"
fi