Skip to content

Commit a59d509

Browse files
Extract functional test steps into reusable composite action
All kind-based functional test jobs now delegate to .github/actions/functional-test, which owns: Go setup, kind cluster creation, TLS cert fix, dep-update, optional test image build, make functionaltest, and debug artifact upload. Callers pass k8s-version, suite, go-version (or go-version-file), and optional flags for image override, debug info, and golden file updates.
1 parent 638aa1d commit a59d509

4 files changed

Lines changed: 146 additions & 128 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Run Functional Tests
2+
description: >
3+
Sets up a kind cluster, installs dependencies, and runs a functional test
4+
suite. Optionally overrides the collector image and uploads debug artifacts.
5+
6+
inputs:
7+
k8s-version:
8+
description: 'Kubernetes version for the kind cluster (e.g. v1.34.3)'
9+
required: true
10+
suite:
11+
description: 'Test suite to run (passed as SUITE= to make functionaltest)'
12+
required: true
13+
go-version:
14+
description: 'Go version to install'
15+
required: false
16+
default: ''
17+
go-version-file:
18+
description: 'Path to go.mod to determine Go version (used when go-version is not set)'
19+
required: false
20+
default: ''
21+
build-test-images:
22+
description: 'Whether to build and load test images into kind'
23+
required: false
24+
default: 'true'
25+
update-expected-results:
26+
description: 'Whether to update golden file expected test results'
27+
required: false
28+
default: 'false'
29+
kubernetes-debug-info:
30+
description: 'Whether to collect and upload k8s debug info'
31+
required: false
32+
default: 'false'
33+
artifact-suffix:
34+
description: 'Suffix for the k8s debug info artifact name'
35+
required: false
36+
default: ''
37+
otelcol-image-repo:
38+
description: 'Override for the collector image repository'
39+
required: false
40+
default: ''
41+
otelcol-image-tag:
42+
description: 'Override for the collector image tag'
43+
required: false
44+
default: ''
45+
46+
runs:
47+
using: composite
48+
steps:
49+
- name: Set KUBECONFIG for all steps
50+
shell: bash
51+
run: echo "KUBECONFIG=/tmp/kube-config-splunk-otel-collector-chart-functional-testing" >> "$GITHUB_ENV"
52+
53+
- name: Set up Go
54+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
55+
with:
56+
go-version: ${{ inputs.go-version != '' && inputs.go-version || '' }}
57+
go-version-file: ${{ inputs.go-version-file != '' && inputs.go-version-file || '' }}
58+
cache-dependency-path: '**/go.sum'
59+
60+
- name: Create kind cluster
61+
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0
62+
with:
63+
node_image: kindest/node:${{ inputs.k8s-version }}
64+
kubectl_version: ${{ inputs.k8s-version }}
65+
cluster_name: kind
66+
config: ./.github/workflows/configs/kind-config.yaml
67+
68+
- name: Fix kubelet TLS server certificates
69+
shell: bash
70+
run: |
71+
kubectl get csr -o=jsonpath='{range.items[?(@.spec.signerName=="kubernetes.io/kubelet-serving")]}{.metadata.name}{" "}{end}' | xargs kubectl certificate approve
72+
73+
- name: Update dependencies
74+
shell: bash
75+
run: make dep-update
76+
77+
- name: Build and load test images into kind
78+
if: inputs.build-test-images == 'true'
79+
shell: bash
80+
run: make kind-build-test-images
81+
82+
- name: Run functional tests
83+
id: run-functional-tests
84+
shell: bash
85+
env:
86+
KUBE_TEST_ENV: kind
87+
K8S_VERSION: ${{ inputs.k8s-version }}
88+
OTELCOL_IMAGE_REPO: ${{ inputs.otelcol-image-repo }}
89+
OTELCOL_IMAGE_TAG: ${{ inputs.otelcol-image-tag }}
90+
run: |
91+
TEARDOWN_BEFORE_SETUP=true \
92+
UPDATE_EXPECTED_RESULTS=${{ inputs.update-expected-results }} \
93+
SUITE=${{ inputs.suite }} \
94+
make functionaltest
95+
96+
- name: Collect Kubernetes Cluster debug info
97+
if: always() && (steps.run-functional-tests.outcome == 'failure' || inputs.kubernetes-debug-info == 'true')
98+
shell: bash
99+
run: |
100+
cd tools
101+
./splunk_kubernetes_debug_info.sh
102+
103+
- name: Upload Kubernetes Cluster debug info
104+
if: always() && (steps.run-functional-tests.outcome == 'failure' || inputs.kubernetes-debug-info == 'true')
105+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
106+
with:
107+
name: k8s-debug-info${{ inputs.artifact-suffix != '' && format('-{0}', inputs.artifact-suffix) || '' }}
108+
path: tools/splunk_kubernetes_debug_info_*
109+
retention-days: 5
110+
111+
- name: Upload updated expected results
112+
if: always() && inputs.update-expected-results == 'true'
113+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
114+
with:
115+
name: updated_expected_results${{ inputs.artifact-suffix != '' && format('-{0}', inputs.artifact-suffix) || '' }}
116+
path: ./functional_tests/**/*.yaml
117+
retention-days: 5
Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Dev Image Tests
22

