blob: 08da40183a7bc61272960c3c4ed477d442791854 [file] [log] [blame]
Alexf7c78632021-02-12 16:44:02 -06001#!/bin/bash
2# files
Ievgeniia Zadorozhnac6582cb2021-05-13 17:14:31 +03003cd /artifacts
Alexf7c78632021-02-12 16:44:02 -06004ca_crt=$(pwd)/ca.crt
5client_crt=$(pwd)/client.crt
6client_key=$(pwd)/client.key
7
8function show_help() {
9 printf "\ngen_kubespec.sh <kubeconfig.yaml>\n"
10 exit 1
11}
12
13# Check for a config file
14if [[ -z ${1+x} ]]; then
15 show_help
16 printf "\nERROR: No kubeconfig.yaml specified\n"
17 exit 1
18fi
19
20# Check if file exists
21if [[ ! -f $1 ]]; then
22 show_help
23 printf "\nERROR: Supplied kubeconfig file not exists at '$1'\n"
24 exit 1
25fi
26
27# extract data as variables
Alex18fc3812021-03-22 09:41:37 -050028declare $(sed -e 's/:[^:\/\/,:443,:6443]/=/g;s/ *=/=/g;s/-/_/g' $1 | grep 'certificate\|key\|server' | tr -d ' ')
29echo "# Declared variable: server=$server"
Alexf7c78632021-02-12 16:44:02 -060030
31### Uncomment if separate files needed
Alex18fc3812021-03-22 09:41:37 -050032printf "# Creating 'ca.crt', 'client.crt' and 'client.key'\n"
Alexf7c78632021-02-12 16:44:02 -060033echo "# '${ca_crt}'"
34echo $certificate_authority_data | base64 -d >${ca_crt}
35echo "# '${client_crt}'"
36echo $client_certificate_data | base64 -d >${client_crt}
37echo "# '${client_key}'"
38echo $client_key_data | base64 -d >${client_key}
39
40printf "Generating 'kubespec.yaml'\n"
41cat << EOF >kubespec_generated.yaml
42---
43existing@kubernetes:
44 server: $server
45 certificate-authority: ${ca_crt}
46 client-certificate: ${client_crt}
47 client-key: ${client_key}
48 tls_insecure: True
49EOF