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