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) + }) }