fix/cicd #3
@@ -1,15 +1,15 @@
|
||||
name: Setup kubectl
|
||||
description: "Reads kube config from inputs and sets KUBECONFIG"
|
||||
description: "Reads kube config from inputs and sets kube config"
|
||||
|
||||
inputs:
|
||||
kube_server:
|
||||
description: "Kubernetes API server address"
|
||||
description: "Kubernetes server address and port. Example (https://serverip:6443)"
|
||||
required: true
|
||||
kube_ca_base64:
|
||||
description: "Base64-encoded CA certificate"
|
||||
description: "Base64-encoded Kubernetes cluster CA certificate"
|
||||
required: true
|
||||
kube_token:
|
||||
description: "ServiceAccount token"
|
||||
description: "Kubernetes ServiceAccount token"
|
||||
required: true
|
||||
|
||||
runs:
|
||||
@@ -18,9 +18,34 @@ runs:
|
||||
- name: Create kubeconfig
|
||||
shell: bash
|
||||
run: |
|
||||
set -x
|
||||
mkdir -p "${GITHUB_TEMP}/.kube"
|
||||
set -euo pipefail
|
||||
|
||||
# check arguments
|
||||
ERROR=0
|
||||
|
||||
if [ -z "${{ inputs.kube_server }}" ]; then
|
||||
echo "❌ ERROR: kube_server input is empty or not set"
|
||||
$ERROR=1
|
||||
fi
|
||||
|
||||
if [ -z "${{ inputs.kube_ca_base64 }}" ]; then
|
||||
echo "❌ ERROR: kube_ca_base64 input is empty or not set"
|
||||
$ERROR=1
|
||||
fi
|
||||
|
||||
if [ -z "${{ inputs.kube_server }}" ]; then
|
||||
echo "❌ ERROR: kube_token input is empty or not set"
|
||||
$ERROR=1
|
||||
fi
|
||||
|
||||
if [ "$ERROR" != 0 ]; then
|
||||
echo "❌ ERROR code $ERROR"
|
||||
exit "$ERROR"
|
||||
fi
|
||||
# end check arguments
|
||||
|
||||
# creates kube config
|
||||
mkdir -p "${GITHUB_TEMP}/.kube"
|
||||
cat <<EOF > "${GITHUB_TEMP}/.kube/config"
|
||||
apiVersion: v1
|
||||
kind: Config
|
||||
@@ -41,11 +66,10 @@ runs:
|
||||
user:
|
||||
token: ${{ inputs.kube_token }}
|
||||
EOF
|
||||
echo "config created - ${GITHUB_TEMP}/.kube/config"
|
||||
ls -lah ${GITHUB_TEMP}/.kube/config
|
||||
|
||||
# sets KUBECONFIG environment variable
|
||||
echo "KUBECONFIG=${GITHUB_TEMP}/.kube/config" >> "${GITHUB_ENV}"
|
||||
|
||||
# curl -vk \
|
||||
# --cacert ca.crt \
|
||||
# -H "Authorization: Bearer $KUBE_TOKEN" \
|
||||
# https://<server>:6443/version
|
||||
# tests communication to server
|
||||
curl -k -cacert <(echo "${{ inputs.kube_ca_base64 }}" | base64 -d) -H "Authorization: Bearer ${{ inputs.kube_token }}" ${{ inputs.kube_server }}/version
|
||||
|
||||
|
||||
Reference in New Issue
Block a user