33
on:
4-
schedule:
5-
- cron: "0 6 * * *"
4+
pull_request:
5+
types: [labeled]
66
workflow_dispatch:
77
inputs:
88
collector_image:
@@ -27,6 +27,9 @@ env:
2727

2828
jobs:
2929
get-test-matrix:
30+
if: >
31+
github.event_name == 'workflow_dispatch' ||
32+
(github.event_name == 'pull_request' && github.event.label.name == 'run-dev-image-test')
3033
runs-on: ubuntu-latest
3134
steps:
3235
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
@@ -42,62 +45,25 @@ jobs:
4245
name: K8s ${{ matrix.k8s-kind-version }} / ${{ matrix.test-job }}
4346
runs-on: ubuntu-latest
4447
needs: get-test-matrix
45-
env:
46-
KUBECONFIG: /tmp/kube-config-splunk-otel-collector-chart-functional-testing
47-
KUBE_TEST_ENV: kind
48-
KUBERNETES_DEBUG_INFO: ${{ github.event.inputs.KUBERNETES_DEBUG_INFO || 'false' }}
4948
strategy:
5049
fail-fast: false
5150
matrix: ${{ fromJSON(needs.get-test-matrix.outputs.matrix) }}
5251
steps:
5352
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
54-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
55-
with:
56-
go-version: ${{ env.GO_VERSION }}
57-
cache-dependency-path: '**/go.sum'
5853

