argoproj / argo-cd

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

repos deleted every other kustomize run #3218

Open lr-carmichael opened 4 years ago

lr-carmichael commented 4 years ago

Checklist:

Describe the bug

I'm building out my declarative ArgoCD deployment, and noticed that every other time I run kubectl apply -k ., it deletes my repositories. The applications never get deleted.

To Reproduce

# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: argocd

bases:
  #- github.com/argoproj/argo-cd//manifests/cluster-install?ref=v1.4.2
  - github.com/argoproj/argo-cd//manifests/cluster-install?ref=master

resources:
  - argo-cd/namespace.yaml
  - argo-cd/repo-config.yaml
  - argo-cd/cluster-app.yaml

patchesStrategicMerge:
  - argo-cd/argocd-server-service.yaml

# repo-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cm
  namespace: argocd
  labels:
    app.kubernetes.io/name: argocd-cm
    app.kubernetes.io/part-of: argocd
data:
  repositories: |
    - url: git@github.com:lr-carmichael/sandbox.git
      sshPrivateKeySecret:
        key: ssh-privatekey
        name: repo-ssh-keypair
      type: git
    - url: git@github.com:lr-carmichael/argocd-example-apps.git
      sshPrivateKeySecret:
        key: ssh-privatekey
        name: repo-ssh-keypair
      type: git

Expected behavior

As I make changes and add new applications or other resources to ArgoCD, I want my repositories to stick around so I don't have to kubectl apply -k . twice every iteration.

Screenshots

n/a

Version

I've reproduced this with both 1.5.0 and 1.4.2 argocd-server images.

argocd version
argocd: v1.4.2+48cced9
  BuildDate: 2020-01-24T01:04:04Z
  GitCommit: 48cced9d925b5bc94f6aa9fa4a8a19b2a59e128a
  GitTreeState: clean
  GoVersion: go1.12.6
  Compiler: gc
  Platform: linux/amd64
argocd-server: v1.5.0+fc00d73
  BuildDate: 2020-03-10T08:51:25Z
  GitCommit: fc00d73cf5b1bcefb01b4d0d724909984a459332
  GitTreeState: clean
  GoVersion: go1.14
  Compiler: gc
  Platform: linux/amd64
  Ksonnet Version: v0.13.1
  Kustomize Version: Version: {Version:kustomize/v3.2.1 GitCommit:d89b448c745937f0cf1936162f26a5aac688f840 BuildDate:2019-09-27T00:10:52Z GoOs:linux GoArch:amd64}
  Helm Version: version.BuildInfo{Version:"v3.1.1", GitCommit:"afe70585407b420d0097d07b21c47dc511525ac8", GitTreeState:"clean", GoVersion:"go1.13.8"}
  Kubectl Version: v1.14.0

Logs

`k get cm argocd-cm -n argocd -o yaml`
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"argocd-cm","app.kubernetes.io/part-of":"argocd"},"name":"argocd-cm","namespace":"argocd"}}
  creationTimestamp: "2020-03-10T14:05:58Z"
  labels:
    app.kubernetes.io/name: argocd-cm
    app.kubernetes.io/part-of: argocd
  name: argocd-cm
  namespace: argocd
  resourceVersion: "26312"
  selfLink: /api/v1/namespaces/argocd/configmaps/argocd-cm
  uid: 758585db-d7cb-4440-b5a2-f34c21c00c08

Note: No changes were made. Just ran it again.

apiVersion: v1
data:
  repositories: |
    - url: git@github.com:lr-carmichael/sandbox.git
      sshPrivateKeySecret:
        key: ssh-privatekey
        name: repo-ssh-keypair
      type: git
    - url: git@github.com:lr-carmichael/argocd-example-apps.git
      sshPrivateKeySecret:
        key: ssh-privatekey
        name: repo-ssh-keypair
      type: git
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"repositories":"- url: git@github.com:lr-carmichael/sandbox.git\n  sshPrivateKeySecret:\n    key: ssh-privatekey\n    name: repo-ssh-keypair\n  type: git\n- url: git@github.com:lr-carmichael/argocd-example-apps.git\n  sshPrivateKeySecret:\n    key: ssh-privatekey\n    name: repo-ssh-keypair\n  type: git\n"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"argocd-cm","app.kubernetes.io/part-of":"argocd"},"name":"argocd-cm","namespace":"argocd"}}
  creationTimestamp: "2020-03-10T14:05:58Z"
  labels:
    app.kubernetes.io/name: argocd-cm
    app.kubernetes.io/part-of: argocd
  name: argocd-cm
  namespace: argocd
  resourceVersion: "26897"
  selfLink: /api/v1/namespaces/argocd/configmaps/argocd-cm
  uid: 758585db-d7cb-4440-b5a2-f34c21c00c08


If I were to run it again with no changes, the repos would all get wiped.
alexmt commented 4 years ago

I run into the same issue. This behavior is inconvenient but expected: the kubectl apply manages ConfigMap declaratively and Argo CD updates. It is impossible to use both at the same time: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/#changing-management-methods

I think the use case is valid and Argo CD should support managing some settings in a declarative way and others using an imperative way. Will create feature request to track it.