Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/argocd/commands/admin/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sort"
"time"

"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/resource_tracking"

"github.com/ghodss/yaml"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -368,7 +368,7 @@ func reconcileApplications(
)

appStateManager := controller.NewAppStateManager(
argoDB, appClientset, repoServerClient, namespace, kubeutil.NewKubectl(), settingsMgr, stateCache, projInformer, server, cache, time.Second, argo.NewResourceTracking())
argoDB, appClientset, repoServerClient, namespace, kubeutil.NewKubectl(), settingsMgr, stateCache, projInformer, server, cache, time.Second, resource_tracking.NewResourceTracking())

appsList, err := appClientset.ArgoprojV1alpha1().Applications(namespace).List(context.Background(), v1.ListOptions{LabelSelector: selector})
if err != nil {
Expand Down Expand Up @@ -410,5 +410,5 @@ func reconcileApplications(
}

func newLiveStateCache(argoDB db.ArgoDB, appInformer kubecache.SharedIndexInformer, settingsMgr *settings.SettingsManager, server *metrics.MetricsServer) cache.LiveStateCache {
return cache.NewLiveStateCache(argoDB, appInformer, settingsMgr, kubeutil.NewKubectl(), server, func(managedByApp map[string]bool, ref apiv1.ObjectReference) {}, nil, argo.NewResourceTracking())
return cache.NewLiveStateCache(argoDB, appInformer, settingsMgr, kubeutil.NewKubectl(), server, func(managedByApp map[string]bool, ref apiv1.ObjectReference) {}, nil, resource_tracking.NewResourceTracking())
}
2 changes: 1 addition & 1 deletion cmd/argocd/commands/admin/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ argocd admin settings resource-overrides ignore-differences ./deploy.yaml --argo

normalizedRes := res.DeepCopy()
logs := collectLogs(func() {
errors.CheckError(normalizer.Normalize(normalizedRes))
errors.CheckError(normalizer.Normalize(normalizedRes, nil, nil))
})
if logs != "" {
_, _ = fmt.Println(logs)
Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
val := argoSettings.ResourceOverrides[k]
overrides[k] = *val
}
normalizer, err := argo.NewDiffNormalizer(app.Spec.IgnoreDifferences, overrides)
normalizer, err := argo.NewDiffNormalizer(app.Spec.IgnoreDifferences, overrides, argoSettings.GetTrackingMethod())
errors.CheckError(err)

diffRes, err := diff.Diff(item.target, item.live, diff.WithNormalizer(normalizer))
Expand Down
6 changes: 4 additions & 2 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"sync"
"time"

"github.com/argoproj/argo-cd/v2/util/resource_tracking"

clustercache "github.com/argoproj/gitops-engine/pkg/cache"
"github.com/argoproj/gitops-engine/pkg/diff"
"github.com/argoproj/gitops-engine/pkg/health"
Expand Down Expand Up @@ -195,8 +197,8 @@ func NewApplicationController(
return nil, err
}
}
stateCache := statecache.NewLiveStateCache(db, appInformer, ctrl.settingsMgr, kubectl, ctrl.metricsServer, ctrl.handleObjectUpdated, clusterFilter, argo.NewResourceTracking())
appStateManager := NewAppStateManager(db, applicationClientset, repoClientset, namespace, kubectl, ctrl.settingsMgr, stateCache, projInformer, ctrl.metricsServer, argoCache, ctrl.statusRefreshTimeout, argo.NewResourceTracking())
stateCache := statecache.NewLiveStateCache(db, appInformer, ctrl.settingsMgr, kubectl, ctrl.metricsServer, ctrl.handleObjectUpdated, clusterFilter, resource_tracking.NewResourceTracking())
appStateManager := NewAppStateManager(db, applicationClientset, repoClientset, namespace, kubectl, ctrl.settingsMgr, stateCache, projInformer, ctrl.metricsServer, argoCache, ctrl.statusRefreshTimeout, resource_tracking.NewResourceTracking())
ctrl.appInformer = appInformer
ctrl.appLister = appLister
ctrl.projInformer = projInformer
Expand Down
8 changes: 5 additions & 3 deletions controller/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sync"
"time"

"github.com/argoproj/argo-cd/v2/util/resource_tracking"

