Chapter 2. Creating an application by using the GitOps CLI With Argo CD, you can create your applications on an OpenShift Container Platform cluster by using the GitOps argocd CLI. 2.1. Creating an application in the default mode by using the GitOps CLI You can create applications in the default mode by using the GitOps argocd CLI. Prerequisites You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster. You have installed the OpenShift CLI ( oc ). You have installed the Red Hat OpenShift GitOps argocd CLI. You have logged in to Argo CD instance. Procedure Get the admin account password for the Argo CD server: USD ADMIN_PASSWD=USD(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d) Get the Argo CD server URL: USD SERVER_URL=USD(oc get routes openshift-gitops-server -n openshift-gitops -o jsonpath='{.status.ingress[0].host}') Log in to the Argo CD server by using the admin account password and enclosing it in single quotes: Important Enclosing the password in single quotes ensures that special characters, such as USD , are not misinterpreted by the shell. Always use single quotes to enclose the literal value of the password. USD argocd login --username admin --password USD{ADMIN_PASSWD} USD{SERVER_URL} Example USD argocd login --username admin --password '<password>' openshift-gitops.openshift-gitops.apps-crc.testing Verify that you are able to run argocd commands in the default mode by listing all applications: USD argocd app list If the configuration is correct, then existing applications will be listed with the following header: Sample output NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET Create an application in the default mode: USD argocd app create app-spring-petclinic \ --repo https://github.com/redhat-developer/openshift-gitops-getting-started.git \ --path app \ --revision main \ --dest-server https://kubernetes.default.svc \ --dest-namespace spring-petclinic \ --directory-recurse \ --sync-policy automated \ --self-heal \ --sync-option Prune=true \ --sync-option CreateNamespace=true Label the spring-petclinic destination namespace to be managed by the openshif-gitops Argo CD instance: USD oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops" List the available applications to confirm that the application is created successfully and repeat the command until the application has the Healthy and Synced statuses: USD argocd app list 2.2. Creating an application in core mode by using the GitOps CLI You can create applications in core mode by using the GitOps argocd CLI. Prerequisites You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster. You have installed the OpenShift CLI ( oc ). You have installed the Red Hat OpenShift GitOps argocd CLI. Procedure Log in to the OpenShift Container Platform cluster by using the oc CLI tool: USD oc login -u <username> -p <password> <server_url> Example USD oc login -u kubeadmin -p '<password>' https://api.crc.testing:6443 Check whether the context is set correctly in the kubeconfig file: USD oc config current-context Set the default namespace of the current context to openshift-gitops : USD oc config set-context --current --namespace openshift-gitops Set the following environment variable to override the Argo CD component names: USD export ARGOCD_REPO_SERVER_NAME=openshift-gitops-repo-server Verify that you are able to run argocd commands in core mode by listing all applications: USD argocd app list --core If the configuration is correct, then existing applications will be listed with the following header: Sample output NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET Create an application in core mode: USD argocd app create app-spring-petclinic --core \ --repo https://github.com/redhat-developer/openshift-gitops-getting-started.git \ --path app \ --revision main \ --dest-server https://kubernetes.default.svc \ --dest-namespace spring-petclinic \ --directory-recurse \ --sync-policy automated \ --self-heal \ --sync-option Prune=true \ --sync-option CreateNamespace=true Label the spring-petclinic destination namespace to be managed by the openshif-gitops Argo CD instance: USD oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops" List the available applications to confirm that the application is created successfully and repeat the command until the application has the Healthy and Synced statuses: USD argocd app list --core 2.3. Additional resources Installing the GitOps CLI Basic GitOps argocd commands

Commands:
ADMIN_PASSWD=USD(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)
SERVER_URL=USD(oc get routes openshift-gitops-server -n openshift-gitops -o jsonpath='{.status.ingress[0].host}')
argocd login --username admin --password USD{ADMIN_PASSWD} USD{SERVER_URL}
argocd login --username admin --password '<password>' openshift-gitops.openshift-gitops.apps-crc.testing
argocd app list
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
argocd app create app-spring-petclinic --repo https://github.com/redhat-developer/openshift-gitops-getting-started.git --path app --revision main --dest-server https://kubernetes.default.svc --dest-namespace spring-petclinic --directory-recurse --sync-policy automated --self-heal --sync-option Prune=true --sync-option CreateNamespace=true
oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"
argocd app list
oc login -u <username> -p <password> <server_url>
oc login -u kubeadmin -p '<password>' https://api.crc.testing:6443
oc config current-context
oc config set-context --current --namespace openshift-gitops
export ARGOCD_REPO_SERVER_NAME=openshift-gitops-repo-server
argocd app list --core
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
argocd app create app-spring-petclinic --core --repo https://github.com/redhat-developer/openshift-gitops-getting-started.git --path app --revision main --dest-server https://kubernetes.default.svc --dest-namespace spring-petclinic --directory-recurse --sync-policy automated --self-heal --sync-option Prune=true --sync-option CreateNamespace=true
oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"
argocd app list --core