CermakM / argo-python-dsl

Python DSL for Argo Workflows | Mirrored to https://github.com/argoproj-labs/argo-python-dsl
https://github.com/argoproj/argo
Apache License 2.0
55 stars 6 forks source link

how to use V1Volume, V1Toleration etc? #12

Closed brtasavpatel closed 4 years ago

brtasavpatel commented 4 years ago

Description I am trying to convert one of our workflow yamls into DSL, which uses few things like volumeClaimTemplates, volumes, volumeMounts, tolerations etc. I can't find any examples for that which explains how can I pass all those configs into V1Container?, any example with DSL would be really helpful.

brtasavpatel commented 4 years ago

I think I found out how to use those, this is an example below, but it seems to have a lot of nested classes which needs to be initiated just to set Affinity. Am I doing it correctly?

from argo.workflows.client import V1alpha1Api

from argo.workflows.dsl import Workflow
from argo.workflows.dsl.tasks import *
from argo.workflows.dsl.templates import *
from kubernetes.client.models import V1Toleration, V1Affinity, V1NodeAffinity, V1NodeSelector, \
    V1NodeSelectorTerm

class TestWorkflow(Workflow):
    service_account_name = 'argo-workflow'

    node_selector = V1NodeSelector(
        node_selector_terms=[
            V1NodeSelectorTerm(
                match_expressions={"key": "app", "operator": "In", "values": ["job"]}),
            V1NodeSelectorTerm(
                match_expressions={"key": "worker", "operator": "In", "values": ["default"]}),
        ])

    node_affnity = V1NodeAffinity(required_during_scheduling_ignored_during_execution=node_selector)

    affinity = V1Affinity(node_affnity)

    tolerations = [V1Toleration(
        key="app",
        operator="Equal",
        value="job",
        effect="NoSchedule"
    )]
yxue-kabam commented 4 years ago

@brtasavpatel tolerations and affinity should go to top level workflow spec see https://github.com/CermakM/argo-client-python/blob/0caa743442d37f2f2e3b30867398ed2708c1bf4d/argo/workflows/client/models/v1alpha1_workflow_spec.py#L59

you are making progress, but currently there is no direct support from the dsl that can help you set those attr directly from within the class.

Once you have the workflow object from TestWorkflow(), try this

workflow.spec.toleration = ...
workflow.spec.affinity = ...
CermakM commented 4 years ago

@yxue-kabam whatever is set as a property to the Workflow becomes part of the WorkflowSpec if that property is valid according to the OpenAPI specification of WorkflowSpec. That being said, @brtasavpatel 's approach is correct, setting affinity property of the Workflow makes part of the workflow.spec.affinity. Unfortunately, that particular property is really annoyingly nested :/ not much we can do here, tho, as this is the specification of it.