openfaas / faas-netes

Serverless Functions For Kubernetes
https://www.openfaas.com
MIT License
2.13k stars 472 forks source link

Feature request: Expose Node IP within function container #677

Closed andyy5 closed 4 years ago

andyy5 commented 4 years ago

Expected Behaviour

I'm trying to send datadog traces from my function to my datadog agent.

For the function, I need to set the environment variable DD_AGENT_HOST to the node's IP, like this:

env:
- name: DD_AGENT_HOST
   valueFrom:
      fieldRef:
        fieldPath: status.hostIP

But based on the docs and code, it seems like this is not supported?

I'm wondering if there is any workaround that can help me here.

Current Behaviour

Not implemented

Possible Solution

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

I'm trying to send datadog traces from my function to my datadog agent and need to set the function's environment variable DD_AGENT_HOST to the node's IP.

Your Environment

alexellis commented 4 years ago

/set title: Feature request: Expose Node IP within function container

alexellis commented 4 years ago

Thanks for your suggestion. This does seem like an edge-case, but would you like to spend some time looking into possible solutions and report back?

andyy5 commented 4 years ago

@alexellis some options:

YAML

pod_info:
  my_env1: status.podIP
  my_env2: status.hostIP
  my_env3: spec.serviceAccountName
  my_env4: spec.nodeName

REST API

"podInfo": {
  "my_env1": "status.hostIP"
  ...
}

YAML

environment:
  my_env: status.hostIP

REST API

"envVars": {
  "my_env": "status.hostIP"
}
LucasRoesler commented 4 years ago

The setup sounds like the Data dog agent is running as a daemon set and you want to specify that it talk to the replica on the same host.

The simplest fastest fix is to define a Service for your daemon set and then reference it by name instead of the node ip. I have done this with Jaeger tracing and haven't had any issues with it so far.

The idea of adding special env values is interesting, it seems like something we could even partially standardize between k8s, faas-swarm, and faasd

alexellis commented 4 years ago

I would agree with @LucasRoesler here, adding a service would make more sense, or some kind of proxy that you can deploy and use instead.

andyy5 commented 4 years ago

Thanks for the help