clustercache "github.com/argoproj/gitops-engine/pkg/cache"
"github.com/argoproj/gitops-engine/pkg/health"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
Expand Down Expand Up @@ -106,7 +108,7 @@ func NewLiveStateCache(
metricsServer *metrics.MetricsServer,
onObjectUpdated ObjectUpdatedHandler,
clusterFilter func(cluster *appv1.Cluster) bool,
resourceTracking argo.ResourceTracking) LiveStateCache {
resourceTracking resource_tracking.ResourceTracking) LiveStateCache {

return &liveStateCache{
appInformer: appInformer,
Expand Down Expand Up @@ -136,7 +138,7 @@ type liveStateCache struct {
settingsMgr *settings.SettingsManager
metricsServer *metrics.MetricsServer
clusterFilter func(cluster *appv1.Cluster) bool
resourceTracking argo.ResourceTracking
resourceTracking resource_tracking.ResourceTracking

// listSemaphore is used to limit the number of concurrent memory consuming operations on the
// k8s list queries results across all clusters to avoid memory spikes during cache initialization.
Expand Down Expand Up @@ -288,7 +290,7 @@ func (c *liveStateCache) getCluster(server string) (clustercache.ClusterCache, e
return nil, fmt.Errorf("controller is configured to ignore cluster %s", cluster.Server)
}

trackingMethod := argo.GetTrackingMethod(c.settingsMgr)
trackingMethod := resource_tracking.GetTrackingMethod(c.settingsMgr)
clusterCache = clustercache.NewClusterCache(cluster.RESTConfig(),
clustercache.SetListSemaphore(c.listSemaphore),
clustercache.SetResyncTimeout(K8SClusterResyncDuration),
Expand Down
12 changes: 7 additions & 5 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"reflect"
"time"

"github.com/argoproj/argo-cd/v2/util/resource_tracking"

"github.com/argoproj/gitops-engine/pkg/diff"
"github.com/argoproj/gitops-engine/pkg/health"
"github.com/argoproj/gitops-engine/pkg/sync"
Expand Down Expand Up @@ -98,7 +100,7 @@ type appStateManager struct {
cache *appstatecache.Cache
namespace string
statusRefreshTimeout time.Duration
resourceTracking argo.ResourceTracking
resourceTracking resource_tracking.ResourceTracking
}

func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, source v1alpha1.ApplicationSource, appLabelKey, revision string, noCache, noRevisionCache, verifySignature bool, proj *v1alpha1.AppProject) ([]*unstructured.Unstructured, *apiclient.ManifestResponse, error) {
Expand Down Expand Up @@ -176,7 +178,7 @@ func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, source v1alpha1
ApiVersions: argo.APIGroupsToVersions(apiGroups),
VerifySignature: verifySignature,
HelmRepoCreds: permittedHelmCredentials,
TrackingMethod: string(argo.GetTrackingMethod(m.settingsMgr)),
TrackingMethod: string(resource_tracking.GetTrackingMethod(m.settingsMgr)),
})
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -259,7 +261,7 @@ func (m *appStateManager) getComparisonSettings(app *appv1.Application) (string,
if err != nil {
return "", nil, nil, nil, err
}
diffNormalizer, err := argo.NewDiffNormalizer(app.Spec.IgnoreDifferences, resourceOverrides)
diffNormalizer, err := argo.NewDiffNormalizer(app.Spec.IgnoreDifferences, resourceOverrides, string(resource_tracking.GetTrackingMethod(m.settingsMgr)))
if err != nil {
return "", nil, nil, nil, err
}
Expand Down Expand Up @@ -463,7 +465,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *ap
}
}

trackingMethod := argo.GetTrackingMethod(m.settingsMgr)
trackingMethod := resource_tracking.GetTrackingMethod(m.settingsMgr)

for _, liveObj := range liveObjByKey {
if liveObj != nil {
Expand Down Expand Up @@ -686,7 +688,7 @@ func NewAppStateManager(
metricsServer *metrics.MetricsServer,
cache *appstatecache.Cache,
statusRefreshTimeout time.Duration,
resourceTracking argo.ResourceTracking,
resourceTracking resource_tracking.ResourceTracking,
) AppStateManager {
return &appStateManager{
liveStateCache: liveStateCache,
Expand Down
4 changes: 2 additions & 2 deletions reposerver/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/resource_tracking"

"github.com/go-git/go-git/v5/plumbing"
"github.com/go-redis/redis/v8"
Expand Down Expand Up @@ -194,7 +194,7 @@ func (c *Cache) DeleteManifests(revision string, appSrc *appv1.ApplicationSource

func appDetailsCacheKey(revision string, appSrc *appv1.ApplicationSource, trackingMethod appv1.TrackingMethod) string {
if trackingMethod == "" {
trackingMethod = argo.TrackingMethodLabel
trackingMethod = resource_tracking.TrackingMethodLabel
}
return fmt.Sprintf("appdetails|%s|%d|%s", revision, appSourceKey(appSrc), trackingMethod)
}
Expand Down
8 changes: 4 additions & 4 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strings"
"time"

"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/resource_tracking"

"github.com/Masterminds/semver"
"github.com/TomOnTime/utfutil"
Expand Down Expand Up @@ -69,7 +69,7 @@ type Service struct {
cache *reposervercache.Cache
parallelismLimitSemaphore *semaphore.Weighted
metricsServer *metrics.MetricsServer
resourceTracking argo.ResourceTracking
resourceTracking resource_tracking.ResourceTracking
newGitClient func(rawRepoURL string, creds git.Creds, insecure bool, enableLfs bool, proxy string, opts ...git.ClientOpts) (git.Client, error)
newHelmClient func(repoURL string, creds helm.Creds, enableOci bool, proxy string, opts ...helm.ClientOpts) helm.Client
initConstants RepoServerInitConstants
Expand All @@ -85,7 +85,7 @@ type RepoServerInitConstants struct {
}

// NewService returns a new instance of the Manifest service
func NewService(metricsServer *metrics.MetricsServer, cache *reposervercache.Cache, initConstants RepoServerInitConstants, resourceTracking argo.ResourceTracking) *Service {
func NewService(metricsServer *metrics.MetricsServer, cache *reposervercache.Cache, initConstants RepoServerInitConstants, resourceTracking resource_tracking.ResourceTracking) *Service {
var parallelismLimitSemaphore *semaphore.Weighted
if initConstants.ParallelismLimit > 0 {
parallelismLimitSemaphore = semaphore.NewWeighted(initConstants.ParallelismLimit)
Expand Down Expand Up @@ -715,7 +715,7 @@ func GenerateManifests(appPath, repoRoot, revision string, q *apiclient.Manifest
var targetObjs []*unstructured.Unstructured
var dest *v1alpha1.ApplicationDestination

resourceTracking := argo.NewResourceTracking()
resourceTracking := resource_tracking.NewResourceTracking()
appSourceType, err := GetAppSourceType(q.ApplicationSource, appPath, q.AppName)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"testing"
"time"

"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/resource_tracking"

"github.com/ghodss/yaml"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -72,7 +72,7 @@ func newServiceWithOpt(cf clientFunc) (*Service, *gitmocks.Client) {
cacheutil.NewCache(cacheutil.NewInMemoryCache(1*time.Minute)),
1*time.Minute,
1*time.Minute,
), RepoServerInitConstants{ParallelismLimit: 1}, argo.NewResourceTracking())
), RepoServerInitConstants{ParallelismLimit: 1}, resource_tracking.NewResourceTracking())

chart := "my-chart"
version := "1.1.0"
Expand Down
4 changes: 2 additions & 2 deletions reposerver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/resource_tracking"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
Expand Down Expand Up @@ -94,7 +94,7 @@ func (a *ArgoCDRepoServer) CreateGRPC() *grpc.Server {
versionpkg.RegisterVersionServiceServer(server, version.NewServer(nil, func() (bool, error) {
return true, nil
}))
manifestService := repository.NewService(a.metricsServer, a.cache, a.initConstants, argo.NewResourceTracking())
manifestService := repository.NewService(a.metricsServer, a.cache, a.initConstants, resource_tracking.NewResourceTracking())
apiclient.RegisterRepoServerServiceServer(server, manifestService)

healthService := health.NewServer()
Expand Down
6 changes: 4 additions & 2 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strings"
"time"

"github.com/argoproj/argo-cd/v2/util/resource_tracking"

"github.com/Masterminds/semver"
"github.com/argoproj/gitops-engine/pkg/diff"
"github.com/argoproj/gitops-engine/pkg/sync/common"
Expand Down Expand Up @@ -331,7 +333,7 @@ func (s *Server) GetManifests(ctx context.Context, q *application.ApplicationMan
KubeVersion: serverVersion,
ApiVersions: argo.APIGroupsToVersions(apiGroups),
HelmRepoCreds: helmCreds,
TrackingMethod: string(argoutil.GetTrackingMethod(s.settingsMgr)),
TrackingMethod: string(resource_tracking.GetTrackingMethod(s.settingsMgr)),
})
return err
})
Expand Down Expand Up @@ -415,7 +417,7 @@ func (s *Server) Get(ctx context.Context, q *application.ApplicationQuery) (*app
KustomizeOptions: kustomizeOptions,
Repos: helmRepos,
NoCache: true,
TrackingMethod: string(argoutil.GetTrackingMethod(s.settingsMgr)),
TrackingMethod: string(resource_tracking.GetTrackingMethod(s.settingsMgr)),
})
return err
}); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/argoproj/argo-cd/v2/util/resource_tracking"

"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/stretchr/testify/assert"

"github.com/argoproj/gitops-engine/pkg/health"
. "github.com/argoproj/gitops-engine/pkg/sync/common"
Expand Down Expand Up @@ -41,7 +41,7 @@ func TestDeployment(t *testing.T) {
func TestDeploymentWithAnnotationTrackingMode(t *testing.T) {
ctx := Given(t)

SetTrackingMethod(string(argo.TrackingMethodAnnotation))
SetTrackingMethod(string(resource_tracking.TrackingMethodAnnotation))
ctx.
Path("deployment").
When().
Expand All @@ -64,7 +64,7 @@ func TestDeploymentWithAnnotationTrackingMode(t *testing.T) {

func TestDeploymentWithLabelTrackingMode(t *testing.T) {
ctx := Given(t)
SetTrackingMethod(string(argo.TrackingMethodLabel))
SetTrackingMethod(string(resource_tracking.TrackingMethodLabel))
ctx.
Path("deployment").
When().
Expand Down
6 changes: 4 additions & 2 deletions util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
"time"

"github.com/argoproj/argo-cd/v2/util/resource_tracking"

"github.com/r3labs/diff"

"github.com/argoproj/gitops-engine/pkg/utils/kube"
Expand Down Expand Up @@ -245,7 +247,7 @@ func ValidateRepo(
KustomizeOptions: kustomizeOptions,
// don't use case during application change to make sure to fetch latest git/helm revisions
NoRevisionCache: true,
TrackingMethod: string(GetTrackingMethod(settingsMgr)),
TrackingMethod: string(resource_tracking.GetTrackingMethod(settingsMgr)),
})
if err != nil {
conditions = append(conditions, argoappv1.ApplicationCondition{
Expand Down Expand Up @@ -499,7 +501,7 @@ func verifyGenerateManifests(
KubeVersion: kubeVersion,
ApiVersions: apiVersions,
HelmRepoCreds: repositoryCredentials,
TrackingMethod: string(GetTrackingMethod(settingsMgr)),
TrackingMethod: string(resource_tracking.GetTrackingMethod(settingsMgr)),
}
req.Repo.CopyCredentialsFromRepo(repoRes)
req.Repo.CopySettingsFrom(repoRes)
Expand Down
13 changes: 8 additions & 5 deletions util/argo/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// NewDiffNormalizer creates normalizer that uses Argo CD and application settings to normalize the resource prior to diffing.
func NewDiffNormalizer(ignore []v1alpha1.ResourceIgnoreDifferences, overrides map[string]v1alpha1.ResourceOverride) (diff.Normalizer, error) {
func NewDiffNormalizer(ignore []v1alpha1.ResourceIgnoreDifferences, overrides map[string]v1alpha1.ResourceOverride, trackingMethod string) (diff.Normalizer, error) {
ignoreNormalizer, err := normalizers.NewIgnoreNormalizer(ignore, overrides)
if err != nil {
return nil, err
Expand All @@ -18,18 +18,21 @@ func NewDiffNormalizer(ignore []v1alpha1.ResourceIgnoreDifferences, overrides ma
if err != nil {
return nil, err
}

return &composableNormalizer{normalizers: []diff.Normalizer{ignoreNormalizer, knownTypesNorm}}, nil
resourceIdNormalizer, err := normalizers.NewResourceIdNormalizer(trackingMethod)
if err != nil {
return nil, err
}
return &composableNormalizer{normalizers: []diff.Normalizer{ignoreNormalizer, knownTypesNorm, resourceIdNormalizer}}, nil
}

type composableNormalizer struct {
normalizers []diff.Normalizer
}

// Normalize performs resource normalization.
func (n *composableNormalizer) Normalize(un *unstructured.Unstructured) error {
func (n *composableNormalizer) Normalize(un, config, live *unstructured.Unstructured) error {
for i := range n.normalizers {
if err := n.normalizers[i].Normalize(un); err != nil {
if err := n.normalizers[i].Normalize(un, config, live); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion util/argo/normalizers/diff_normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func NewIgnoreNormalizer(ignore []v1alpha1.ResourceIgnoreDifferences, overrides
}

// Normalize removes fields from supplied resource using json paths from matching items of specified resources ignored differences list
func (n *ignoreNormalizer) Normalize(un *unstructured.Unstructured) error {
func (n *ignoreNormalizer) Normalize(un, config, live *unstructured.Unstructured) error {
matched := make([]normalizerPatch, 0)
for _, patch := range n.patches {
groupKind := un.GroupVersionKind().GroupKind()
Expand Down
Loading