user10283726
user10283726

Reputation: 81

Argo - submit workflow from python with input parameter file

I basically want to run this command: argo submit -n argo workflows/workflow.yaml -f params.json through the official python SDK.

This example covers how to submit a workflow manifest, but I don't know where to add the input parameter file.

import os
from pprint import pprint
import yaml
from pathlib import Path

import argo_workflows
from argo_workflows.api import workflow_service_api
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow_create_request import \
    IoArgoprojWorkflowV1alpha1WorkflowCreateRequest

configuration = argo_workflows.Configuration(host="https://localhost:2746")
configuration.verify_ssl = False

with open("workflows/workflow.yaml", "r") as f:
    manifest = yaml.safe_load(f)

api_client = argo_workflows.ApiClient(configuration)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)
api_response = api_instance.create_workflow(
    namespace="argo",
    body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest, _check_type=False),
    _check_return_type=False)
pprint(api_response)

Where to pass in the params.json file?

Upvotes: 0

Views: 1744

Answers (1)

tubensandwich
tubensandwich

Reputation: 187

I found this snippet in the docs of WorkflowServiceApi.md (which was apparently too big to render as markdown):

import time
import argo_workflows
from argo_workflows.api import workflow_service_api
from argo_workflows.model.grpc_gateway_runtime_error import GrpcGatewayRuntimeError
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow_submit_request import IoArgoprojWorkflowV1alpha1WorkflowSubmitRequest
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow import IoArgoprojWorkflowV1alpha1Workflow
from pprint import pprint
# Defining the host is optional and defaults to http://localhost:2746
# See configuration.py for a list of all supported configuration parameters.
configuration = argo_workflows.Configuration(
    host = "http://localhost:2746"
)


# Enter a context with an instance of the API client
with argo_workflows.ApiClient() as api_client:
    # Create an instance of the API class
    api_instance = workflow_service_api.WorkflowServiceApi(api_client)
    namespace = "namespace_example" # str | 
    body = IoArgoprojWorkflowV1alpha1WorkflowSubmitRequest(
        namespace="namespace_example",
        resource_kind="resource_kind_example",
        resource_name="resource_name_example",
        submit_options=IoArgoprojWorkflowV1alpha1SubmitOpts(
            annotations="annotations_example",
            dry_run=True,
            entry_point="entry_point_example",
            generate_name="generate_name_example",
            labels="labels_example",
            name="name_example",
            owner_reference=OwnerReference(
                api_version="api_version_example",
                block_owner_deletion=True,
                controller=True,
                kind="kind_example",
                name="name_example",
                uid="uid_example",
            ),
            parameter_file="parameter_file_example",
            parameters=[
                "parameters_example",
            ],
            pod_priority_class_name="pod_priority_class_name_example",
            priority=1,
            server_dry_run=True,
            service_account="service_account_example",
        ),
    ) # IoArgoprojWorkflowV1alpha1WorkflowSubmitRequest | 

    # example passing only required values which don't have defaults set
    try:
        api_response = api_instance.submit_workflow(namespace, body)
        pprint(api_response)
    except argo_workflows.ApiException as e:
        print("Exception when calling WorkflowServiceApi->submit_workflow: %s\n" % e)

Have you tried using a IoArgoprojWorkflowV1alpha1WorkflowSubmitRequest? Looks like it has submit_options of type IoArgoprojWorkflowV1alpha1SubmitOpts which has a parameter_file param.

Upvotes: 0

Related Questions