Bootstrap FreeKB - ArgoCD - Sync Application using the CLI
ArgoCD - Sync Application using the CLI

Updated:   |  ArgoCD articles

This assumes:

You can

  • Sync an app (Push the YAML manifests in ArgoCD to Kubernetes or OpenShift)
  • Refresh a repo (The YAML manifest in ArgoCD will be compared to the YAML in the version control system (such as GitHub) and if any differences are detected the YAML manifest in ArgoCD will be updated to match the YAML in the version control system (such as GitHub))
  • Hard Refresh a repo (YAML manifests in ArgoCD are cached - A hard refresh invalidates the cache which forces the YAML manifests in ArgoCD to match the YAML in the version control system (such as GitHub))

 

The argocd app list command can then be used to list the app you have created.

~]$ argocd app list
NAME                   CLUSTER                         NAMESPACE  PROJECT  STATUS     HEALTH   SYNCPOLICY  CONDITIONS  REPO                                       PATH    TARGET
openshift-gitops/demo  https://kubernetes.default.svc  default    default  OutOfSync  Missing  Manual      <none>      https://github.com/my_project/my_repo.git  python

 

Notice in this example that the app is OutOfSync. The argocd app sync command can be used to attempt to sync the app.

~]$ argocd app sync openshift-gitops/demo
TIMESTAMP                  GROUP        KIND   NAMESPACE                  NAME    STATUS    HEALTH        HOOK  MESSAGE
2024-12-19T20:42:14-06:00   apps  Deployment     default                python  OutOfSync  Missing
2024-12-19T20:42:14-06:00   apps  Deployment     default                python  OutOfSync  Missing              deployments.apps is forbidden: User "system:serviceaccount:openshift-gitops:openshift-gitops-argocd-application-controller" cannot create resource "deployments" in API group "apps" in the namespace "default"
Name:               openshift-gitops/demo
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          default
URL:                https://openshift-gitops-server-openshift-gitops.apps.openshift.example.com/applications/openshift-gitops/demo
Source:
- Repo:             https://github.com/my_project/my_repo.git
  Target:
  Path:             python
SyncWindow:         Sync Allowed
Sync Policy:        Manual
Sync Status:        OutOfSync from  (dbc57d6)
Health Status:      Missing
Operation:          Sync
Sync Revision:      dbc57d62045ddae6c68f925b7cb3f6a1f621bd81
Phase:              Failed
Start:              2024-12-19 20:42:14 -0600 CST
Finished:           2024-12-19 20:42:14 -0600 CST
Duration:           0s
Message:            one or more objects failed to apply, reason: deployments.apps is forbidden: User "system:serviceaccount:openshift-gitops:openshift-gitops-argocd-application-controller" cannot create resource "deployments" in API group "apps" in the namespace "default"
GROUP  KIND        NAMESPACE  NAME    STATUS     HEALTH   HOOK  MESSAGE
apps   Deployment  default    python  OutOfSync  Missing        deployments.apps is forbidden: User "system:serviceaccount:openshift-gitops:openshift-gitops-argocd-application-controller" cannot create resource "deployments" in API group "apps" in the namespace "default"
FATA[0000] Operation has completed with phase: Failed

 

As a default safety feature, automated sync in ArgoCD doesn't delete resources that have been removed from the Git repository. These resources then need to be pruned. The --prune flag can be used if you want to also prune which will remove resources that no longer exist in the git repo.

argocd app sync openshift-gitops/demo --prune

 

The "server" pod should contain logs like this.

~]$ oc logs openshift-gitops-server-6794f7fc56-sh8hx --namespace openshift-gitops

time="2025-01-15T02:14:55Z" level=info msg="Refreshing app status (spec.source differs), level (3)" app-namespace=openshift-gitops app-qualified-name=openshift-gitops/hello-world application=hello-world project=default

time="2025-01-15T02:14:55Z" level=info msg="Comparing app state (cluster: https://kubernetes.default.svc, namespace: my-project)" application=openshift-gitops/hello-world

time="2025-01-15T02:15:01Z" level=info msg="Updated sync status:  -> OutOfSync" application=hello-world dest-namespace=my-project dest-server="https://kubernetes.default.svc" reason=ResourceUpdated type=Normal

time="2025-01-15T02:15:01Z" level=info msg="Updated health status:  -> Missing" application=hello-world dest-namespace=my-project dest-server="https://kubernetes.default.svc" reason=ResourceUpdated type=Normal

time="2025-01-15T02:15:01Z" level=info msg="Update successful" app-namespace=openshift-gitops app-qualified-name=openshift-gitops/hello-world application=hello-world project=default

time="2025-01-15T02:15:01Z" level=info msg=Syncing application=openshift-gitops/hello-world skipHooks=false started=false syncId=00001-XEDbR

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter a2da55 in the box below so that we can be sure you are a human.