Adding CNFM testing basic setup
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / package / docker / src / main / docker / docker-files / kind-cluster / entrypoint.sh
1 #!/bin/bash
2 # ============LICENSE_START=======================================================
3 #   Copyright (C) 2023 Nordix Foundation.
4 # ================================================================================
5 #  Licensed under the Apache License, Version 2.0 (the "License");
6 #  you may not use this file except in compliance with the License.
7 #  You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #  Unless required by applicable law or agreed to in writing, software
12 #  distributed under the License is distributed on an "AS IS" BASIS,
13 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #  See the License for the specific language governing permissions and
15 #  limitations under the License.
16 #
17 #  SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19
20 # Script copied from https://hub.docker.com/r/devopps/kind-cluster-buster
21
22 set -o errexit
23 set -o nounset
24 set -o pipefail
25
26 # Startup Docker daemon and wait for it to be ready.
27 echo "Running entrypoint-original.sh .."
28 /entrypoint-original.sh bash -c "touch /dockerd-ready && sleep infinity" &
29 while [ ! -f /dockerd-ready ]; do sleep 10; done
30
31 echo "Setting up KIND cluster"
32
33 # Startup a KIND cluster.
34 API_SERVER_ADDRESS=${API_SERVER_ADDRESS:-$(hostname -i)}
35 echo "hostname: ${API_SERVER_ADDRESS}"
36 sed -ri "s/^(\s*)(apiServerAddress\s*:\s*apiServerAddress\s*$)/\1apiServerAddress: ${API_SERVER_ADDRESS}/" kind-config.yaml
37
38 CERT_SANS=(${CERT_SANS:-""})
39 CERT_SANS+=(${API_SERVER_ADDRESS})
40 CERT_SANS+=($(hostname -i))
41 CERT_SANS+=(localhost)
42 CERT_SANS+=(127.0.0.1)
43
44 for node in $(kubectl get nodes -o wide --no-headers | awk '{print $6}'); do
45 echo "node: $node"
46 CERT_SANS+=(node)
47 done
48
49 UNIQUE_CERT_SANS=($(echo "${CERT_SANS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
50
51 for hostname in "${UNIQUE_CERT_SANS[@]}"; do
52 cat <<EOF >> kind-config.yaml
53 - group: kubeadm.k8s.io
54   version: v1beta2
55   kind: ClusterConfiguration
56   patch: |
57     - op: add
58       path: /apiServer/certSANs/-
59       value: ${hostname}
60 EOF
61 done
62
63 kind create cluster --config=kind-config.yaml --image=${KIND_NODE_IMAGE-"devopps/kind-node:v1.21.1"} --wait=900s
64
65 while read -r line;
66 do
67   echo "$line";
68 done < "$HOME/.kube/config"
69
70 CONFIG_ADDRESS=$HOME/.kube/config
71
72 echo "Finished Setting up KIND cluster $CONFIG_ADDRESS"
73 exec "$@"