-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yaml
108 lines (94 loc) · 4.21 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: 'Virtual Kubernetes Cluster'
description: 'Create or delete a virtual cluster ephemeral environment on Uffizzi'
author: 'Vibhav Bobade'
branding:
color: 'yellow'
icon: 'upload-cloud'
inputs:
server:
description: 'URL to Uffizzi'
required: false
default: 'https://app.uffizzi.com/'
cluster-name:
description: 'Name of the Uffizzi cluster which is going to get created'
required: true
kubeconfig:
description: 'Path to kubeconfig file.'
default: ${{ github.workspace }}/kubeconfig
required: false
k8s-manifest-file:
description: 'Path to the k8s manifest file that needs to be applied'
default: ''
required: false
action:
description: 'Specify whether to create or delete a cluster'
default: 'create'
required: false
k8s-version:
description: 'Specify the version of kubernetes you want to create'
required: false
runs:
using: 'composite'
steps:
- name: Setup binary
uses: UffizziCloud/setup-action@main
- shell: bash
# Check if the input variable `action` is create
if: ${{ inputs.action == 'create' }}
run: |
function kubernetes_version_flag() {
local kubernetes_version=${{ inputs.k8s-version }}
if [ -n "$kubernetes_version" ]; then
echo "--k8s-version $kubernetes_version"
else
echo $kubernetes_version
fi
}
function kubeconfig_file_flag() {
local kubeconfig_name=${{ inputs.kubeconfig }}
if [ -n "$kubeconfig_name" ]; then
echo "--kubeconfig $kubeconfig_name"
else
echo "--kubeconfig kubeconfig"
fi
}
export UFFIZZI_SERVER=${{ inputs.server }}
export REQUEST_TOKEN=${ACTIONS_ID_TOKEN_REQUEST_TOKEN}
export REQUEST_TOKEN_URL=${ACTIONS_ID_TOKEN_REQUEST_URL}
OIDC_TOKEN=$(curl -sLS "${REQUEST_TOKEN_URL}&audience=uffizzi" -H "User-Agent: actions/oidc-client" -H "Authorization: Bearer $REQUEST_TOKEN")
./uffizzi-linux login_by_identity_token --oidc-token "${OIDC_TOKEN}" --server "${UFFIZZI_SERVER}"
chmod 777 uffizzi-linux
kubeconfig_flag=$(kubeconfig_file_flag)
# Identify if a Cluster for this PR exists.
if ./uffizzi-linux cluster list | grep --quiet "${{ inputs.cluster-name }}$"
then
./uffizzi-linux cluster update-kubeconfig "${{ inputs.cluster-name }}" --kubeconfig kubeconfig
else
k8s_version_flag=$(kubernetes_version_flag)
./uffizzi-linux cluster create "${{ inputs.cluster-name }}" --creation-source=github_actions --kubeconfig kubeconfig $k8s_version_flag
echo "Uffizzi Cluster \`${{ inputs.cluster-name }}\` created." | tee --append $GITHUB_STEP_SUMMARY
export KUBERNETES_SERVICE_HOST=`yq '.clusters[0].cluster.server' < ./${{ inputs.kubeconfig-name }} | cut -d'/' -f3`
echo "Available at \`${KUBERNETES_SERVICE_HOST}\`." | tee --append $GITHUB_STEP_SUMMARY
echo "You can access this cluster with a command like \`uffizzi cluster update-kubeconfig ${UFFIZZI_CLUSTER} $kubeconfig_flag\`" | tee --append $GITHUB_STEP_SUMMARY
echo "and then \`kubectl --kubeconfig /tmp/kubeconfig\` or similar." | tee --append $GITHUB_STEP_SUMMARY
sleep 3
fi
mv --no-clobber ./kubeconfig "${{ inputs.kubeconfig }}"
echo "kubeconfig file at ${{ inputs.kubeconfig }}"
- shell: bash
# Check if the input variable `action` is delete
if: ${{ inputs.action == 'delete' }}
run: |
export UFFIZZI_SERVER=${{ inputs.server }}
export REQUEST_TOKEN=${ACTIONS_ID_TOKEN_REQUEST_TOKEN}
export REQUEST_TOKEN_URL=${ACTIONS_ID_TOKEN_REQUEST_URL}
OIDC_TOKEN=$(curl -sLS "${REQUEST_TOKEN_URL}&audience=uffizzi" -H "User-Agent: actions/oidc-client" -H "Authorization: Bearer $REQUEST_TOKEN")
./uffizzi-linux login_by_identity_token --oidc-token "${OIDC_TOKEN}" --server "${UFFIZZI_SERVER}"
# Identify if a Cluster for this PR exists.
if ./uffizzi-linux cluster list | grep --quiet "${{ inputs.cluster-name }}$"
then
# delete the cluster if it exists
./uffizzi-linux cluster delete "${{ inputs.cluster-name }}"
else
echo "Given cluster ${{ inputs.cluster-name }} does not exist"
fi