Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load environment variables in override with envFrom #1429

Merged
merged 10 commits into from
Oct 2, 2024

Conversation

swang392
Copy link
Contributor

@swang392 swang392 commented Sep 23, 2024

What does this PR do?

Add ability for environment variables to be loaded in the override map of datadog-agent.yaml using envFrom.
Example:
Screenshot 2024-09-23 at 4 52 29 PM

Motivation

#896

Additional Notes

Anything else we should know when reviewing?

Minimum Agent Versions

Are there minimum versions of the Datadog Agent and/or Cluster Agent required?

  • Agent: vX.Y.Z
  • Cluster Agent: vX.Y.Z

Describe your test plan

  • make a kind cluster with Operator
  • Make and load some test configMaps and secrets into kind cluster. To double check the priority between env and envFrom (env should take priority), add a field DD_CLUSTER_NAME: <not your cluster name>
  • Add fields into datadog-agent.yaml: spec.override.nodeAgent.EnvFrom, spec.override.clusterAgent.envFrom, and/or spec.override.clusterChecksRunner.envFrom with configMaps or secrets
  • add Agent to kind cluster
  • run kubectl describe pod for agent, cluster checks runner, and cluster agent and verify that the configs or secrets that you specified are there. They should be in a separate section right above the environment variables.
  • run kubectl exec -it <datadog agent pod> bash and then env. You should be able to see the specific variables you added with their values.
  • For agent that you modified DD_CLUSTER_NAME for, when you run the exec command, the DD_CLUSTER_NAME field should not be overridden to what was put in the configMap/secret.

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request does not contain a valid label. Please add one of the following labels: bug, enhancement, refactoring, documentation, tooling, dependencies

@swang392 swang392 changed the title load variables in override w/ envFrom Load environment variables in override with envFrom Sep 23, 2024
@swang392 swang392 changed the title Load environment variables in override with envFrom Load environment variables in override with envFrom Sep 23, 2024
@swang392 swang392 added this to the v1.10.0 milestone Sep 23, 2024
@swang392 swang392 added the enhancement New feature or request label Sep 23, 2024
@codecov-commenter
Copy link

codecov-commenter commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 11.70213% with 83 lines in your changes missing coverage. Please review.

Project coverage is 48.75%. Comparing base (fdaeb06) to head (eecc545).

Files with missing lines Patch % Lines
...ler/datadogagent/merger/fake/envfromvar_manager.go 10.86% 41 Missing ⚠️
...ernal/controller/datadogagent/merger/envvarfrom.go 13.15% 32 Missing and 1 partial ⚠️
...ontroller/datadogagent/override/podtemplatespec.go 0.00% 3 Missing and 1 partial ⚠️
internal/controller/datadogagent/feature/types.go 0.00% 3 Missing ⚠️
...r/datadogagent/feature/fake/PodTemplateManagers.go 33.33% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1429      +/-   ##
==========================================
- Coverage   48.95%   48.75%   -0.20%     
==========================================
  Files         221      222       +1     
  Lines       19252    19342      +90     
==========================================
+ Hits         9424     9431       +7     
- Misses       9345     9425      +80     
- Partials      483      486       +3     
Flag Coverage Δ
unittests 48.75% <11.70%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
api/datadoghq/v2alpha1/datadogagent_types.go 100.00% <ø> (ø)
...r/datadogagent/feature/fake/PodTemplateManagers.go 92.59% <33.33%> (-7.41%) ⬇️
internal/controller/datadogagent/feature/types.go 26.16% <0.00%> (-0.76%) ⬇️
...ontroller/datadogagent/override/podtemplatespec.go 71.76% <0.00%> (-0.97%) ⬇️
...ernal/controller/datadogagent/merger/envvarfrom.go 42.85% <13.15%> (-57.15%) ⬇️
...ler/datadogagent/merger/fake/envfromvar_manager.go 10.86% <10.86%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fdaeb06...eecc545. Read the comment docs.

@swang392 swang392 marked this pull request as ready for review September 24, 2024 18:08
@swang392 swang392 requested review from a team as code owners September 24, 2024 18:08
Copy link
Contributor

@fanny-jiang fanny-jiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@swang392 swang392 merged commit 5e5ce7e into main Oct 2, 2024
19 checks passed
@swang392 swang392 deleted the swang392/envfrom-config branch October 2, 2024 14:36
mftoure pushed a commit that referenced this pull request Oct 3, 2024
* load variables in override w/ envFrom

* fix broken reference to commonv1

* fix bug with mocking containers

* add test cases for envfrom override

* change assert to ElementsMatch

* remove unused container objects

* remove comment

---------

Co-authored-by: Fanny Jiang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants