great-egg-84692
08/12/2025, 7:01 PM--with kubernetes
or argo-workflows
.
Currently, we put the validation code in config/mfextinit_org.py
, but that gets run even when user just tries to run the flow locally, which is annoying, esp. when the validation fails, and user gets confused why is k8s even relevant when they run the flow locally.
What would be the recommended way to put such checks? An equivalent question is how to know if the user command needs to interact with k8s or not reliably from the extension?victorious-lawyer-58417
08/12/2025, 7:07 PM@kubernetes
based on your policies - much easier than creating an extensionvictorious-lawyer-58417
08/12/2025, 7:07 PMgreat-egg-84692
08/12/2025, 7:27 PMvictorious-lawyer-58417
08/12/2025, 7:28 PMdry-beach-38304
08/12/2025, 7:29 PMdry-beach-38304
08/12/2025, 7:29 PMvictorious-lawyer-58417
08/12/2025, 7:29 PMgreat-egg-84692
08/12/2025, 8:18 PMvictorious-lawyer-58417
08/12/2025, 8:19 PMgreat-egg-84692
08/12/2025, 9:01 PM2.14.0
victorious-lawyer-58417
08/12/2025, 9:03 PMgreat-egg-84692
08/12/2025, 9:10 PM--with kubernetes
) or using argo-workflows create
there is no pre-specified policy on when to use kubernetes.
I'm looking for an integration point that can help tell whether the user command will require interaction with kubernetes or not so I can do the validation accordingly. E.g. when user just run
python flow.py run
and flow.py
has no use of @kubernetes
then, I can skip the validation. In other case, when
python flow.py run --with kubernetes
or
python flow.py argo-workflows create
then the validation logic should be triggered. Is mutator still the right pattern?victorious-lawyer-58417
08/12/2025, 9:19 PM@kubernetes
is present, and if so, performs validation (this might work with argo-workflows create
out of the box, but need to confirm)
• instead of --with kubernetes
, you can instruct your users to use --with mykubernetes
(you can call it whatever you want), which performs validation and adds @kubernetes
interallygreat-egg-84692
08/12/2025, 9:21 PMargo-workflows create
doesn't have much to do with @kubernetes
.
the validation we need to check is basically ensuring user are using the right k8s context when interacting with k8s.victorious-lawyer-58417
08/12/2025, 9:23 PMargo-workflows create
manually? If it's done via CI/CD, it should be easy to insert a mutator programmaticallygreat-egg-84692
08/12/2025, 9:24 PMdo your users callCurrently, yes.manually?argo-workflows create
victorious-lawyer-58417
08/12/2025, 9:29 PMclass validated_k8s(FlowMutator):
def mutate(self, mutable_flow):
if 'argo-workflows create' in ' '.join(sys.argv):
print('deploying to argo')
for name, s in mutable_flow.steps:
s.add_decorator('kubernetes')
i.e. have a flow mutator that applies the desired @kubernetes
decorators prior to deployment (and/or you can check what the user has added by themselves)great-egg-84692
08/13/2025, 2:37 PM@kubernetes
to step, more like detecting it in the flow so that the extension will validate the k8s context.
Since we're still using an old version and mutator isn't available, I decide to just using a flow decorator like
def flow_init(
self,
flow: FlowSpec,
graph: graph_.FlowGraph,
environment: metaflow_environment.MetaflowEnvironment,
flow_datastore: flow_datastore_.FlowDataStore,
metadata: metadata_.MetadataProvider,
logger: Callable[..., None],
echo: Callable[..., None],
options: dict[str, Any],
):
if any(deco.name == 'kubernetes' for step in flow for deco in step.decorators) or 'argo-workflows' in sys.argv or '--with kubernetes' in sys.argv:
validate_kubectx(metaflow_config.CSS_RUN_ENV)
the condition is just for illustrating the idea and will be made more robust.victorious-lawyer-58417
08/13/2025, 5:09 PMvalidate_kubectx
but no need to change it if it works 🙂
mutators are way easier to create than extensions and the mutator API is stable vs. technically the extensions APIs may introduce breaking changing in the futuregreat-egg-84692
08/13/2025, 5:14 PMmutators are way easier to create than extensions and the mutator API is stable vs. technically the extensions APIs may introduce breaking changing in the futureunderstood, it's just legacy. I feel upgrading metaflow will have more pain, we forked metaflow. the custom decorator https://docs.metaflow.org/metaflow/composing-flows/custom-decorators is also new compared to the version of metaflow we use and it looks a much easier way to develop decorators then the extension way, i.e. subclass
FlowDecorator
dry-beach-38304
08/13/2025, 5:24 PM