Skip to content

Commit 0e8443c

Browse files
authored
[chore] Use a k8s lease to run functional test concurrently (#1704)
The Github actions concurrency feature can only ensure only allows one queued job. Any other jobs are cancelled. It means that the third EKS job is always cancelled, see https://github.com/signalfx/splunk-otel-collector-chart/actions/runs/13731622293/job/38416102735. This change introduces another approach to handle concurrency via k8s leases. It allows queueing many jobs on the same cluster and run them locally.
1 parent 252d987 commit 0e8443c

File tree

12 files changed

+168
-137
lines changed

12 files changed

+168
-137
lines changed

.github/workflows/functional_test_v2.yaml

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ jobs:
101101
if: |
102102
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
103103
(github.ref == 'refs/heads/main')
104-
concurrency:
105-
group: eks-access
106104
env:
107105
KUBECONFIG: /tmp/kube-config-splunk-otel-collector-chart-functional-testing-eks
108106
KUBE_TEST_ENV: eks
@@ -139,8 +137,6 @@ jobs:
139137
if: |
140138
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
141139
(github.ref == 'refs/heads/main')
142-
concurrency:
143-
group: eks-access
144140
env:
145141
KUBECONFIG: /tmp/kube-config-splunk-otel-collector-chart-functional-testing-eks
146142
KUBE_TEST_ENV: eks
@@ -180,28 +176,21 @@ jobs:
180176
aws eks update-kubeconfig --name rotel-eks --region us-west-1
181177
- name: Update dependencies
182178
run: |
183-
cd base && make dep-update
184-
- name: Deploy previous version of the chart
185-
run: |
186-
helm list | grep -q "^sock$" && echo "Found previous 'sock' release. Deleting..." && helm delete sock
187-
cd base && helm install sock helm-charts/splunk-otel-collector --set cloudProvider=aws --set distribution=eks --set splunkObservability.realm=us0 --set splunkObservability.accessToken=xxxxx
188-
- name: Update dependencies
189-
run: |
190-
make dep-update
179+
make dep-update && cd base && make dep-update
191180
- name: run functional tests
192181
env:
193182
HOST_ENDPOINT: 0.0.0.0
183+
UPGRADE_FROM_VALUES: aws_upgrade_from_previous_release_values.yaml
184+
UPGRADE_FROM_CHART_DIR: base
194185
run: |
195-
SUITE=functional make functionaltest
186+
TEARDOWN_BEFORE_SETUP=true SUITE=functional make functionaltest
196187
197188
gke-autopilot-test:
198189
name: Test helm install in GKE/Autopilot - credentials needed
199190
needs: kubernetes-test
200191
if: |
201192
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
202193
(github.ref == 'refs/heads/main')
203-
concurrency:
204-
group: gke-autopilot-access
205194
env:
206195
KUBE_TEST_ENV: gke/autopilot
207196
SKIP_TESTS: "true"
@@ -240,8 +229,6 @@ jobs:
240229
if: |
241230
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
242231
(github.ref == 'refs/heads/main')
243-
concurrency:
244-
group: gke-autopilot-access
245232
env:
246233
KUBE_TEST_ENV: gke/autopilot
247234
SKIP_TESTS: "true"
@@ -283,26 +270,21 @@ jobs:
283270
project_id: ${{ secrets.GKE_PROJECT }}
284271
- name: Update dependencies
285272
run: |
286-
make dep-update
287-
- name: Deploy previous version of the chart
288-
run: |
289-
cd base
290-
helm dependency update helm-charts/splunk-otel-collector
291-
helm install sock helm-charts/splunk-otel-collector --set cloudProvider=gcp --set distribution=gke/autopilot --set splunkObservability.realm=us0 --set splunkObservability.accessToken=xxxxx
273+
make dep-update && cd base && make dep-update
292274
- name: run functional tests
293275
env:
294276
HOST_ENDPOINT: 0.0.0.0
277+
UPGRADE_FROM_VALUES: gke_autopilot_upgrade_from_previous_release_values.yaml
278+
UPGRADE_FROM_CHART_DIR: base
295279
run: |
296-
SUITE=functional make functionaltest
280+
TEARDOWN_BEFORE_SETUP=true SUITE=functional make functionaltest
297281
298282
aks-windows-test:
299283
name: Test helm install in AKS - credentials needed
300284
needs: kubernetes-test
301285
if: |
302286
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
303287
(github.ref == 'refs/heads/main')
304-
concurrency:
305-
group: aks-windows-group
306288
env:
307289
KUBE_TEST_ENV: aks
308290
SKIP_TESTS: "true"
@@ -342,8 +324,6 @@ jobs:
342324
if: |
343325
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
344326
(github.ref == 'refs/heads/main')
345-
concurrency:
346-
group: gce-access
347327
env:
348328
KUBE_TEST_ENV: gce
349329
SKIP_TESTS: "true"

functional_tests/configuration_switching/configuration_switching_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func deployChartsAndApps(t *testing.T, valuesFileName string, repl map[string]in
7070
client, err := kubernetes.NewForConfig(kubeConfig)
7171
require.NoError(t, err)
7272

73-
chart := internal.LoadCollectorChart(t)
73+
chart := internal.LoadCollectorChart(t, "")
7474

7575
var valuesBytes []byte
7676
valuesBytes, err = os.ReadFile(filepath.Join(testDir, valuesDir, valuesFileName))

functional_tests/functional/functional_test.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const (
6161
manifestsDir = "manifests"
6262
eksValuesDir = "expected_eks_values"
6363
kindValuesDir = "expected_kind_values"
64+
helmActionTimeout = 5 * time.Minute
6465
)
6566

6667
var archRe = regexp.MustCompile("-amd64$|-arm64$|-ppc64le$")
@@ -93,22 +94,24 @@ func setupOnce(t *testing.T) *sinks {
9394
signalFxReceiverK8sClusterReceiverPort),
9495
tracesConsumer: internal.SetupOTLPTracesSink(t),
9596
}
97+
98+
testKubeConfig, setKubeConfig := os.LookupEnv("KUBECONFIG")
99+
require.True(t, setKubeConfig, "the environment variable KUBECONFIG must be set")
100+
internal.AcquireLeaseForTest(t, testKubeConfig)
96101
if os.Getenv("TEARDOWN_BEFORE_SETUP") == "true" {
97-
teardown(t)
102+
teardown(t, testKubeConfig)
98103
}
99104
// deploy the chart and applications.
100105
if os.Getenv("SKIP_SETUP") == "true" {
101106
t.Log("Skipping setup as SKIP_SETUP is set to true")
102107
return
103108
}
104-
deployChartsAndApps(t)
109+
deployChartsAndApps(t, testKubeConfig)
105110
})
106111

