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

Extend Pod Information to Containers Through Environment Variables specifically valueFrom #17041

Open
dboschbach-bw opened this issue Feb 7, 2025 · 0 comments
Labels
enhancement An improvement of an existing feature

Comments

@dboschbach-bw
Copy link

Describe the current behavior

Currently the job template generation only allows to create simple key value pairs even though Kubernetes supports https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/ more.
Example:

"env": {
    "PREFECT_HOME": "/home/prefect",
    "PREFECT_DEBUG_MODE": "false",
    "PREFECT_LOCAL_STORAGE_PATH": "/home/prefect/storage",
    "DD_AGENT_HOST": {
        "valueFrom": {
            "fieldRef": {"apiVersion": "v1", "fieldPath": "status.hostIP"}
        }
    }
}

Results:

env:
...
  - name: PREFECT_DEBUG_MODE
    value: 'False'
  - name: PREFECT_HOME
    value: /home/prefect
  - name: DD_AGENT_HOST
    value: '{''valueFrom'': {''fieldRef'': {''fieldPath'': ''status.hostIP'', ''apiVersion'': ''v1''}}}'
  - name: PREFECT_LOCAL_STORAGE_PATH
    value: /home/prefect/storage

Looking at the Prefect 2 code

class BaseJobConfiguration(BaseModel):
...
async def from_template_and_values (
...
if isinstance(base_config.get("env"), dict) and (
    deployment_env := variables.get("env")
):
    base_config["env"] = {**base_config.get("env", {}), **deployment_env}

or Prefect 3 code it is simply not supported yet.

async def from_template_and_values (
...
    if isinstance(job_config.get("env"), dict) and (
        hardcoded_env := variables.get("env")
    ):
        job_config["env"] = hardcoded_env | job_config.get("env")

Describe the proposed behavior

  • Use Pod fields as values for environment variables
  • Use container fields as values for environment variables

Example Use

Template:

"env": {
    "PREFECT_HOME": "/home/prefect",
    "PREFECT_DEBUG_MODE": "false",
    "PREFECT_LOCAL_STORAGE_PATH": "/home/prefect/storage",
    "DD_AGENT_HOST": {
        "valueFrom": {
            "fieldRef": {"apiVersion": "v1", "fieldPath": "status.hostIP"}
        }
    }
}

Result:

env:
...
  - name: PREFECT_DEBUG_MODE
    value: 'False'
  - name: PREFECT_HOME
    value: /home/prefect
  - name: DD_AGENT_HOST
    valueFrom:
      fieldRef:
        apiVersion: v1
        fieldPath: status.hostIP
  - name: PREFECT_LOCAL_STORAGE_PATH
    value: /home/prefect/storage

Additional context

No response

@dboschbach-bw dboschbach-bw added the enhancement An improvement of an existing feature label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant