-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This task is used to sync an Argo CD application with its underlying Git repository and to wait for it to become healthy. It takes in no resources, only parameters, and passes them to the argocd command. The application's name and the Argo CD server address are required. Some form of login is also required, either through a username/password combo or an authentication token. The specific revision to sync to and the flags to append to commands can also be passed as parameters. Currently there is no way to pass plain strings or files between tasks, or it could have been better to split the login and sync tasks. This way, there could have been two login tasks - one for username/password and one for authentication token. With the current approach, the bash command runs an if statement to see if the token's default value was overriden, and if so, it uses that token. Otherwise, it uses the username/password passed in. This issue (typing of PipelineResources) is being discussed in tektoncd/pipeline#238.
- Loading branch information
1 parent
984c3a2
commit 917c35e
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Argo CD | ||
|
||
This task syncs 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. | ||
|
||
## Install the Task | ||
|
||
``` | ||
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/argocd/argocd.yaml | ||
``` | ||
|
||
## Inputs | ||
|
||
### Parameters | ||
|
||
* **server:** Argo CD server address | ||
|
||
* **username:** Login username (_default:_ admin) | ||
|
||
* **password:** Login password (_default:_ admin) | ||
|
||
* **token:** Login token, used in place of username/password if default is overridden (_default:_ none) | ||
|
||
* **application-name:** Name of the application to sync | ||
|
||
* **revision:** The revision to sync to | ||
|
||
* **flags:** Flags to append after commands, e.g. `--insecure` (_default:_ `--`) | ||
|
||
## Usage | ||
|
||
This Pipeline 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. | ||
|
||
```YAML | ||
apiVersion: tekton.dev/v1alpha1 | ||
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: server | ||
value: argocd-server.argocd.svc.cluster.local | ||
- name: application-name | ||
value: some-application | ||
- name: username | ||
value: admin | ||
- name: password | ||
value: password123 | ||
- name: flags | ||
value: --insecure # needed in this example only because the Argo CD server is locally hosted | ||
``` | ||
Note that | ||
```YAML | ||
- name: username | ||
value: admin | ||
- name: password | ||
value: password123 | ||
``` | ||
can be replaced with | ||
``` YAML | ||
- name: token | ||
value: some-token | ||
``` | ||
as another way to log in. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: argocd-task-sync-and-wait | ||
spec: | ||
inputs: | ||
params: | ||
- name: server | ||
description: address of the Argo CD server | ||
- name: username | ||
description: Argo CD username | ||
default: admin | ||
- name: password | ||
description: Argo CD password | ||
default: admin | ||
- name: token | ||
description: Argo CD token (leave blank to use username/password login instead) | ||
default: none | ||
- name: application-name | ||
description: name of the application to sync | ||
- name: revision | ||
description: the revision to sync to | ||
default: HEAD | ||
- name: flags | ||
default: -- | ||
steps: | ||
- name: login | ||
image: argoproj/argocd | ||
command: ["bash", "-c", "if [ ${inputs.params.token} = 'none' ]; \ | ||
then yes | argocd login ${inputs.params.server} --username=${inputs.params.username} --password=${inputs.params.password}; \ | ||
else echo 'export ARGOCD_SERVER=${inputs.params.server} ; export ARGOCD_AUTH_TOKEN=${inputs.params.token}' > ~/env.sh; \ | ||
chmod 777 ~/env.sh; fi"] | ||
- name: sync | ||
image: argoproj/argocd | ||
command: ["bash", "-c", "source ~/env.sh > /dev/null ; argocd app sync ${inputs.params.application-name} --revision ${inputs.params.revision} ${inputs.params.flags}"] | ||
- name: wait | ||
image: argoproj/argocd | ||
command: ["bash", "-c", "source ~/env.sh > /dev/null ; argocd app wait ${inputs.params.application-name} --health ${inputs.params.flags}"] |