107112
return globalSinks
108113
}
109-
func deployChartsAndApps(t *testing.T) {
110-
testKubeConfig, setKubeConfig := os.LookupEnv("KUBECONFIG")
111-
require.True(t, setKubeConfig, "the environment variable KUBECONFIG must be set")
114+
func deployChartsAndApps(t *testing.T, testKubeConfig string) {
112115
kubeTestEnv, setKubeTestEnv := os.LookupEnv("KUBE_TEST_ENV")
113116
require.True(t, setKubeTestEnv, "the environment variable KUBE_TEST_ENV must be set")
114117
kubeConfig, err := clientcmd.BuildConfigFromFlags("", testKubeConfig)
@@ -182,7 +185,7 @@ func deployChartsAndApps(t *testing.T) {
182185
}
183186
}, 1*time.Minute, 5*time.Second)
184187

185-
chart := internal.LoadCollectorChart(t)
188+
chart := internal.LoadCollectorChart(t, "")
186189

187190
var valuesBytes []byte
188191
switch kubeTestEnv {
@@ -235,18 +238,35 @@ func deployChartsAndApps(t *testing.T) {
235238
}); err != nil {
236239
require.NoError(t, err)
237240
}
241+
238242
install := action.NewInstall(actionConfig)
239243
install.Namespace = "default"
240244
install.ReleaseName = "sock"
241-
_, err = install.Run(chart, values)
242-
if err != nil {
243-
t.Logf("error reported during helm install: %v\n", err)
244-
retryUpgrade := action.NewUpgrade(actionConfig)
245-
retryUpgrade.Namespace = "default"
246-
retryUpgrade.Install = true
247-
_, err = retryUpgrade.Run("sock", chart, values)
245+
install.Timeout = helmActionTimeout
246+
247+
// If UPGRADE_FROM_VALUES env var is set, we install the helm chart using the values. Otherwise, run helm install.
248+
// UPGRADE_FROM_CHART_DIR is an optional env var that provides an alternative path for the initial helm chart.
249+
upgradeFromValues := os.Getenv("UPGRADE_FROM_VALUES")
250+
if upgradeFromValues != "" {
251+
// install the base chart
252+
initValuesBytes, rfErr := os.ReadFile(filepath.Join(testDir, valuesDir, upgradeFromValues))
253+
require.NoError(t, rfErr)
254+
initChart := internal.LoadCollectorChart(t, os.Getenv("UPGRADE_FROM_CHART_DIR"))
255+
var initValues map[string]interface{}
256+
require.NoError(t, yaml.Unmarshal(initValuesBytes, &initValues))
257+
_, err = install.Run(initChart, initValues)
248258
require.NoError(t, err)
259+
260+
// test the upgrade
261+
upgrade := action.NewUpgrade(actionConfig)
262+
upgrade.Namespace = "default"
263+
upgrade.Install = true
264+
upgrade.Timeout = helmActionTimeout
265+
_, err = upgrade.Run("sock", chart, values)
266+
} else {
267+
_, err = install.Run(chart, values)
249268
}
269+
require.NoError(t, err)
250270

251271
waitForAllDeploymentsToStart(t, client)
252272

@@ -405,14 +425,12 @@ func deployChartsAndApps(t *testing.T) {
405425
return
406426
}
407427
t.Log("Cleaning up cluster")
408-
teardown(t)
428+
teardown(t, testKubeConfig)
409429

410430
})
411431
}
412432

413-
func teardown(t *testing.T) {
414-
testKubeConfig, setKubeConfig := os.LookupEnv("KUBECONFIG")
415-
require.True(t, setKubeConfig, "the environment variable KUBECONFIG must be set")
433+
func teardown(t *testing.T, testKubeConfig string) {
416434
decode := scheme.Codecs.UniversalDeserializer().Decode
417435
kubeConfig, err := clientcmd.BuildConfigFromFlags("", testKubeConfig)
418436
require.NoError(t, err)
@@ -515,6 +533,7 @@ func teardown(t *testing.T) {
515533
uninstall := action.NewUninstall(actionConfig)
516534
uninstall.IgnoreNotFound = true
517535
uninstall.Wait = true
536+
uninstall.Timeout = helmActionTimeout
518537
_, _ = uninstall.Run("sock")
519538
}
520539

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cloudProvider: aws
2+
distribution: eks
3+
environment: dev
4+
splunkObservability:
5+
realm: us0
6+
accessToken: xxxxx
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cloudProvider: gcp
2+
distribution: gke/autopilot
3+
splunkObservability:
4+
realm: us0
5+
accessToken: xxxxx

functional_tests/go.mod

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33

44
module github.com/signalfx/splunk-otel-collector-chart/functional_tests
55

6-
go 1.23.0
6+
go 1.24.0
77

88
require (
99
github.com/docker/docker v27.5.1+incompatible
1010
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.121.0
1111
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.121.0
1212
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest v0.121.0
13-
github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor v0.121.0
1413
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver v0.121.0
1514
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver v0.121.0
1615
github.com/stretchr/testify v1.10.0
1716
go.opentelemetry.io/collector/component/componenttest v0.121.0
1817
go.opentelemetry.io/collector/consumer/consumertest v0.121.0
1918
go.opentelemetry.io/collector/pdata v1.27.0
20-
go.opentelemetry.io/collector/processor/processortest v0.121.0
2119
go.opentelemetry.io/collector/receiver/otlpreceiver v0.121.0
2220
go.opentelemetry.io/collector/receiver/receivertest v0.121.0
2321
gopkg.in/yaml.v3 v3.0.1
@@ -40,9 +38,6 @@ require (
4038
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
4139
github.com/Masterminds/squirrel v1.5.4 // indirect
4240
github.com/Microsoft/go-winio v0.6.2 // indirect
43-
github.com/alecthomas/participle/v2 v2.1.1 // indirect
44-
github.com/antchfx/xmlquery v1.4.3 // indirect
45-
github.com/antchfx/xpath v1.3.3 // indirect
4641
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
4742
github.com/beorn7/perks v1.0.1 // indirect
4843
github.com/blang/semver/v4 v4.0.0 // indirect
@@ -62,8 +57,6 @@ require (
6257
github.com/docker/go-connections v0.5.0 // indirect
6358
github.com/docker/go-metrics v0.0.1 // indirect
6459
github.com/docker/go-units v0.5.0 // indirect
65-
github.com/elastic/go-grok v0.3.1 // indirect
66-
github.com/elastic/lunes v0.1.0 // indirect
6760
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
6861
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
6962
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
@@ -80,9 +73,7 @@ require (
8073
github.com/go-openapi/swag v0.23.0 // indirect
8174
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
8275
github.com/gobwas/glob v0.2.3 // indirect
83-
github.com/goccy/go-json v0.10.5 // indirect
8476
github.com/gogo/protobuf v1.3.2 // indirect
85-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
8677
github.com/golang/protobuf v1.5.4 // indirect
8778
github.com/golang/snappy v0.0.4 // indirect
8879
github.com/google/btree v1.0.1 // indirect
@@ -98,10 +89,8 @@ require (
9889
github.com/hashicorp/errwrap v1.1.0 // indirect
9990
github.com/hashicorp/go-multierror v1.1.1 // indirect
10091
github.com/hashicorp/go-version v1.7.0 // indirect
101-
github.com/hashicorp/golang-lru v0.5.4 // indirect
10292
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
10393
github.com/huandu/xstrings v1.5.0 // indirect
104-
github.com/iancoleman/strcase v0.3.0 // indirect
10594
github.com/inconshreveable/mousetrap v1.1.0 // indirect
10695
github.com/jmoiron/sqlx v1.4.0 // indirect
10796
github.com/josharian/intern v1.0.0 // indirect
@@ -113,7 +102,6 @@ require (
113102
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
114103
github.com/lib/pq v1.10.9 // indirect
115104
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
116-
github.com/magefile/mage v1.15.0 // indirect
117105
github.com/mailru/easyjson v0.7.7 // indirect
118106
github.com/mattn/go-colorable v0.1.13 // indirect
119107
github.com/mattn/go-isatty v0.0.17 // indirect
@@ -133,11 +121,8 @@ require (
133121
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
134122
github.com/open-telemetry/opentelemetry-collector-contrib/extension/ackextension v0.121.0 // indirect
135123
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.121.0 // indirect
136-
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.121.0 // indirect
137-
github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil v0.121.0 // indirect
138124
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.121.0 // indirect
139125
github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk v0.121.0 // indirect
140-
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.121.0 // indirect
141126
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.121.0 // indirect
142127
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/signalfx v0.121.0 // indirect
143128
github.com/opencontainers/go-digest v1.0.0 // indirect
@@ -159,7 +144,6 @@ require (
159144
github.com/spf13/cast v1.7.0 // indirect
160145
github.com/spf13/cobra v1.8.1 // indirect
161146
github.com/spf13/pflag v1.0.5 // indirect
162-
github.com/ua-parser/uap-go v0.0.0-20240611065828-3a4781585db6 // indirect
163147
github.com/x448/float16 v0.8.4 // indirect
164148
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
165149
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
@@ -190,10 +174,7 @@ require (
190174
go.opentelemetry.io/collector/internal/sharedcomponent v0.121.0 // indirect
191175
go.opentelemetry.io/collector/internal/telemetry v0.121.0 // indirect
192176
go.opentelemetry.io/collector/pdata/pprofile v0.121.0 // indirect
193-
go.opentelemetry.io/collector/pdata/testdata v0.121.0 // indirect
194177
go.opentelemetry.io/collector/pipeline v0.121.0 // indirect
195-
go.opentelemetry.io/collector/processor v0.121.0 // indirect
196-
go.opentelemetry.io/collector/processor/xprocessor v0.121.0 // indirect
197178
go.opentelemetry.io/collector/receiver v0.121.0 // indirect
198179
go.opentelemetry.io/collector/receiver/xreceiver v0.121.0 // indirect
199180
go.opentelemetry.io/collector/semconv v0.121.0 // indirect
@@ -207,7 +188,6 @@ require (
207188
go.uber.org/multierr v1.11.0 // indirect
208189
go.uber.org/zap v1.27.0 // indirect
209190
golang.org/x/crypto v0.35.0 // indirect
210-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
211191
golang.org/x/net v0.35.0 // indirect
212192
golang.org/x/oauth2 v0.24.0 // indirect
213193
golang.org/x/sync v0.11.0 // indirect
@@ -220,7 +200,6 @@ require (
220200
google.golang.org/protobuf v1.36.5 // indirect
221201
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
222202
gopkg.in/inf.v0 v0.9.1 // indirect
223-
gopkg.in/yaml.v2 v2.4.0 // indirect
224203
k8s.io/apiserver v0.32.2 // indirect
225204
k8s.io/cli-runtime v0.32.1 // indirect
226205
k8s.io/component-base v0.32.2 // indirect

0 commit comments

Comments
 (0)