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

Small changes to task argocd-task-sync-and-wait #903

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ metadata:
tekton.dev/tags: deploy
tekton.dev/displayName: "argocd"
tekton.dev/platforms: "linux/amd64"
tekton.dev/deprecated: "true"
spec:
description: >-
This task syncs (deploys) an Argo CD application and waits for it to be healthy.
Expand Down
77 changes: 77 additions & 0 deletions task/argocd-task-sync-and-wait/0.2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Argo CD

This task syncs (deploys) an [Argo CD](https://argoproj.github.io/argo-cd/) application and waits for it to be healthy. To do so, it requires the address of the Argo CD server and some form of authentication - either a username/password or an authentication token.

## Install the Task

```
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/argocd-task-sync-and-wait/0.2/argocd-task-sync-and-wait.yaml
```

## Parameters

* **application-name:** Name of the application to sync

* **revision:** The revision to sync to (_default:_ `HEAD`)

* **flags:** Flags to append after commands, e.g. `--insecure` (_default:_ `--`)

## Platforms

The Task can be run on `linux/amd64` platform.

## Usage

This `Pipeline` implements the typical CD flow using GitOps, as explained [here](https://argoproj.github.io/argo-cd/user-guide/ci_automation/). It runs a sample `Task` that makes and pushes a change to a Git repository, after which it runs the Argo CD `Task` to sync an application based on that repository.

The `ConfigMap` and `Secret` give an example of how to define the Argo CD server address and give credentials for logging in.

```YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-env-configmap
data:
ARGOCD_SERVER: <Argo CD server address>
---
apiVersion: v1
kind: Secret
metadata:
name: argocd-env-secret
data:
# choose one of username/password or auth token
ARGOCD_USERNAME: <username>
ARGOCD_PASSWORD: <password>
ARGOCD_AUTH_TOKEN: <token>
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: argocd-pipeline
spec:
tasks:
- name: push-to-git
taskRef:
name: some-git-task # pushes to the Git repository used by the application in the next task
- name: sync-application
taskRef:
name: argocd-task-sync-and-wait
params:
- name: application-name
value: some-application
- name: flags
value: --insecure # needed in this example only because the Argo CD server is locally hosted
```

For the `Secret`, choose one of username/password or auth token for logging in. Either of the following are acceptable:

```YAML
data:
ARGOCD_USERNAME: <username>
ARGOCD_PASSWORD: <password>
```

```YAML
data:
ARGOCD_AUTH_TOKEN: <token>
```
44 changes: 44 additions & 0 deletions task/argocd-task-sync-and-wait/0.2/argocd-task-sync-and-wait.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: argocd-task-sync-and-wait
labels:
app.kubernetes.io/version: "0.2"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/categories: Deployment
tekton.dev/tags: deploy
tekton.dev/displayName: "argocd"
tekton.dev/platforms: "linux/amd64"
spec:
description: >-
This task syncs (deploys) an Argo CD application and waits for it to be healthy.

To do so, it requires the address of the Argo CD server and some form of
authentication either a username/password or an authentication token.

params:
- name: application-name
description: name of the application to sync
- name: revision
description: the revision to sync to
default: HEAD
- name: flags
default: --
- name: argocd-version
default: v2.2.2
stepTemplate:
envFrom:
- configMapRef:
name: argocd-env-configmap # used for server address
- secretRef:
name: argocd-env-secret # used for authentication (username/password or auth token)
steps:
- name: login
image: quay.io/argoproj/argocd:$(params.argocd-version)
script: |
if [ -z "$ARGOCD_AUTH_TOKEN" ]; then
yes | argocd login "$ARGOCD_SERVER" --username="$ARGOCD_USERNAME" --password="$ARGOCD_PASSWORD";
fi
argocd app sync "$(params.application-name)" --revision "$(params.revision)" "$(params.flags)"
argocd app wait "$(params.application-name)" --health "$(params.flags)"