<@ULVA73B9P> Is it possible to use `valueFrom` in ...
# ask-marvin
m
@Marvin Is it possible to use
valueFrom
in the env section in Base Job Template json?
m
Using placeholders such as
{{ variable_name }}
within the
env
section of the BaseJobTemplate JSON in Prefect 2.x is possible. Placeholders allow you to reference values provided in the variables section. These placeholders are declared using double curly braces, which means you can customize your environment variables using the variables that you define. Here's an excerpt from the documentation highlighting this:
job_configuration values can also be hard-coded if the value should not be customizable. Each worker type is configured with a default base job template, making it easy to start with a work pool.
For a more detailed example and explanation of how to use these placeholders, it's advised to look at the Prefect documentation, specifically the section about work pools and the base job template configuration, which can be found here.
m
Yeah, I added:
Copy code
"POD_IP": {
      "valueFrom": {
        "fieldRef": {
          "fieldPath": "status.podIP",
          "apiVersion": "v1"
        }
      }
    },
to
{{ env }}
but it failed:
Copy code
Failed to submit flow run '1b04588e-8a19-4bab-bbf4-cc61a97c2313' to infrastructure.
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/prefect/workers/base.py", line 894, in _submit_run_and_capture_errors
    configuration = await self._get_configuration(flow_run)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prefect/workers/base.py", line 969, in _get_configuration
    configuration = await self.job_configuration.from_template_and_values(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prefect/client/utilities.py", line 51, in with_injected_client
    return await fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prefect/workers/base.py", line 152, in from_template_and_values
    return cls(**populated_configuration)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 6 validation errors for KubernetesWorkerJobConfiguration
env -> POD_IP
  str type expected (type=type_error.str)