Skip to content

Commit 638aa1d

Browse files
Add collector image and extra values overrides to test framework
ChartInstallOrUpgrade now reads OTELCOL_IMAGE_REPO, OTELCOL_IMAGE_TAG, and HELM_EXTRA_SET env vars and merges them into the helm values before install/upgrade, so any test suite can be run against an arbitrary collector image without modifying values files. The dev-image-test workflow uses these vars to inject the dev image instead of patching values.yaml with yq.
1 parent 73863b6 commit 638aa1d

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

.github/workflows/dev-image-test.yaml

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,8 @@ permissions:
2424
env:
2525
GO_VERSION: 1.26.2
2626
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2
27-
COLLECTOR_IMAGE: ${{ github.event.inputs.collector_image || 'quay.io/signalfx/splunk-otel-collector-dev:latest' }}
2827

2928
jobs:
30-
# ── Step 1: patch values.yaml with the dev image ───────────────────────────
31-
set-image:
32-
runs-on: ubuntu-latest
33-
outputs:
34-
image_repository: ${{ steps.parse.outputs.image_repository }}
35-
image_tag: ${{ steps.parse.outputs.image_tag }}
36-
steps:
37-
- name: Parse image into repository and tag
38-
id: parse
39-
run: |
40-
IMAGE="${COLLECTOR_IMAGE}"
41-
# Split on the last colon to separate repo from tag
42-
IMAGE_REPOSITORY="${IMAGE%:*}"
43-
IMAGE_TAG="${IMAGE##*:}"
44-
# If no colon was found (no tag), treat the whole string as repo with latest tag
45-
if [[ "$IMAGE_REPOSITORY" == "$IMAGE_TAG" ]]; then
46-
IMAGE_TAG="latest"
47-
fi
48-
echo "image_repository=${IMAGE_REPOSITORY}" >> "$GITHUB_OUTPUT"
49-
echo "image_tag=${IMAGE_TAG}" >> "$GITHUB_OUTPUT"
50-
echo "Using repository=${IMAGE_REPOSITORY} tag=${IMAGE_TAG}"
51-
52-
# ── Step 2: functional tests (kind) ────────────────────────────────────────
5329
get-test-matrix:
5430
runs-on: ubuntu-latest
5531
steps:
@@ -65,7 +41,7 @@ jobs:
6541
functional-test:
6642
name: K8s ${{ matrix.k8s-kind-version }} / ${{ matrix.test-job }}
6743
runs-on: ubuntu-latest
68-
needs: [set-image, get-test-matrix]
44+
needs: get-test-matrix
6945
env:
7046
KUBECONFIG: /tmp/kube-config-splunk-otel-collector-chart-functional-testing
7147
KUBE_TEST_ENV: kind
@@ -80,10 +56,11 @@ jobs:
8056
go-version: ${{ env.GO_VERSION }}
8157
cache-dependency-path: '**/go.sum'
8258

83-
- name: Update chart image to dev image
59+
- name: Set collector image overrides
8460
run: |
85-
yq e '.image.otelcol.repository = "${{ needs.set-image.outputs.image_repository }}"' -i helm-charts/splunk-otel-collector/values.yaml
86-
yq e '.image.otelcol.tag = "${{ needs.set-image.outputs.image_tag }}"' -i helm-charts/splunk-otel-collector/values.yaml
61+
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"
8764
8865
- name: Create kind cluster
8966
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0

functional_tests/internal/chart.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"os/exec"
1212
"path/filepath"
13+
"strings"
1314
"testing"
1415
"text/template"
1516
"time"
@@ -21,6 +22,7 @@ import (
2122
"helm.sh/helm/v4/pkg/chart/loader"
2223
"helm.sh/helm/v4/pkg/kube"
2324
releasev1 "helm.sh/helm/v4/pkg/release/v1"
25+
"helm.sh/helm/v4/pkg/strvals"
2426
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
2527
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2628
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -69,6 +71,7 @@ func ChartInstallOrUpgrade(t *testing.T, testKubeConfig string, valuesFile strin
6971
var values map[string]any
7072
err = yaml.Unmarshal(buf.Bytes(), &values)
7173
require.NoError(t, err)
74+
applyEnvOverrides(t, values)
7275

7376
actionConfig := InitHelmActionConfig(t, testKubeConfig)
7477
install := action.NewInstall(actionConfig)
@@ -128,6 +131,34 @@ func ChartInstallOrUpgrade(t *testing.T, testKubeConfig string, valuesFile strin
128131
CheckPodsReady(t, clientset, options.ChartNamespace, labelSelector, options.ChartTimeout, minReadyTime)
129132
}
130133

134+
// applyEnvOverrides merges environment-driven value overrides into the helm values map.
135+
//
136+
// Supported env vars:
137+
//
138+
// OTELCOL_IMAGE_REPO - overrides image.otelcol.repository
139+
// OTELCOL_IMAGE_TAG - overrides image.otelcol.tag
140+
// HELM_EXTRA_SET - comma-separated key=value pairs, applied last (same syntax as helm --set)
141+
func applyEnvOverrides(t *testing.T, values map[string]any) {
142+
if repo := os.Getenv("OTELCOL_IMAGE_REPO"); repo != "" {
143+
t.Logf("OTELCOL_IMAGE_REPO override: image.otelcol.repository=%s", repo)
144+
require.NoError(t, strvals.ParseInto("image.otelcol.repository="+repo, values))
145+
}
146+
if tag := os.Getenv("OTELCOL_IMAGE_TAG"); tag != "" {
147+
t.Logf("OTELCOL_IMAGE_TAG override: image.otelcol.tag=%s", tag)
148+
require.NoError(t, strvals.ParseInto("image.otelcol.tag="+tag, values))
149+
}
150+
if extra := os.Getenv("HELM_EXTRA_SET"); extra != "" {
151+
for pair := range strings.SplitSeq(extra, ",") {
152+
pair = strings.TrimSpace(pair)
153+
if pair == "" {
154+
continue
155+
}
156+
t.Logf("HELM_EXTRA_SET override: %s", pair)
157+
require.NoError(t, strvals.ParseInto(pair, values))
158+
}
159+
}
160+
}
161+
131162
func getKubeClient(kubeConfig string) (*kubernetes.Clientset, error) {
132163
config, err := clientcmd.BuildConfigFromFlags("", kubeConfig)
133164
if err != nil {

0 commit comments

Comments
 (0)