argoproj / argo-cd

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

applicationset matrix modify template ignoreDifference not effective #13245

Open 13567436138 opened 1 year ago

13567436138 commented 1 year ago

Checklist:

Describe the bug

To Reproduce applicationSet/appProject-gitlab-https.yaml

kubectl apply -f appProject-gitlab-https.yaml -n argocd

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: project
spec:
  clusterResourceWhitelist:
  - group: ""
    kind: Namespace
  sourceRepos:
    - https://gitlab.example.com/hxp/argocd-test.git
    - https://gitlab.example.com/hxp/argocd-test-2.git
  destinations:
    - server: https://192.168.229.153:6443
      namespace: demo
    - server: https://192.168.229.156:6443
      namespace: demo

applicationSet/appset-generators-matrix-template-ignoreDifferences.yaml

kubectl apply -f appset-generators-matrix-template-ignoreDifferences.yaml -n argocd

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: appset
spec:
  generators:
  - matrix:
      generators:
      - list:
          elements:
            - serverUrl: https://192.168.229.153:6443
              cluster: cluster1
            - serverUrl: https://192.168.229.156:6443
              cluster: cluster2
      - scmProvider:
          gitlab:
            api: https://gitlab.example.com
            allBranches: true
            includeSubgroups: true
            group: hxp
            tokenRef:
              secretName: gitlab-access-token
              key: token
          requeueAfterSeconds: 30
          cloneProtocol: https
          filters:
          - repositoryMatch: "^argocd-test.*" 
      template:
        metadata:
          labels:
            repo: '{{repository}}'
        spec:
          source:
            repoURL: '{{url}}'
            targetRevision: '{{ sha }}'
            path: demo1
          project: project
          destination:
            server: '{{serverUrl}}'
            namespace: demo
          ignoreDifferences:
          - group: apps
            kind: Deployment
            jsonPointers:
            - /spec/template/metadata/annotations
            - /spec/replica
  template:
    metadata:
      name: 'myapp-{{ repository }}-{{cluster}}'
    spec:
      source:
        repoURL: '{{url}}'
        targetRevision: '{{ sha }}'
        path: demo1
      project: project
      destination:
        server: '{{serverUrl}}'
        namespace: demo
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
        - CreateNamespace=true
        - RespectIgnoreDifferences=true
[root@mycompany applicationSet]# argocd app list
NAME                                 CLUSTER                       NAMESPACE  PROJECT  STATUS  HEALTH   SYNCPOLICY  CONDITIONS  REPO                                              PATH   TARGET
argocd/myapp-argocd-test-2-cluster1  https://192.168.229.153:6443  demo       project  Synced  Healthy  Auto-Prune  <none>      https://gitlab.example.com/hxp/argocd-test-2.git  demo1  a473f3f0b026a621b7d11cf8e01ab67e40560e4d
argocd/myapp-argocd-test-2-cluster2  https://192.168.229.156:6443  demo       project  Synced  Healthy  Auto-Prune  <none>      https://gitlab.example.com/hxp/argocd-test-2.git  demo1  a473f3f0b026a621b7d11cf8e01ab67e40560e4d
argocd/myapp-argocd-test-cluster1    https://192.168.229.153:6443  demo       project  Synced  Healthy  Auto-Prune  <none>      https://gitlab.example.com/hxp/argocd-test.git    demo1  fc0905c5d4dd2d010a4b0bc0850c62eba933d50d
argocd/myapp-argocd-test-cluster2    https://192.168.229.156:6443  demo       project  Synced  Healthy  Auto-Prune  <none>      https://gitlab.example.com/hxp/argocd-test.git    demo1  fc0905c5d4dd2d010a4b0bc0850c62eba933d50d

[root@member1-153 ~]# kubectl scale deploy -n demo nginx-2 --replicas=3
deployment.apps/nginx-2 scaled
[root@member1-153 ~]# kubectl get pod -n demo
NAME                       READY   STATUS        RESTARTS   AGE
nginx-2-787f54657b-ccq8z   0/1     Terminating   0          2s
nginx-2-787f54657b-gwqq4   1/1     Running       0          3m44s
nginx-2-787f54657b-k7rbs   0/1     Terminating   0          2s
nginx-787f54657b-m25w2     1/1     Running       0          3m44s

