Prepare scripts and scenarios to use in MOSK testing of Kubernetes
Related-PROD: PROD-36128
Change-Id: I0d9145045c2a95e34966519157e9c7200bea4e3e
diff --git a/k8s/gen_kubespec.sh b/k8s/gen_kubespec.sh
new file mode 100644
index 0000000..d4053aa
--- /dev/null
+++ b/k8s/gen_kubespec.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# files
+ca_crt=$(pwd)/ca.crt
+client_crt=$(pwd)/client.crt
+client_key=$(pwd)/client.key
+
+function show_help() {
+ printf "\ngen_kubespec.sh <kubeconfig.yaml>\n"
+ exit 1
+}
+
+# Check for a config file
+if [[ -z ${1+x} ]]; then
+ show_help
+ printf "\nERROR: No kubeconfig.yaml specified\n"
+ exit 1
+fi
+
+# Check if file exists
+if [[ ! -f $1 ]]; then
+ show_help
+ printf "\nERROR: Supplied kubeconfig file not exists at '$1'\n"
+ exit 1
+fi
+
+# extract data as variables
+declare $(sed -e 's/:[^:\/\/,:4]/=/g;s/ *=/=/g;s/-/_/g' $1 | grep 'certificate\|key\|server' | tr -d ' ')
+
+### Uncomment if separate files needed
+printf "Creating 'ca.crt', 'client.crt' and 'client.key'\n"
+echo "# '${ca_crt}'"
+echo $certificate_authority_data | base64 -d >${ca_crt}
+echo "# '${client_crt}'"
+echo $client_certificate_data | base64 -d >${client_crt}
+echo "# '${client_key}'"
+echo $client_key_data | base64 -d >${client_key}
+
+printf "Generating 'kubespec.yaml'\n"
+cat << EOF >kubespec_generated.yaml
+---
+existing@kubernetes:
+ server: $server
+ certificate-authority: ${ca_crt}
+ client-certificate: ${client_crt}
+ client-key: ${client_key}
+ tls_insecure: True
+EOF