59-
- name: Set collector image overrides
54+
- name: Parse collector image input
55+
id: parse-image
6056
run: |
6157
IMAGE="${{ github.event.inputs.collector_image || 'quay.io/signalfx/splunk-otel-collector-dev:latest' }}"
62-
echo "OTELCOL_IMAGE_REPO=${IMAGE%:*}" >> "$GITHUB_ENV"
63-
echo "OTELCOL_IMAGE_TAG=${IMAGE##*:}" >> "$GITHUB_ENV"
58+
echo "repo=${IMAGE%:*}" >> "$GITHUB_OUTPUT"
59+
echo "tag=${IMAGE##*:}" >> "$GITHUB_OUTPUT"
6460
65-
- name: Create kind cluster
66-
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0
61+
- uses: ./.github/actions/functional-test
6762
with:
68-
node_image: kindest/node:${{ matrix.k8s-kind-version }}
69-
kubectl_version: ${{ matrix.k8s-kind-version }}
70-
cluster_name: kind
71-
config: ./.github/workflows/configs/kind-config.yaml
72-
73-
- name: Fix kubelet TLS server certificates
74-
run: |
75-
kubectl get csr -o=jsonpath='{range.items[?(@.spec.signerName=="kubernetes.io/kubelet-serving")]}{.metadata.name}{" "}{end}' | xargs kubectl certificate approve
76-
77-
- name: Update dependencies
78-
run: make dep-update
79-
80-
- name: Build and load test images into kind
81-
run: make kind-build-test-images
82-
83-
- name: Run functional tests
84-
id: run-functional-tests
85-
env:
86-
K8S_VERSION: ${{ matrix.k8s-kind-version }}
87-
run: |
88-
TEARDOWN_BEFORE_SETUP=true SUITE=${{ matrix.test-job }} make functionaltest
89-
90-
- name: Collect Kubernetes Cluster debug info on failure
91-
if: always() && (steps.run-functional-tests.outcome == 'failure' || env.KUBERNETES_DEBUG_INFO == 'true')
92-
id: collect-debug-info
93-
run: |
94-
cd tools
95-
./splunk_kubernetes_debug_info.sh
96-
97-
- name: Upload Kubernetes Cluster debug info
98-
if: always() && (steps.run-functional-tests.outcome == 'failure' || env.KUBERNETES_DEBUG_INFO == 'true')
99-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
100-
with:
101-
name: k8s-debug-info-${{ matrix.test-job }}-${{ matrix.k8s-kind-version }}
102-
path: tools/splunk_kubernetes_debug_info_*
103-
retention-days: 5
63+
k8s-version: ${{ matrix.k8s-kind-version }}
64+
suite: ${{ matrix.test-job }}
65+
go-version: ${{ env.GO_VERSION }}
66+
kubernetes-debug-info: ${{ github.event.inputs.KUBERNETES_DEBUG_INFO || 'false' }}
67+
artifact-suffix: ${{ matrix.test-job }}-${{ matrix.k8s-kind-version }}
68+
otelcol-image-repo: ${{ steps.parse-image.outputs.repo }}
69+
otelcol-image-tag: ${{ steps.parse-image.outputs.tag }}

.github/workflows/functional_test_v2.yaml

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ jobs:
4949

