Skip to content

Commit

Permalink
add additional templatevalues parameter
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Dec 9, 2024
1 parent 3590805 commit 2273f4d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
10 changes: 7 additions & 3 deletions pkg/k8stest/k8s_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions processor/k8sattributesprocessor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions receiver/k8sclusterreceiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sobjectsreceiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion receiver/kubeletstatsreceiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2273f4d

Please sign in to comment.