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

how to use V1Volume, V1Toleration etc? #12

Closed
brtasavpatel opened this issue Mar 3, 2020 · 3 comments
Closed

how to use V1Volume, V1Toleration etc? #12

brtasavpatel opened this issue Mar 3, 2020 · 3 comments
Labels
good first issue Good for newcomers question Further information is requested

Comments

@brtasavpatel
Copy link

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 brtasavpatel added the question Further information is requested label Mar 3, 2020
@brtasavpatel
Copy link
Author

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
Copy link

yxue-kabam commented Mar 3, 2020

@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
Copy link
Owner

CermakM commented Mar 4, 2020

@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.

@CermakM CermakM added the good first issue Good for newcomers label Mar 4, 2020
@CermakM CermakM pinned this issue Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants