Skip to content

Commit

Permalink
set AGENT_OPERATOR env var
Browse files Browse the repository at this point in the history
  • Loading branch information
captncraig committed Nov 14, 2023
1 parent 43494f2 commit 635c496
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/operator/resources_pod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/operator/resources_pod_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit 635c496

Please sign in to comment.