argoproj / gitops-engine

Democratizing GitOps
https://pkg.go.dev/github.com/argoproj/gitops-engine?tab=subdirectories
Apache License 2.0
1.7k stars 265 forks source link

Stop reconciliation on empty CRD modifications #555

Open prune998 opened 1 year ago

prune998 commented 1 year ago

This code compares cached CRD to the new MODIFICATION event and skip reconciling the CRD if the change is trivial.

Here's what changes in the CRD in a GKE cluster where the addon-manager keeps patching some CRDs:

argocd-application-controller-0 application-controller watchEvents mismatch for CRD {apiextensions.k8s.io CustomResourceDefinition  gcpbackendpolicies.networking.gke.io} (-want +got):
argocd-application-controller-0 application-controller   v1.CustomResourceDefinition{
argocd-application-controller-0 application-controller      TypeMeta: {Kind: "CustomResourceDefinition", APIVersion: "apiextensions.k8s.io/v1"},
argocd-application-controller-0 application-controller      ObjectMeta: v1.ObjectMeta{
argocd-application-controller-0 application-controller          ... // 3 identical fields
argocd-application-controller-0 application-controller          SelfLink:          "",
argocd-application-controller-0 application-controller          UID:               "8a9b77ed-241f-43a6-8125-f5b43879b8af",
argocd-application-controller-0 application-controller -        ResourceVersion:   "2187186233",
argocd-application-controller-0 application-controller +        ResourceVersion:   "2187186273",
argocd-application-controller-0 application-controller          Generation:        1,
argocd-application-controller-0 application-controller          CreationTimestamp: {Time: s"2023-05-29 13:53:32 +0000 UTC"},
argocd-application-controller-0 application-controller          ... // 4 identical fields
argocd-application-controller-0 application-controller          OwnerReferences: nil,
argocd-application-controller-0 application-controller          Finalizers:      nil,
argocd-application-controller-0 application-controller          ManagedFields: []v1.ManagedFieldsEntry{
argocd-application-controller-0 application-controller              {
argocd-application-controller-0 application-controller                  Manager:     "kube-addon-manager",
argocd-application-controller-0 application-controller                  Operation:   "Apply",
argocd-application-controller-0 application-controller                  APIVersion:  "apiextensions.k8s.io/v1",
argocd-application-controller-0 application-controller -                Time:        s"2023-11-27 22:37:40 +0000 UTC",
argocd-application-controller-0 application-controller +                Time:        s"2023-11-27 22:37:41 +0000 UTC",
argocd-application-controller-0 application-controller                  FieldsType:  "FieldsV1",
argocd-application-controller-0 application-controller                  FieldsV1:    &{Raw: `{"f:metadata":{"f:annotations":{"f:components.gke.io/component-n`...},
argocd-application-controller-0 application-controller                  Subresource: "",
argocd-application-controller-0 application-controller              },
argocd-application-controller-0 application-controller              {Manager: "kube-apiserver", Operation: "Update", APIVersion: "apiextensions.k8s.io/v1", Time: s"2023-05-29 13:53:32 +0000 UTC", ...},
argocd-application-controller-0 application-controller          },
argocd-application-controller-0 application-controller      },
argocd-application-controller-0 application-controller      Spec:

This PR just stop tracking those changes and fully skip the CRD reconciliation.

In case a real change is made to the CRD, the normal behavious applies:

argocd-application-controller-0 application-controller watchEvents mismatch for CRD after cleanup {apiextensions.k8s.io CustomResourceDefinition  lbpolicies.networking.gke.io} (-want +got):
argocd-application-controller-0 application-controller   v1.CustomResourceDefinition{
argocd-application-controller-0 application-controller      TypeMeta: {Kind: "CustomResourceDefinition", APIVersion: "apiextensions.k8s.io/v1"},
argocd-application-controller-0 application-controller      ObjectMeta: v1.ObjectMeta{
argocd-application-controller-0 application-controller          ... // 9 identical fields
argocd-application-controller-0 application-controller          DeletionGracePeriodSeconds: nil,
argocd-application-controller-0 application-controller          Labels:                     {"addonmanager.kubernetes.io/mode": "Reconcile"},
argocd-application-controller-0 application-controller          Annotations: map[string]string{
argocd-application-controller-0 application-controller              "components.gke.io/component-name":      "gateway-api-crds",
argocd-application-controller-0 application-controller              "components.gke.io/component-version":   "0.7.0-gke.0",
argocd-application-controller-0 application-controller              "components.gke.io/layer":               "addon",
argocd-application-controller-0 application-controller -            "controller-gen.kubebuilder.io/version": "(unknown)",
argocd-application-controller-0 application-controller +            "controller-gen.kubebuilder.io/version": "v1.0.0",
argocd-application-controller-0 application-controller          },
argocd-application-controller-0 application-controller          OwnerReferences: nil,
argocd-application-controller-0 application-controller          Finalizers:      nil,
argocd-application-controller-0 application-controller          ManagedFields:   {},
argocd-application-controller-0 application-controller      },
argocd-application-controller-0 application-controller      Spec:
sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

codecov[bot] commented 1 year ago

Codecov Report

Attention: 30 lines in your changes are missing coverage. Please review.

Comparison is base (4a5648e) 54.70% compared to head (518494f) 54.36%. Report is 1 commits behind head on master.

Files Patch % Lines
pkg/cache/cluster.go 0.00% 26 Missing :warning:
pkg/sync/sync_context.go 82.60% 2 Missing and 2 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #555 +/- ## ========================================== - Coverage 54.70% 54.36% -0.34% ========================================== Files 41 41 Lines 4645 4672 +27 ========================================== - Hits 2541 2540 -1 - Misses 1908 1935 +27 - Partials 196 197 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.