blob: d4053aa3a00d472228fe0baafbe569310ac16581 [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
27declare $(sed -e 's/:[^:\/\/,:4]/=/g;s/ *=/=/g;s/-/_/g' $1 | grep 'certificate\|key\|server' | tr -d ' ')
28
29### Uncomment if separate files needed
30printf "Creating 'ca.crt', 'client.crt' and 'client.key'\n"
31echo "# '${ca_crt}'"
32echo $certificate_authority_data | base64 -d >${ca_crt}
33echo "# '${client_crt}'"
34echo $client_certificate_data | base64 -d >${client_crt}
35echo "# '${client_key}'"
36echo $client_key_data | base64 -d >${client_key}
37
38printf "Generating 'kubespec.yaml'\n"
39cat << EOF >kubespec_generated.yaml
40---
41existing@kubernetes:
42 server: $server
43 certificate-authority: ${ca_crt}
44 client-certificate: ${client_crt}
45 client-key: ${client_key}
46 tls_insecure: True
47EOF