-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
299 lines (265 loc) · 12.3 KB
/
action.yaml
File metadata and controls
299 lines (265 loc) · 12.3 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
---
name: Run Integration Test
description: |
This action runs Stackable Operator integration tests on various platforms and
Kubernetes distributions.
inputs:
# Test inputs
test-mode:
description: Interu test mode to run in
test-mode-input:
description: The Interu profile or runner to be used based on the test-mode
test-suite:
description: The Beku test-suite to run
test:
description: Matching Beku tests to run
# Tokens
replicated-api-token:
description: Replicated API token
# Tool versions
interu-version:
description: Version of interu
# See https://github.com/stackabletech/actions/releases for latest version
default: 0.2.0
beku-version:
description: Version of beku
# See https://github.com/stackabletech/beku.py/releases for latest version
default: 0.0.10
kubectl-version:
description: Version of kubectl
# See https://dl.k8s.io/release/stable.txt for latest version
default: v1.34.1
kuttl-version:
description: Version of kubectl-kuttl
# See https://github.com/kudobuilder/kuttl/releases for latest version
default: 0.22.0
helm-version:
description: Version of helm
# See https://github.com/helm/helm/releases for latest version
default: v3.19.0
stackablectl-version:
description: Version of stackablectl
# See https://github.com/stackabletech/stackable-cockpit/releases for latest version
default: 1.1.0
outputs:
start-time:
description: The date and time this integration test was started.
value: ${{ steps.start-time.outputs.START_TIME }}
end-time:
description: The date and time this integration test finished.
value: ${{ steps.end-time.outputs.END_TIME }}
health:
description: The health of this integration test over the last few tries.
value: ${{ steps.health.outputs.HEALTH }}
failed-tests:
description: The (potentially empty) list of failed tests
value: ${{ steps.failed-tests.outputs.FAILED_TESTS }}
runs:
using: composite
steps:
- name: Install interu
env:
INTERU_VERSION: ${{ inputs.interu-version }}
GITHUB_DEBUG: ${{ runner.debug }}
shell: bash
run: "$GITHUB_ACTION_PATH/../.scripts/actions/install_interu.sh"
- name: Extract Test and Instance Configuration
env:
TEST_MODE_INPUT: ${{ inputs.test-mode-input }}
TEST_SUITE: ${{ inputs.test-suite }}
TEST_MODE: ${{ inputs.test-mode }}
TEST: ${{ inputs.test }}
GITHUB_DEBUG: ${{ runner.debug }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}"
shell: bash
run: |
set -euo pipefail
[ -n "$GITHUB_DEBUG" ] && set -x
# Generate the cluster name
echo "KUBERNETES_CLUSTER_NAME=integration-test-${GITHUB_REPOSITORY}-${GITHUB_RUN_ID}" | tee -a "$GITHUB_ENV"
# Run interu to expand parameters into GITHUB_ENV
if [ "$TEST_MODE" == "profile" ]; then
[ -n "${TEST_SUITE:-}" ] && echo "::warning::The test-suite input is ignored, because a profile is selected."
[ -n "${TEST:-}" ] && echo "::warning::The test input is ignored, because a profile is selected."
interu --instances "$GITHUB_ACTION_PATH/instances.yaml" profile "$TEST_MODE_INPUT" --check-test-definitions --output "$GITHUB_ENV"
else
[ -n "${TEST_SUITE:-}" ] && ARGS+=" --test-suite $TEST_SUITE"
[ -n "${TEST:-}" ] && ARGS+=" --test $TEST"
interu --instances "$GITHUB_ACTION_PATH/instances.yaml" custom "$TEST_MODE_INPUT" ${ARGS:-} --output "$GITHUB_ENV"
fi
# Install all tools BEFORE creating the cluster, because if some of the tools fail to download
# and are therefore not available, there is no need to create the cluster or run the tests,
# because the tests can never run in the first place.
- name: Install kubectl, kubectl-kuttl, and helm
env:
KUBECTL_VERSION: ${{ inputs.kubectl-version }}
KUTTL_VERSION: ${{ inputs.kuttl-version }}
HELM_VERSION: ${{ inputs.helm-version }}
GITHUB_DEBUG: ${{ runner.debug }}
shell: bash
run: |
"$GITHUB_ACTION_PATH/../.scripts/actions/install_kubectl.sh"
"$GITHUB_ACTION_PATH/../.scripts/actions/install_kubectl_kuttl.sh"
"$GITHUB_ACTION_PATH/../.scripts/actions/install_helm.sh"
# Python3 is already installed, if we ever need to specify the version, we can use the
# setup-python action.
# See https://github.com/actions/runner-images/blob/main/images/ubuntu/scripts/build/install-python.sh
#
# mikefarah/yq is already installed on the runner
# See https://github.com/actions/runner-images/blob/main/images/ubuntu/scripts/build/install-yq.sh
- name: Install stackablectl
env:
STACKABLECTL_VERSION: ${{ inputs.stackablectl-version }}
GITHUB_DEBUG: ${{ runner.debug }}
shell: bash
run: "$GITHUB_ACTION_PATH/../.scripts/actions/install_stackablectl.sh"
- name: Install beku
env:
BEKU_VERSION: ${{ inputs.beku-version }}
GITHUB_DEBUG: ${{ runner.debug }}
shell: bash
run: |
set -euo pipefail
[ -n "$GITHUB_DEBUG" ] && set -x
pip install "beku-stackabletech==$BEKU_VERSION"
- name: Install apt packages
shell: bash
run: |
set -euo pipefail
sudo apt update
sudo apt install -y \
gettext-base
- name: Prepare Replicated Cluster
id: prepare-replicated-cluster
uses: replicatedhq/replicated-actions/create-cluster@291bef61a059631e39e84f8470f86152171c4c20 # v1.26.0
with:
# See: https://github.com/replicatedhq/replicated-actions/tree/main/create-cluster#inputs
api-token: ${{ inputs.replicated-api-token }}
cluster-name: ${{ env.KUBERNETES_CLUSTER_NAME }}
kubernetes-distribution: ${{ env.INTERU_KUBERNETES_DISTRIBUTION }}
kubernetes-version: ${{ env.INTERU_KUBERNETES_VERSION }}
ttl: ${{ env.INTERU_CLUSTER_TTL }}
node-groups: ${{ env.INTERU_NODE_GROUPS }}
# FIXME (@Techassi): Add test-suite and test here
tags: |
- key: kubernetes-distribution
value: ${{ env.INTERU_KUBERNETES_DISTRIBUTION }}
- key: triggered-by
value: ${{ github.triggering_actor }}
- key: test-parallelism
value: "${{ env.BEKU_TEST_PARALLELISM }}"
- name: Set Replicated kubeconfig
env:
KUBECONFIG: ${{ steps.prepare-replicated-cluster.outputs.cluster-kubeconfig }}
shell: bash
run: |
set -euo pipefail
mkdir ~/.kube
echo "$KUBECONFIG" > ~/.kube/config
- name: Extract Operator Name
env:
REPOSITORY: ${{ github.repository }}
shell: bash
run: |
set -euo pipefail
OPERATOR_NAME=$(echo "$REPOSITORY" | cut -d / -f 2 | sed 's/-operator//g')
echo "OPERATOR_NAME=$OPERATOR_NAME" | tee -a "$GITHUB_ENV"
- name: Install OpenTelemetry Operator
shell: bash
run: |
set -euo pipefail
echo "::group::kubectl apply"
kubectl kustomize --enable-helm "${GITHUB_ACTION_PATH}/kustomize/bases/opentelemetry-operator" | kubectl apply -f -
kubectl -n opentelemetry-operator wait --for condition=Progressing deploy/opentelemetry-operator --timeout=300s
kubectl -n opentelemetry-operator wait --for condition=Available deploy/opentelemetry-operator --timeout=300s
kubectl -n opentelemetry-operator get pods
echo "::endgroup::"
- name: Apply OpenTelemetry Collectors configurations
shell: bash
env:
GITHUB_TRIGGERED_BY: ${{ github.triggering_actor }}
run: |
set -euo pipefail
echo "::group::get info"
INTEGRATION_TEST_INFO="${GITHUB_ACTION_PATH}/kustomize/overlays/replicated/integration-test-info.env"
echo "KUBERNETES_CLUSTER_NAME=${KUBERNETES_CLUSTER_NAME}" | tee -a "$INTEGRATION_TEST_INFO"
echo "KUBERNETES_DISTRIBUTION=${INTERU_KUBERNETES_DISTRIBUTION}" | tee -a "$INTEGRATION_TEST_INFO"
echo "KUBERNETES_VERSION=${INTERU_KUBERNETES_VERSION}" | tee -a "$INTEGRATION_TEST_INFO"
echo "TRIGGERED_BY=${GITHUB_TRIGGERED_BY}" | tee -a "$INTEGRATION_TEST_INFO"
echo "::endgroup::"
echo "::group::kubectl apply"
kubectl apply -k "${GITHUB_ACTION_PATH}/kustomize/overlays/replicated"
echo "Waiting a few seconds for the operator to create the deployment" && sleep 5
kubectl -n opentelemetry-operator wait --for condition=Progressing deploy/replicated-kubernetes-events-collector --timeout=300s
kubectl -n opentelemetry-operator wait --for condition=Available deploy/replicated-kubernetes-events-collector --timeout=300s
kubectl -n opentelemetry-operator rollout status ds replicated-container-log-scrape-collector --timeout=300s
echo "::endgroup::"
echo "::group::kubectl get"
kubectl -n opentelemetry-operator get opentelemetrycollectors
kubectl -n opentelemetry-operator get pods
echo "::endgroup::"
- name: Record Test Start Time
id: start-time
shell: bash
run: |
echo "START_TIME=$(date +'%Y-%m-%dT%H:%M:%S')" | tee -a "$GITHUB_OUTPUT"
- name: Run Integration Test
id: integration-test
env:
REF_NAME: ${{ github.ref_name }}
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
OPERATOR_VERSION=$("$GITHUB_ACTION_PATH/../.scripts/actions/get_operator_version.sh" "$REF_NAME")
python ./scripts/run-tests --skip-tests --operator "$OPERATOR_NAME=$OPERATOR_VERSION" | tee -a test-output.log
[ -n "${BEKU_TEST_SUITE:-}" ] && ARGS+=" --test-suite $BEKU_TEST_SUITE"
[ -n "${BEKU_TEST:-}" ] && ARGS+=" --test $BEKU_TEST"
python ./scripts/run-tests --skip-release --log-level debug --parallel "$BEKU_TEST_PARALLELISM" ${ARGS:-} | tee -a test-output.log
- name: Record Test End Time
id: end-time
if: always()
shell: bash
run: |
echo "END_TIME=$(date +'%Y-%m-%dT%H:%M:%S')" | tee -a "$GITHUB_OUTPUT"
- name: Destroy Replicated Cluster
if: always()
# If the creation of the cluster failed, we don't want to error and abort
continue-on-error: true
uses: replicatedhq/replicated-actions/remove-cluster@291bef61a059631e39e84f8470f86152171c4c20 # v1.26.0
with:
# See: https://github.com/replicatedhq/replicated-actions/tree/main/remove-cluster#inputs
api-token: ${{ inputs.replicated-api-token }}
cluster-id: ${{ steps.prepare-replicated-cluster.outputs.cluster-id }}
- name: Extract Failed Tests
id: failed-tests
# The success() function is automatically used if no other status function is used.
# See https://docs.github.com/en/actions/reference/workflows-and-actions/expressions#failure-with-conditions
if: failure() && steps.integration-test.conclusion == 'failure'
shell: bash
run: |
# Only look at the last 200 lines of test output which should be more than enough to capture all test results
FAILED_TESTS=$(tail --lines 200 test-output.log | grep -E '\s{8}--- FAIL:' | sed -e 's|^.*kuttl/harness/||')
echo "FAILED_TESTS<<EOF\n$FAILED_TESTS\nEOF" | tee -a "$GITHUB_OUTPUT"
- name: Calculate Health
if: always()
id: health
env:
INTEGRATION_TEST_CONCLUSION: ${{ steps.integration-test.conclusion }}
WORKFLOW_NAME: "Integration Test"
GH_TOKEN: ${{ github.token }}
LAST_TRIES_LIMIT: "4"
shell: bash
run: |
set -euo pipefail
# First, we retrieve the number of successes of the last (currently) 4 runs. Afterwards we
# add 1 to the number of successes if this run succeeded. This ultimately represents the
# number of successes in the last 5 runs, similar to what Jenkins does. This score is then
# turned into an appropriate "weather" emoji and provided as an output to follow-up steps.
LAST_RUNS=$(gh run list --limit "$LAST_TRIES_LIMIT" --workflow "$WORKFLOW_NAME" --json conclusion)
SUCCESSES=$(echo $LAST_RUNS | jq '[.[] | select(.conclusion == "success")] | length')
export LAST_TRIES_TOTAL=$(echo $LAST_RUNS | jq 'length')
[ "$INTEGRATION_TEST_CONCLUSION" == "success" ] && SUCCESSES=$(echo "$SUCCESSES+1" | bc)
export SUCCESSES="$SUCCESSES"
echo "HEALTH=$(cat "${GITHUB_ACTION_PATH}/health" | envsubst | bc)" | tee -a "$GITHUB_OUTPUT"