貌似不支持

Expected behavior

Screenshots

Version

Paste the output from `argocd version` here.

Logs

Paste any relevant application logs here.
13567436138 commented 1 year ago

applicationSet/appProject-gitlab-https.yaml

kubectl apply -f appProject-gitlab-https.yaml -n argocd

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: project
spec:
  clusterResourceWhitelist:
  - group: ""
    kind: Namespace
  sourceRepos:
    - https://gitlab.example.com/hxp/argocd-test.git
    - https://gitlab.example.com/hxp/argocd-test-2.git
  destinations:
    - server: https://192.168.229.153:6443
      namespace: demo
    - server: https://192.168.229.156:6443
      namespace: demo

applicationSet/appset-generators-merge-template-ignoreDifferences.yaml

kubectl apply -f appset-generators-merge-template-ignoreDifferences.yaml -n argocd

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: appset
spec:
  generators:
  - merge:
      mergeKeys:
      - repository
      generators:
      - list:
          elements:
            - serverUrl: https://192.168.229.153:6443
              repository: argocd-test
              cluster: cluster1
            - serverUrl: https://192.168.229.156:6443
              repository: argocd-test-2
              cluster: cluster2
      - scmProvider:
          gitlab:
            api: https://gitlab.example.com
            allBranches: true
            includeSubgroups: true
            group: hxp
            tokenRef:
              secretName: gitlab-access-token
              key: token
          requeueAfterSeconds: 30
          cloneProtocol: https
          filters:
          - repositoryMatch: "^argocd-test.*"  
      template:
        metadata:
          labels:
            repo: '{{repository}}'
        spec:
          source:
            repoURL: '{{url}}'
            targetRevision: '{{ sha }}'
            path: demo1
          project: project
          destination:
            server: '{{serverUrl}}'
            namespace: demo
          ignoreDifferences:
          - group: apps
            kind: Deployment
            jsonPointers:
            - /spec/template/metadata/annotations
            - /spec/replica
  template:
    metadata:
      name: 'myapp-{{ repository }}-{{cluster}}'
    spec:
      source:
        repoURL: '{{url}}'
        targetRevision: '{{ sha }}'
        path: demo1
      project: project
      destination:
        server: '{{serverUrl}}'
        namespace: demo
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
        - CreateNamespace=true
        - RespectIgnoreDifferences=true
[root@mycompany applicationSet]# argocd app list
NAME                                 CLUSTER                       NAMESPACE  PROJECT  STATUS  HEALTH   SYNCPOLICY  CONDITIONS  REPO                                              PATH   TARGET
argocd/myapp-argocd-test-2-cluster2  https://192.168.229.156:6443  demo       project  Synced  Healthy  Auto-Prune  <none>      https://gitlab.example.com/hxp/argocd-test-2.git  demo1  a473f3f0b026a621b7d11cf8e01ab67e40560e4d
argocd/myapp-argocd-test-cluster1    https://192.168.229.153:6443  demo       project  Synced  Healthy  Auto-Prune  <none>      https://gitlab.example.com/hxp/argocd-test.git    demo1  fc0905c5d4dd2d010a4b0bc0850c62eba933d50d

[root@member1-153 ~]# kubectl get pod -n demo
NAME                     READY   STATUS    RESTARTS   AGE
nginx-787f54657b-z4drf   1/1     Running   0          19s
[root@member1-153 ~]# kubectl scale deploy nginx -n demo --replicas=3
deployment.apps/nginx scaled
[root@member1-153 ~]# kubectl get pod -n demo
NAME                     READY   STATUS        RESTARTS   AGE
nginx-787f54657b-6g5tw   0/1     Terminating   0          2s
nginx-787f54657b-cjls9   0/1     Terminating   0          2s
nginx-787f54657b-z4drf   1/1     Running       0          32s

不支持

this is not supported also