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

How to get DD_AGENT_HOST for functions for the Datadog agent? #913

Closed
1 of 2 tasks
kevin-lindsay-1 opened this issue Feb 10, 2022 · 7 comments
Closed
1 of 2 tasks

Comments

@kevin-lindsay-1
Copy link
Contributor

kevin-lindsay-1 commented Feb 10, 2022

The function CRD has a flatmap of strings for environment variables, but for certain things like needing the host IP, you need to use valueFrom, not just value.

Expected Behaviour

You should be able to set environment variables that can use valueFrom, like any other pod.

Current Behaviour

You can't use it.

Are you a GitHub Sponsor (Yes/No?)

Check at: https://github.com/sponsors/openfaas

  • Yes
  • No

List All Possible Solutions and Workarounds

Either change the existing API to support valueFrom, or make a new environmentFrom which looks something like:

# usage
environmentFrom:
  DD_AGENT_HOST:
    fieldRef:
      fieldPath: status.hostIP
# deployment template
...
env:
{{- range $key, $value := .environment }}
- name: {{ $key }}
  value: {{ $value }}
{{- end }}
{{- range $key, $valueFrom := .environmentFrom }}
- name: {{ $key }}
  valueFrom: {{ toYaml $valueFrom | nindent 4 }}
{{- end }}

Alternatively, you could just bake this environment variable in by default (with a different name, obviously). Seems brittle though.

Which Solution Do You Recommend?

I don't use the environment variable references like this very often, and I mostly just care that it works.

Steps to Reproduce (for bugs)

Context

Trying to tell my datadog tracer & profiler on my function pod where the datadog agent lives, and can't easily because OF does not support the use case with their CRD.

Your Environment

  • FaaS-CLI version ( Full output from: faas-cli version ):

  • Docker version docker version (e.g. Docker 17.0.05 ):

  • What version and distriubtion of Kubernetes are you using? kubectl version

  • Operating System and version (e.g. Linux, Windows, MacOS):

  • Link to your project or a code example to reproduce issue:

  • What network driver are you using and what CIDR? i.e. Weave net / Flannel

@LucasRoesler
Copy link
Member

It seems like there is some overlap with #848 and we would likely solve this issue by providing a general resolution in #848

@kevin-lindsay-1
Copy link
Contributor Author

kevin-lindsay-1 commented Feb 17, 2022

Yes, I think these are basically the same issue, however it looked like it was discussing different ways to solve this issue than what k8s would say to do in the first place.

To me, this is a simple API issue; it's opt-in on my end, OpenFaaS just doesn't support the feature.

I use the environmentFrom pattern at work because it's infrequent and lets "normal" environment variables have a less verbose syntax.

I don't see any real reason why something that's completely opt-in would be omitted, outside of "nobody has asked for it yet". valueFrom is pretty much the de-facto answer here. In the ecosystem it's effectively a completely solved problem, to the point where no one is even discussing alternatives outside of convenience features, such as namespace-level auto-injected environment variables, which is still in discussion and is more a workaround for this particular issue of lack of standard k8s API support.

If you look up this issue in k8s docs, there is basically 1 question and exactly 1 answer, and valueFrom is it. That's what it's for. No idea why we'd discuss reinventing the wheel here.

@alexellis
Copy link
Member

We talked about this on the office hours call today.

Under "Enabling DogStatsD and APM" on this blog post https://blog.porter.run/datadog-and-kubernetes/ - there seems to be a an admissions controller that can automate this. It would be worth trying that out and seeing if the openfaas operator would fight with it?

Another option may be for openfaas pro users to have an additional option to only populate host_ip into one or more environment variables DD_AGENT_HOST plus OF_HOST_IP

@kevin-lindsay-1
Copy link
Contributor Author

I enabled the admission controller in the DataDog helm chart, and this environment variable is now being injected into function pods.

Function pods definitions do not appear to be being fought over with these injections.

@alexellis
Copy link
Member

I'm going to close this issue because it was more about a specific way to get DD_AGENT_HOST working with Datadog, than a generic need for secrets in environment variables.

@alexellis
Copy link
Member

/lock: resolved

@derek derek bot locked and limited conversation to collaborators Jun 9, 2022
@alexellis
Copy link
Member

/set title: How to get DD_AGENT_HOST for functions for the Datadog agent?

@derek derek bot changed the title Function CRD environment variables do not support valueFrom How to get DD_AGENT_HOST for functions for the Datadog agent? Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants