argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
17.84k stars 5.45k forks source link

argocd app create --dest-name command is not idempotent #18794

Open par97 opened 4 months ago

par97 commented 4 months ago

Checklist:

Describe the bug

argocd app create command should be idempotent, but when I use --dest-name parameter, it becomes not idempotent.

To Reproduce

par@rhocs-bm6 ~ $ argocd version
argocd: v2.11.3+3f344d5
  BuildDate: 2024-06-06T09:27:36Z
  GitCommit: 3f344d54a4e0bbbb4313e1c19cfe1e544b162598
  GitTreeState: clean
  GoVersion: go1.21.10
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.11.3+3f344d5
  BuildDate: 2024-06-06T09:27:36Z
  GitCommit: 3f344d54a4e0bbbb4313e1c19cfe1e544b162598
  GitTreeState: clean
  GoVersion: go1.21.10
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v5.4.1 2024-04-04T17:14:00Z
  Helm Version: v3.14.4+g81c902a
  Kubectl Version: v0.26.11
  Jsonnet Version: v0.20.0

par@rhocs-bm6 ~ $ argocd cluster list
SERVER                          NAME        VERSION  STATUS  MESSAGE  PROJECT
https://kubernetes.default.svc  in-cluster

par@rhocs-bm6 ~ $ argocd app create guestbook-1 --repo=https://github.com/argoproj/argocd-example-apps.git --path=guestbook --dest-server https://kubernetes.default.svc --dest-namespace=argocd-test-1 --sync-option=CreateNamespace=true --sync-policy=automated

application 'guestbook-1' created
par@rhocs-bm6 ~ $ argocd app create guestbook-1 --repo=https://github.com/argoproj/argocd-example-apps.git --path=guestbook --dest-server https://kubernetes.default.svc --dest-namespace=argocd-test-1 --sync-option=CreateNamespace=true --sync-policy=automated

application 'guestbook-1' unchanged       <-------- this is expected

par@rhocs-bm6 ~ $ argocd app create guestbook-2 --repo=https://github.com/argoproj/argocd-example-apps.git --path=guestbook --dest-name in-cluster --dest-namespace=argocd-test-2 --sync-option=CreateNamespace=true --sync-policy=automated
application 'guestbook-2' created

par@rhocs-bm6 ~ $ argocd app create guestbook-2 --repo=https://github.com/argoproj/argocd-example-apps.git --path=guestbook --dest-name in-cluster --dest-namespace=argocd-test-2 --sync-option=CreateNamespace=true --sync-policy=automated
FATA[0002] rpc error: code = InvalidArgument desc = existing application spec is different, 
use upsert flag to force update   <--------- this is not expected.
agaudreault commented 4 months ago

With the existence of the --upsert flag and validation of the spec, it seems like this is the intended behavior.

par97 commented 4 months ago

according to issue https://github.com/argoproj/argo-cd/issues/238, --upsert flag is used when the existing app spec is different.

from argocd app create --help: --upsert Allows to override application with the same name even if supplied application spec is different from existing spec

In my above examples, the app spec is the same, using "--dest-server" is ok, but using "--dest-name" shows error.

agaudreault commented 4 months ago

That makes sense, thanks for clarifying :)

parambath92 commented 4 months ago

Hi @agaudreault , I would like to work on this issue.

theikalman commented 3 months ago

Do you still work on this @parambath92 ? if not, I'll take it.

parambath92 commented 3 months ago

Hey @theikalman , yes I am working on this issue. I will raise a PR this week.

DomineCore commented 3 months ago

/assign

DomineCore commented 3 months ago

Are you still working on fixing the problem? If not, I can fix it. @parambath92

theikalman commented 2 months ago

Since there's no response from @parambath92 , I try to fix the issue. Please help me to review.