important-london-94970
01/08/2025, 9:15 PM.env
and then redefining in @environment
, it would be really convenient if I could define this value for them so it gets injected into every step that has the @kubernetes
decoratorancient-application-36103
01/08/2025, 9:18 PMimportant-london-94970
01/08/2025, 9:24 PMMETAFLOW_KUBERNETES_SECRETS
which is working for my use caseancient-application-36103
01/08/2025, 9:29 PMvictorious-lawyer-58417
01/08/2025, 11:07 PM.env
, you could read the desired env vars from a config which you can inject in every @kubernetes
step like this:
import os
from pprint import pprint
from functools import wraps
from metaflow import FlowSpec, step, Config, kubernetes
def my_k8s(f):
@wraps(f)
def wrapper(self):
os.environ.update(self.config)
f(self)
return kubernetes(wrapper)
class CommonEnvFlow(FlowSpec):
config = Config('config', default='config.json')
@my_k8s
@step
def start(self):
pprint(dict(os.environ))
self.next(self.end)
@my_k8s
@step
def end(self):
pprint(dict(os.environ))
if __name__ == '__main__':
CommonEnvFlow()
and then your config is something like
{
"FIRST_VAR": "hello",
"SECOND_VAR": "world"
}