From 8df0b90f60912c11a7648f9d21e3b2852014783d Mon Sep 17 00:00:00 2001 From: odubajDT Date: Mon, 9 Dec 2024 14:12:04 +0100 Subject: [PATCH] add additional templatevalues parameter Signed-off-by: odubajDT --- pkg/k8stest/k8s_collector.go | 10 +++++++--- processor/k8sattributesprocessor/e2e_test.go | 8 ++++---- receiver/k8sclusterreceiver/e2e_test.go | 4 ++-- receiver/k8sobjectsreceiver/e2e_test.go | 2 +- receiver/kubeletstatsreceiver/e2e_test.go | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pkg/k8stest/k8s_collector.go b/pkg/k8stest/k8s_collector.go index b5c34a76de90..f55ac6bcfc24 100644 --- a/pkg/k8stest/k8s_collector.go +++ b/pkg/k8stest/k8s_collector.go @@ -20,7 +20,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) -func CreateCollectorObjects(t *testing.T, client *K8sClient, testID string, manifestsDir string) []*unstructured.Unstructured { +func CreateCollectorObjects(t *testing.T, client *K8sClient, testID string, manifestsDir string, templateValues map[string]string) []*unstructured.Unstructured { if manifestsDir == "" { manifestsDir = filepath.Join(".", "testdata", "e2e", "collector") } @@ -36,11 +36,15 @@ func CreateCollectorObjects(t *testing.T, client *K8sClient, testID string, mani for _, manifestFile := range manifestFiles { tmpl := template.Must(template.New(manifestFile.Name()).ParseFiles(filepath.Join(manifestsDir, manifestFile.Name()))) manifest := &bytes.Buffer{} - require.NoError(t, tmpl.Execute(manifest, map[string]string{ + defaultTemplateValues := map[string]string{ "Name": "otelcol-" + testID, "HostEndpoint": host, "TestID": testID, - })) + } + for key, value := range templateValues { + defaultTemplateValues[key] = value + } + require.NoError(t, tmpl.Execute(manifest, defaultTemplateValues)) obj, err := CreateObject(client, manifest.Bytes()) require.NoErrorf(t, err, "failed to create collector object from manifest %s", manifestFile.Name()) objKind := obj.GetKind() diff --git a/processor/k8sattributesprocessor/e2e_test.go b/processor/k8sattributesprocessor/e2e_test.go index 1a991ed7af24..c7a5469faf45 100644 --- a/processor/k8sattributesprocessor/e2e_test.go +++ b/processor/k8sattributesprocessor/e2e_test.go @@ -86,7 +86,7 @@ func TestE2E_ClusterRBAC(t *testing.T) { defer shutdownSinks() testID := uuid.NewString()[:8] - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector")) + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector"), map[string]string{}) createTeleOpts := &k8stest.TelemetrygenCreateOpts{ ManifestsDir: filepath.Join(testDir, "telemetrygen"), TestID: testID, @@ -566,7 +566,7 @@ func TestE2E_NamespacedRBAC(t *testing.T) { defer shutdownSinks() testID := uuid.NewString()[:8] - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector")) + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector"), map[string]string{}) createTeleOpts := &k8stest.TelemetrygenCreateOpts{ ManifestsDir: filepath.Join(testDir, "telemetrygen"), TestID: testID, @@ -746,7 +746,7 @@ func TestE2E_MixRBAC(t *testing.T) { }() } - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector")) + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector"), map[string]string{}) defer func() { for _, obj := range collectorObjs { require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName()) @@ -941,7 +941,7 @@ func TestE2E_NamespacedRBACNoPodIP(t *testing.T) { defer shutdownSinks() testID := uuid.NewString()[:8] - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector")) + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(testDir, "collector"), map[string]string{}) createTeleOpts := &k8stest.TelemetrygenCreateOpts{ ManifestsDir: filepath.Join(testDir, "telemetrygen"), TestID: testID, diff --git a/receiver/k8sclusterreceiver/e2e_test.go b/receiver/k8sclusterreceiver/e2e_test.go index 32a0dec7d784..3498db30c5c3 100644 --- a/receiver/k8sclusterreceiver/e2e_test.go +++ b/receiver/k8sclusterreceiver/e2e_test.go @@ -63,7 +63,7 @@ func TestE2EClusterScoped(t *testing.T) { defer shutdownSink() testID := uuid.NewString()[:8] - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "cluster-scoped", "collector")) + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "cluster-scoped", "collector"), map[string]string{}) t.Cleanup(func() { for _, obj := range append(collectorObjs) { @@ -147,7 +147,7 @@ func TestE2ENamespaceScoped(t *testing.T) { defer shutdownSink() testID := uuid.NewString()[:8] - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "namespace-scoped", "collector")) + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "namespace-scoped", "collector"), map[string]string{}) t.Cleanup(func() { for _, obj := range append(collectorObjs) { diff --git a/receiver/k8sobjectsreceiver/e2e_test.go b/receiver/k8sobjectsreceiver/e2e_test.go index 1f302a6b902a..e91e1df2e74b 100644 --- a/receiver/k8sobjectsreceiver/e2e_test.go +++ b/receiver/k8sobjectsreceiver/e2e_test.go @@ -60,7 +60,7 @@ func TestE2E(t *testing.T) { }() // startup collector in k8s cluster - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, "") + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, "", map[string]string{}) defer func() { for _, obj := range collectorObjs { diff --git a/receiver/kubeletstatsreceiver/e2e_test.go b/receiver/kubeletstatsreceiver/e2e_test.go index 5d8bd10ead6c..1d4ab1b51fab 100644 --- a/receiver/kubeletstatsreceiver/e2e_test.go +++ b/receiver/kubeletstatsreceiver/e2e_test.go @@ -41,7 +41,7 @@ func TestE2E(t *testing.T) { defer shutdownSink() testID := uuid.NewString()[:8] - collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, "") + collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, "", map[string]string{}) defer func() { for _, obj := range append(collectorObjs) {