From 635c4960358af3b20358aa727694b23d245c1c81 Mon Sep 17 00:00:00 2001 From: Craig Peterson <192540+captncraig@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:47:12 -0500 Subject: [PATCH] set AGENT_OPERATOR env var --- pkg/operator/resources_pod_template.go | 17 ++++++++++++----- pkg/operator/resources_pod_template_test.go | 13 +++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pkg/operator/resources_pod_template.go b/pkg/operator/resources_pod_template.go index c826ea6ea980..b0a818b2b01d 100644 --- a/pkg/operator/resources_pod_template.go +++ b/pkg/operator/resources_pod_template.go @@ -190,12 +190,19 @@ func generatePodTemplate( finalLabels = cfg.Labels.Merge(podLabels) ) - envVars := []core_v1.EnvVar{{ - Name: "POD_NAME", - ValueFrom: &core_v1.EnvVarSource{ - FieldRef: &core_v1.ObjectFieldSelector{FieldPath: "metadata.name"}, + envVars := []core_v1.EnvVar{ + { + Name: "POD_NAME", + ValueFrom: &core_v1.EnvVarSource{ + FieldRef: &core_v1.ObjectFieldSelector{FieldPath: "metadata.name"}, + }, }, - }} + // Allows the agent to identify this is an operator-created pod. + { + Name: "AGENT_OPERATOR", + Value: "1", + }, + } envVars = append(envVars, opts.ExtraEnvVars...) useConfigReloaderVersion := d.Agent.Spec.ConfigReloaderVersion diff --git a/pkg/operator/resources_pod_template_test.go b/pkg/operator/resources_pod_template_test.go index eb855820cc9d..4e5702a50893 100644 --- a/pkg/operator/resources_pod_template_test.go +++ b/pkg/operator/resources_pod_template_test.go @@ -155,4 +155,17 @@ func Test_generatePodTemplate(t *testing.T) { require.NoError(t, err) assert.Nil(t, tmpl.Spec.RuntimeClassName) }) + + t.Run("AGENT_OPERATOR env ser", func(t *testing.T) { + deploy := gragent.Deployment{ + Agent: &gragent.GrafanaAgent{ + ObjectMeta: v1.ObjectMeta{Name: name, Namespace: name}, + }, + } + + tmpl, _, err := generatePodTemplate(cfg, "agent", deploy, podTemplateOptions{}) + require.NoError(t, err) + require.Equal(t, "1", tmpl.Spec.Containers[1].Env[1].Value) + require.Equal(t, "AGENT_OPERATOR", tmpl.Spec.Containers[1].Env[1].Name) + }) }