5050
kubernetes-test:
5151
env:
52-
KUBECONFIG: /tmp/kube-config-splunk-otel-collector-chart-functional-testing
53-
KUBE_TEST_ENV: kind
52+
KUBE_TEST_ENV: kind
5453
UPDATE_EXPECTED_RESULTS: ${{ github.event.inputs.UPDATE_EXPECTED_RESULTS || 'false' }}
5554
KUBERNETES_DEBUG_INFO: ${{ github.event.inputs.KUBERNETES_DEBUG_INFO || 'false' }}
5655
needs: get-test-matrix
@@ -61,53 +60,14 @@ jobs:
6160
continue-on-error: ${{ contains(github.event.pull_request.labels.*.name, 'Ignore Tests') }}
6261
steps:
6362
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
64-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
63+
- uses: ./.github/actions/functional-test
6564
with:
65+
k8s-version: ${{ matrix.k8s-kind-version }}
66+
suite: ${{ matrix.test-job }}
6667
go-version: ${{ env.GO_VERSION }}
67-
cache-dependency-path: '**/go.sum'
68-
- name: Create kind cluster
69-
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0
70-
with:
71-
node_image: kindest/node:${{ matrix.k8s-kind-version }}
72-
kubectl_version: ${{ matrix.k8s-kind-version }}
73-
cluster_name: kind
74-
config: ./.github/workflows/configs/kind-config.yaml
75-
- name: Fix kubelet TLS server certificates
76-
run: |
77-
kubectl get csr -o=jsonpath='{range.items[?(@.spec.signerName=="kubernetes.io/kubelet-serving")]}{.metadata.name}{" "}{end}' | xargs kubectl certificate approve
78-
- name: Update dependencies
79-
run: |
80-
make dep-update
81-
- name: Build and load test images into kind
82-
run: |
83-
make kind-build-test-images
84-
- name: run functional tests
85-
id: run-functional-tests
86-
env:
87-
K8S_VERSION: ${{ matrix.k8s-kind-version }}
88-
run: |
89-
TEARDOWN_BEFORE_SETUP=true UPDATE_EXPECTED_RESULTS=${{ env.UPDATE_EXPECTED_RESULTS }} SUITE=${{ matrix.test-job }} make functionaltest
90-
- name: Collect Kubernetes Cluster debug info on failure
91-
if: always() && (steps.run-functional-tests.outcome == 'failure' || env.KUBERNETES_DEBUG_INFO == 'true')
92-
id: collect-debug-info
93-
run: |
94-
echo "Functional tests failed. Collecting debug info for current state of the Kubernetes cluster..."
95-
cd tools
96-
./splunk_kubernetes_debug_info.sh
97-
- name: Upload Kubernetes Cluster debug info
98-
if: always() && (steps.run-functional-tests.outcome == 'failure' || env.KUBERNETES_DEBUG_INFO == 'true')
99-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
100-
with:
101-
name: k8s-debug-info-${{ matrix.test-job }}-${{ matrix.k8s-kind-version }}
102-
path: tools/splunk_kubernetes_debug_info_*
103-
retention-days: 5
104-
- name: Upload updated files artifact
105-
if: always() && env.UPDATE_EXPECTED_RESULTS == 'true'
106-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
107-
with:
108-
name: updated_expected_results-${{ matrix.test-job }}-${{ matrix.k8s-kind-version }}
109-
path: ./functional_tests/**/*.yaml
110-
retention-days: 5
68+
update-expected-results: ${{ env.UPDATE_EXPECTED_RESULTS }}
69+
kubernetes-debug-info: ${{ env.KUBERNETES_DEBUG_INFO }}
70+
artifact-suffix: ${{ matrix.test-job }}-${{ matrix.k8s-kind-version }}
11171

11272
eks-test:
11373
name: Test helm install in EKS - credentials needed

.github/workflows/instrumentation_cr_test.yaml

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,10 @@ jobs:
1515
continue-on-error: ${{ contains(github.event.pull_request.labels.*.name, 'Ignore Tests') }}
1616
steps:
1717
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
18-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
18+
- uses: ./.github/actions/functional-test
1919
with:
20+
k8s-version: v1.34.3
21+
suite: instrumentation_cr
2022
go-version-file: functional_tests/go.mod
21-
cache-dependency-path: functional_tests/go.sum
22-
- name: Create kind cluster
23-
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0
24-
with:
25-
node_image: kindest/node:v1.34.3
26-
kubectl_version: v1.34.3
27-
cluster_name: kind
28-
config: ./.github/workflows/configs/kind-config.yaml
29-
- name: Fix kubelet TLS server certificates
30-
run: |
31-
kubectl get csr -o=jsonpath='{range.items[?(@.spec.signerName=="kubernetes.io/kubelet-serving")]}{.metadata.name}{" "}{end}' | xargs kubectl certificate approve
32-
- name: Update Helm dependencies
33-
run: make dep-update
34-
- name: Run instrumentation CR e2e tests
35-
id: run-e2e
36-
run: make functionaltest SUITE=instrumentation_cr
37-
- name: Collect Kubernetes Cluster debug info on failure
38-
if: always() && steps.run-e2e.outcome == 'failure'
39-
run: |
40-
echo "Instrumentation CR tests failed. Collecting debug info..."
41-
cd tools
42-
./splunk_kubernetes_debug_info.sh
43-
- name: Upload Kubernetes Cluster debug info
44-
if: always() && steps.run-e2e.outcome == 'failure'
45-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
46-
with:
47-
name: k8s-debug-info-instrumentation-cr
48-
path: tools/splunk_kubernetes_debug_info_*
49-
retention-days: 5
23+
build-test-images: 'false'
24+
artifact-suffix: instrumentation-cr

0 commit comments

Comments
 (0)