How to Pass Key-Values between Argo Workflows Part 2
November 22, 2022
7 min read
Learn how to pass key-values between Argo workflows, which include using `ConfigMap`, `Secrets`, and `Artifacts`.
The first part of this series introduced Argo Workflows, explained how to set up an Argo workflow in your Kubernetes cluster, and discussed different methods of passing key-values between Argo workflow steps, which included using `scripts and results` and `output parameters`.
In this second part of the series, you’ll learn how to pass key-values between Argo workflows, which include using `ConfigMap`, `Secrets`, and `Artifacts`.
Why Do You Need to Pass Key-Values between Workflows?
As your project gets bigger, it becomes harder to fit all your jobs in a single workflow containing multiple steps. Instead, you start to namespace similar jobs together in multiple workflows for easier management and to keep related jobs together.
However, there are instances where you need to share configuration data across multiple workflows. Fortunately, Argo’s `ConfigMap` and `Secrets` allow you to share configuration data across multiple workflows, removing the overhead of scoping each configuration data to every workflow.
Furthermore, there are instances where you want to use the output result of a workflow in multiple other workflows. This can be accomplished using an artifact repository, which you can configure in Argo Workflows. The following sections will discuss how to use `ConfigMap`, `Secrets`, and `Artifacts` to share data.
Passing Key-Values Between Workflows Using ConfigMap
Argo Workflows provides three methods of using `ConfigMap` key-values in your workflows:
- Using `arguments` parameters from `ConfigMap`
- Using `global parameters` referenced from `ConfigMap` as a local variable
- Using `global parameters` referenced from `ConfigMap`
In order to use any of these methods, the `ConfigMap` you want to use should already exist in your cluster.
Create a file named `simple-configmap.yaml` and paste the following:
In your terminal, run the command below to apply the `ConfigMap` in your cluster:
The `ConfigMap` you just created will be used to explain the different methods of using `ConfigMap` key-values in your Argo workflows.
Using Arguments Parameters from ConfigMap
In part one of this series, you learned how to use `parameters` to pass key-values to Argo workflows. The `parameters` contained custom values that you manually included in the workflow template via `arguments` or `inputs`. In scenarios where these custom values are required in multiple workflow files, it becomes cumbersome to manually edit these files, and this is where `ConfigMap` becomes useful, as mentioned earlier.
Using `ConfigMap`, you can pass values into your workflow `parameters`. In the workflow below, the `whalesay` template has `config`, a parameter whose value is extracted from the `simple-configmap` you created earlier:
Using Global Parameters Referenced from ConfigMap as a Local Variable
ConfigMaps are not only restricted to steps in a `WorkflowTemplate`. When the `ConfigMap` value is to be used in multiple steps, instead of referencing the `ConfigMap` locally as `input` in each `WorkflowTemplate`, you can reference the `ConfigMap` in `arguments` at the `spec` level; this change will allow each step in the workflow to use the `ConfigMap` value that’s set in the `arguments.parameters`:
Using Global Parameters Referenced from ConfigMap
You can also reference your workflow `arguments.parameters` directly in your template steps, without having to create an `inputs.parameters` reference in the `WorkflowTemplate` as seen below:
Passing Key-Values between Workflows Using Secrets
Similar to using `ConfigMap` to pass key-values, you can also use `Secrets`. You can first start by creating a sample secret to use. In your terminal, run the following command to create `new-secret`:
Next, you can create a workflow using the secret you just created. To access the secret as a file, you add a volume entry in `specs.volumes` and also add a mount using `volumeMounts` in the container template spec:
You can now use the `Secret` directly in your workflow step as seen above in the `whalesay template`.
Passing Key-Values between Workflows Using the Artifact Repository
Artifacts are output files generated by Argo Workflow steps. There are instances in your Argo workflows where a particular workflow requires the output of another workflow. For instance, continuous integration/continuous development (CI/CD) is an important process in the development and release of an application. You can have a workflow that ensures your application passes all the tests and then creates a build artifact that can be deployed by another workflow to your staging environment.
The example below demonstrates this process as a workflow that generates a text in a file, which is then used by another workflow. The other workflow retrieves the text in the file and displays it.
However, you should note that you need an artifacts repository to use artifacts. Argo supports S3-compatible artifact repositories such as AWS, GCS, MinIO, and so on. You can check out the Argo Workflow Repository and follow the guide to install the repository storage of your choice.
The workflow below generates a text file containing “hello world” and saves it in the location configured in the artifact repository:
Other workflows will be able to use the artifact generated by the first workflow when they’re submitted using the sample code below. The workflow template links to the location in the artifact repository where the required data is stored. It then retrieves the data and performs the necessary action, which is to output the data:
This article concludes this series about passing key-values between Argo workflows. In this two-part series, you were introduced to Argo Workflows, a Kubernetes tool for running multiple Kubernetes jobs in series or in parallel. You also learned about the structure of an Argo `Workflow template` and how to pass key-values between workflows using `scripts and results`, `output parameters`, `ConfigMap`, `Secrets`, and `Artifacts`.
If your team has been looking to get started with Argo Workflows, Pipekit provides production-ready workflows in minutes by configuring Argo Workflows on your infrastructure. It’s easy to set up and provides a built-in logging system. You can even run Argo Workflows on Pipekit Cloud without running Kubernetes.
Subscribe for Pipekit updates.
Get the latest articles on all things Pipekit & data orchestration delivered straight to your inbox.