Skip to content

Commit

Permalink
feat(appset): Add a cache layer for Argo Projects to speed-up applica…
Browse files Browse the repository at this point in the history
…tion validation (argoproj#18703)

* feat(appset): Add a cache layer for Argo Projects to speed-up application validation

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

* Use local client rather than custom cache

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

* Clean go.mod

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

* Merge master

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

* Fix after merging master
Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

* Initialize appProject variable inside loop

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

* Remove unused ArgoAppClientset field
Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

* Fix linter issue
Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>

---------

Signed-off-by: Philippe Da Costa <pdacosta@gmail.com>
Signed-off-by: Adrian Aneci <aneci@adobe.com>
  • Loading branch information
dacofr authored and adriananeci committed Dec 4, 2024
1 parent bd5d7be commit 64dd048
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 161 deletions.
9 changes: 5 additions & 4 deletions applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import (
"github.com/argoproj/argo-cd/v2/util/db"

argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
argoutil "github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/argo/normalizers"

Expand All @@ -79,7 +78,6 @@ type ApplicationSetReconciler struct {
Recorder record.EventRecorder
Generators map[string]generators.Generator
ArgoDB db.ArgoDB
ArgoAppClientset appclientset.Interface
KubeClientset kubernetes.Interface
Policy argov1alpha1.ApplicationsSyncPolicy
EnablePolicyOverride bool
Expand All @@ -97,6 +95,7 @@ type ApplicationSetReconciler struct {
// +kubebuilder:rbac:groups=argoproj.io,resources=applicationsets/status,verbs=get;update;patch

func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
startReconcile := time.Now()
logCtx := log.WithField("applicationset", req.NamespacedName)

var applicationSetInfo argov1alpha1.ApplicationSet
Expand Down Expand Up @@ -334,7 +333,7 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque
requeueAfter = ReconcileRequeueOnValidationError
}

logCtx.WithField("requeueAfter", requeueAfter).Info("end reconcile")
logCtx.WithField("requeueAfter", requeueAfter).Info("end reconcile in ", time.Since(startReconcile))

return ctrl.Result{
RequeueAfter: requeueAfter,
Expand Down Expand Up @@ -472,7 +471,9 @@ func (r *ApplicationSetReconciler) validateGeneratedApplications(ctx context.Con
errorsByIndex[i] = fmt.Errorf("ApplicationSet %s contains applications with duplicate name: %s", applicationSetInfo.Name, app.Name)
continue
}
_, err := r.ArgoAppClientset.ArgoprojV1alpha1().AppProjects(r.ArgoCDNamespace).Get(ctx, app.Spec.GetProject(), metav1.GetOptions{})

appProject := &argov1alpha1.AppProject{}
err := r.Client.Get(ctx, types.NamespacedName{Name: app.Spec.Project, Namespace: r.ArgoCDNamespace}, appProject)
if err != nil {
if apierr.IsNotFound(err) {
errorsByIndex[i] = fmt.Errorf("application references project %s which does not exist", app.Spec.Project)
Expand Down
Loading

0 comments on commit 64dd048

Please sign in to comment.