Skip to content

Commit 92e0b55

Browse files
authoredSep 30, 2024··
feat(appset): Add a cache layer for Argo Projects to speed-up application validation (#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>
1 parent 5d89339 commit 92e0b55

File tree

3 files changed

+78
-161
lines changed

3 files changed

+78
-161
lines changed
 

‎applicationset/controllers/applicationset_controller.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import (
5252
"github.com/argoproj/argo-cd/v2/util/db"
5353

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

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

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

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

337-
logCtx.WithField("requeueAfter", requeueAfter).Info("end reconcile")
336+
logCtx.WithField("requeueAfter", requeueAfter).Info("end reconcile in ", time.Since(startReconcile))
338337

339338
return ctrl.Result{
340339
RequeueAfter: requeueAfter,
@@ -472,7 +471,9 @@ func (r *ApplicationSetReconciler) validateGeneratedApplications(ctx context.Con
472471
errorsByIndex[i] = fmt.Errorf("ApplicationSet %s contains applications with duplicate name: %s", applicationSetInfo.Name, app.Name)
473472
continue
474473
}
475-
_, err := r.ArgoAppClientset.ArgoprojV1alpha1().AppProjects(r.ArgoCDNamespace).Get(ctx, app.Spec.GetProject(), metav1.GetOptions{})
474+
475+
appProject := &argov1alpha1.AppProject{}
476+
err := r.Client.Get(ctx, types.NamespacedName{Name: app.Spec.Project, Namespace: r.ArgoCDNamespace}, appProject)
476477
if err != nil {
477478
if apierr.IsNotFound(err) {
478479
errorsByIndex[i] = fmt.Errorf("application references project %s which does not exist", app.Spec.Project)

‎applicationset/controllers/applicationset_controller_test.go

+73-154
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737

3838
appsetmetrics "github.com/argoproj/argo-cd/v2/applicationset/metrics"
3939
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
40-
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned/fake"
4140
dbmocks "github.com/argoproj/argo-cd/v2/util/db/mocks"
4241

4342
"github.com/argoproj/argo-cd/v2/pkg/apis/application"
@@ -48,9 +47,6 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
4847
err := v1alpha1.AddToScheme(scheme)
4948
require.NoError(t, err)
5049

51-
err = v1alpha1.AddToScheme(scheme)
52-
require.NoError(t, err)
53-
5450
for _, c := range []struct {
5551
// name is human-readable test name
5652
name string
@@ -1091,9 +1087,6 @@ func TestRemoveFinalizerOnInvalidDestination_FinalizerTypes(t *testing.T) {
10911087
err := v1alpha1.AddToScheme(scheme)
10921088
require.NoError(t, err)
10931089

1094-
err = v1alpha1.AddToScheme(scheme)
1095-
require.NoError(t, err)
1096-
10971090
for _, c := range []struct {
10981091
// name is human-readable test name
10991092
name string
@@ -1214,9 +1207,6 @@ func TestRemoveFinalizerOnInvalidDestination_DestinationTypes(t *testing.T) {
12141207
err := v1alpha1.AddToScheme(scheme)
12151208
require.NoError(t, err)
12161209

1217-
err = v1alpha1.AddToScheme(scheme)
1218-
require.NoError(t, err)
1219-
12201210
for _, c := range []struct {
12211211
// name is human-readable test name
12221212
name string
@@ -1371,9 +1361,6 @@ func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) {
13711361
err := v1alpha1.AddToScheme(scheme)
13721362
require.NoError(t, err)
13731363

1374-
err = v1alpha1.AddToScheme(scheme)
1375-
require.NoError(t, err)
1376-
13771364
for _, c := range []struct {
13781365
// name is human-readable test name
13791366
name string
@@ -1447,9 +1434,6 @@ func TestCreateApplications(t *testing.T) {
14471434
err := v1alpha1.AddToScheme(scheme)
14481435
require.NoError(t, err)
14491436

1450-
err = v1alpha1.AddToScheme(scheme)
1451-
require.NoError(t, err)
1452-
14531437
testCases := []struct {
14541438
name string
14551439
appSet v1alpha1.ApplicationSet
@@ -1653,8 +1637,6 @@ func TestDeleteInCluster(t *testing.T) {
16531637
scheme := runtime.NewScheme()
16541638
err := v1alpha1.AddToScheme(scheme)
16551639
require.NoError(t, err)
1656-
err = v1alpha1.AddToScheme(scheme)
1657-
require.NoError(t, err)
16581640

16591641
for _, c := range []struct {
16601642
// appSet is the application set on which the delete function is called
@@ -1809,8 +1791,6 @@ func TestGetMinRequeueAfter(t *testing.T) {
18091791
scheme := runtime.NewScheme()
18101792
err := v1alpha1.AddToScheme(scheme)
18111793
require.NoError(t, err)
1812-
err = v1alpha1.AddToScheme(scheme)
1813-
require.NoError(t, err)
18141794

18151795
client := fake.NewClientBuilder().WithScheme(scheme).Build()
18161796
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
@@ -1913,12 +1893,6 @@ func TestValidateGeneratedApplications(t *testing.T) {
19131893
err := v1alpha1.AddToScheme(scheme)
19141894
require.NoError(t, err)
19151895

1916-
err = v1alpha1.AddToScheme(scheme)
1917-
require.NoError(t, err)
1918-
1919-
client := fake.NewClientBuilder().WithScheme(scheme).Build()
1920-
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
1921-
19221896
// Valid cluster
19231897
myCluster := v1alpha1.Cluster{
19241898
Server: "https://kubernetes.default.svc",
@@ -1945,6 +1919,9 @@ func TestValidateGeneratedApplications(t *testing.T) {
19451919
},
19461920
}
19471921

1922+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(myProject).Build()
1923+
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
1924+
19481925
// Test a subset of the validations that 'validateGeneratedApplications' performs
19491926
for _, cc := range []struct {
19501927
name string
@@ -2094,21 +2071,15 @@ func TestValidateGeneratedApplications(t *testing.T) {
20942071
myCluster,
20952072
}}, nil)
20962073

2097-
argoObjs := []runtime.Object{myProject}
2098-
for _, app := range cc.apps {
2099-
argoObjs = append(argoObjs, &app)
2100-
}
2101-
21022074
r := ApplicationSetReconciler{
2103-
Client: client,
2104-
Scheme: scheme,
2105-
Recorder: record.NewFakeRecorder(1),
2106-
Generators: map[string]generators.Generator{},
2107-
ArgoDB: &argoDBMock,
2108-
ArgoCDNamespace: "namespace",
2109-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
2110-
KubeClientset: kubeclientset,
2111-
Metrics: metrics,
2075+
Client: client,
2076+
Scheme: scheme,
2077+
Recorder: record.NewFakeRecorder(1),
2078+
Generators: map[string]generators.Generator{},
2079+
ArgoDB: &argoDBMock,
2080+
ArgoCDNamespace: "namespace",
2081+
KubeClientset: kubeclientset,
2082+
Metrics: metrics,
21122083
}
21132084

21142085
appSetInfo := v1alpha1.ApplicationSet{}
@@ -2150,8 +2121,6 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
21502121
scheme := runtime.NewScheme()
21512122
err := v1alpha1.AddToScheme(scheme)
21522123
require.NoError(t, err)
2153-
err = v1alpha1.AddToScheme(scheme)
2154-
require.NoError(t, err)
21552124

21562125
project := v1alpha1.AppProject{
21572126
ObjectMeta: metav1.ObjectMeta{Name: "good-project", Namespace: "argocd"},
@@ -2190,9 +2159,8 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
21902159

21912160
kubeclientset := kubefake.NewSimpleClientset()
21922161
argoDBMock := dbmocks.ArgoDB{}
2193-
argoObjs := []runtime.Object{&project}
21942162

2195-
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
2163+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &project).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
21962164
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
21972165
goodCluster := v1alpha1.Cluster{Server: "https://good-cluster", Name: "good-cluster"}
21982166
badCluster := v1alpha1.Cluster{Server: "https://bad-cluster", Name: "bad-cluster"}
@@ -2210,12 +2178,11 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
22102178
Generators: map[string]generators.Generator{
22112179
"List": generators.NewListGenerator(),
22122180
},
2213-
ArgoDB: &argoDBMock,
2214-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
2215-
KubeClientset: kubeclientset,
2216-
Policy: v1alpha1.ApplicationsSyncPolicySync,
2217-
ArgoCDNamespace: "argocd",
2218-
Metrics: metrics,
2181+
ArgoDB: &argoDBMock,
2182+
KubeClientset: kubeclientset,
2183+
Policy: v1alpha1.ApplicationsSyncPolicySync,
2184+
ArgoCDNamespace: "argocd",
2185+
Metrics: metrics,
22192186
}
22202187

22212188
req := ctrl.Request{
@@ -2246,8 +2213,6 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
22462213
scheme := runtime.NewScheme()
22472214
err := v1alpha1.AddToScheme(scheme)
22482215
require.NoError(t, err)
2249-
err = v1alpha1.AddToScheme(scheme)
2250-
require.NoError(t, err)
22512216

22522217
testCases := []struct {
22532218
appset v1alpha1.ApplicationSet
@@ -2395,7 +2360,6 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
23952360

23962361
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
23972362
argoDBMock := dbmocks.ArgoDB{}
2398-
argoObjs := []runtime.Object{}
23992363

24002364
for _, testCase := range testCases {
24012365
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&testCase.appset).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).WithStatusSubresource(&testCase.appset).Build()
@@ -2409,10 +2373,9 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
24092373
Generators: map[string]generators.Generator{
24102374
"List": generators.NewListGenerator(),
24112375
},
2412-
ArgoDB: &argoDBMock,
2413-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
2414-
KubeClientset: kubeclientset,
2415-
Metrics: metrics,
2376+
ArgoDB: &argoDBMock,
2377+
KubeClientset: kubeclientset,
2378+
Metrics: metrics,
24162379
}
24172380

24182381
for _, condition := range testCase.conditions {
@@ -2428,8 +2391,6 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
24282391
scheme := runtime.NewScheme()
24292392
err := v1alpha1.AddToScheme(scheme)
24302393
require.NoError(t, err)
2431-
err = v1alpha1.AddToScheme(scheme)
2432-
require.NoError(t, err)
24332394

24342395
defaultProject := v1alpha1.AppProject{
24352396
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"},
@@ -2469,9 +2430,8 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
24692430

24702431
kubeclientset := kubefake.NewSimpleClientset()
24712432
argoDBMock := dbmocks.ArgoDB{}
2472-
argoObjs := []runtime.Object{&defaultProject}
24732433

2474-
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
2434+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
24752435
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
24762436
goodCluster := v1alpha1.Cluster{Server: "https://good-cluster", Name: "good-cluster"}
24772437
argoDBMock.On("GetCluster", mock.Anything, "https://good-cluster").Return(&goodCluster, nil)
@@ -2489,7 +2449,6 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
24892449
},
24902450
ArgoDB: &argoDBMock,
24912451
ArgoCDNamespace: "argocd",
2492-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
24932452
KubeClientset: kubeclientset,
24942453
Policy: v1alpha1.ApplicationsSyncPolicySync,
24952454
EnablePolicyOverride: allowPolicyOverride,
@@ -2593,8 +2552,6 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
25932552
scheme := runtime.NewScheme()
25942553
err := v1alpha1.AddToScheme(scheme)
25952554
require.NoError(t, err)
2596-
err = v1alpha1.AddToScheme(scheme)
2597-
require.NoError(t, err)
25982555

25992556
defaultProject := v1alpha1.AppProject{
26002557
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"},
@@ -2634,9 +2591,8 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
26342591

26352592
kubeclientset := kubefake.NewSimpleClientset()
26362593
argoDBMock := dbmocks.ArgoDB{}
2637-
argoObjs := []runtime.Object{&defaultProject}
26382594

2639-
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
2595+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
26402596
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
26412597
goodCluster := v1alpha1.Cluster{Server: "https://good-cluster", Name: "good-cluster"}
26422598
argoDBMock.On("GetCluster", mock.Anything, "https://good-cluster").Return(&goodCluster, nil)
@@ -2654,7 +2610,6 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
26542610
},
26552611
ArgoDB: &argoDBMock,
26562612
ArgoCDNamespace: "argocd",
2657-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
26582613
KubeClientset: kubeclientset,
26592614
Policy: v1alpha1.ApplicationsSyncPolicySync,
26602615
EnablePolicyOverride: allowPolicyOverride,
@@ -2752,9 +2707,6 @@ func TestPolicies(t *testing.T) {
27522707
err := v1alpha1.AddToScheme(scheme)
27532708
require.NoError(t, err)
27542709

2755-
err = v1alpha1.AddToScheme(scheme)
2756-
require.NoError(t, err)
2757-
27582710
defaultProject := v1alpha1.AppProject{
27592711
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"},
27602712
Spec: v1alpha1.AppProjectSpec{SourceRepos: []string{"*"}, Destinations: []v1alpha1.ApplicationDestination{{Namespace: "*", Server: "https://kubernetes.default.svc"}}},
@@ -2767,7 +2719,6 @@ func TestPolicies(t *testing.T) {
27672719
kubeclientset := kubefake.NewSimpleClientset()
27682720
argoDBMock := dbmocks.ArgoDB{}
27692721
argoDBMock.On("GetCluster", mock.Anything, "https://kubernetes.default.svc").Return(&myCluster, nil)
2770-
argoObjs := []runtime.Object{&defaultProject}
27712722

27722723
for _, c := range []struct {
27732724
name string
@@ -2839,7 +2790,7 @@ func TestPolicies(t *testing.T) {
28392790
},
28402791
}
28412792

2842-
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
2793+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
28432794
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
28442795

28452796
r := ApplicationSetReconciler{
@@ -2850,12 +2801,11 @@ func TestPolicies(t *testing.T) {
28502801
Generators: map[string]generators.Generator{
28512802
"List": generators.NewListGenerator(),
28522803
},
2853-
ArgoDB: &argoDBMock,
2854-
ArgoCDNamespace: "argocd",
2855-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
2856-
KubeClientset: kubeclientset,
2857-
Policy: policy,
2858-
Metrics: metrics,
2804+
ArgoDB: &argoDBMock,
2805+
ArgoCDNamespace: "argocd",
2806+
KubeClientset: kubeclientset,
2807+
Policy: policy,
2808+
Metrics: metrics,
28592809
}
28602810

28612811
req := ctrl.Request{
@@ -2923,12 +2873,9 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) {
29232873
scheme := runtime.NewScheme()
29242874
err := v1alpha1.AddToScheme(scheme)
29252875
require.NoError(t, err)
2926-
err = v1alpha1.AddToScheme(scheme)
2927-
require.NoError(t, err)
29282876

29292877
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
29302878
argoDBMock := dbmocks.ArgoDB{}
2931-
argoObjs := []runtime.Object{}
29322879

29332880
for _, cc := range []struct {
29342881
name string
@@ -3012,10 +2959,9 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) {
30122959
Generators: map[string]generators.Generator{
30132960
"List": generators.NewListGenerator(),
30142961
},
3015-
ArgoDB: &argoDBMock,
3016-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
3017-
KubeClientset: kubeclientset,
3018-
Metrics: metrics,
2962+
ArgoDB: &argoDBMock,
2963+
KubeClientset: kubeclientset,
2964+
Metrics: metrics,
30192965
}
30202966

30212967
err = r.setAppSetApplicationStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.appStatuses)
@@ -3031,9 +2977,6 @@ func TestBuildAppDependencyList(t *testing.T) {
30312977
err := v1alpha1.AddToScheme(scheme)
30322978
require.NoError(t, err)
30332979

3034-
err = v1alpha1.AddToScheme(scheme)
3035-
require.NoError(t, err)
3036-
30372980
client := fake.NewClientBuilder().WithScheme(scheme).Build()
30382981
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
30392982

@@ -3766,17 +3709,15 @@ func TestBuildAppDependencyList(t *testing.T) {
37663709
t.Run(cc.name, func(t *testing.T) {
37673710
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
37683711
argoDBMock := dbmocks.ArgoDB{}
3769-
argoObjs := []runtime.Object{}
37703712

37713713
r := ApplicationSetReconciler{
3772-
Client: client,
3773-
Scheme: scheme,
3774-
Recorder: record.NewFakeRecorder(1),
3775-
Generators: map[string]generators.Generator{},
3776-
ArgoDB: &argoDBMock,
3777-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
3778-
KubeClientset: kubeclientset,
3779-
Metrics: metrics,
3714+
Client: client,
3715+
Scheme: scheme,
3716+
Recorder: record.NewFakeRecorder(1),
3717+
Generators: map[string]generators.Generator{},
3718+
ArgoDB: &argoDBMock,
3719+
KubeClientset: kubeclientset,
3720+
Metrics: metrics,
37803721
}
37813722

37823723
appDependencyList, appStepMap := r.buildAppDependencyList(log.NewEntry(log.StandardLogger()), cc.appSet, cc.apps)
@@ -3791,9 +3732,6 @@ func TestBuildAppSyncMap(t *testing.T) {
37913732
err := v1alpha1.AddToScheme(scheme)
37923733
require.NoError(t, err)
37933734

3794-
err = v1alpha1.AddToScheme(scheme)
3795-
require.NoError(t, err)
3796-
37973735
client := fake.NewClientBuilder().WithScheme(scheme).Build()
37983736
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
37993737

@@ -4357,17 +4295,15 @@ func TestBuildAppSyncMap(t *testing.T) {
43574295
t.Run(cc.name, func(t *testing.T) {
43584296
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
43594297
argoDBMock := dbmocks.ArgoDB{}
4360-
argoObjs := []runtime.Object{}
43614298

43624299
r := ApplicationSetReconciler{
4363-
Client: client,
4364-
Scheme: scheme,
4365-
Recorder: record.NewFakeRecorder(1),
4366-
Generators: map[string]generators.Generator{},
4367-
ArgoDB: &argoDBMock,
4368-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
4369-
KubeClientset: kubeclientset,
4370-
Metrics: metrics,
4300+
Client: client,
4301+
Scheme: scheme,
4302+
Recorder: record.NewFakeRecorder(1),
4303+
Generators: map[string]generators.Generator{},
4304+
ArgoDB: &argoDBMock,
4305+
KubeClientset: kubeclientset,
4306+
Metrics: metrics,
43714307
}
43724308

43734309
appSyncMap := r.buildAppSyncMap(cc.appSet, cc.appDependencyList, cc.appMap)
@@ -4381,9 +4317,6 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) {
43814317
err := v1alpha1.AddToScheme(scheme)
43824318
require.NoError(t, err)
43834319

4384-
err = v1alpha1.AddToScheme(scheme)
4385-
require.NoError(t, err)
4386-
43874320
for _, cc := range []struct {
43884321
name string
43894322
appSet v1alpha1.ApplicationSet
@@ -5144,20 +5077,18 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) {
51445077
t.Run(cc.name, func(t *testing.T) {
51455078
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
51465079
argoDBMock := dbmocks.ArgoDB{}
5147-
argoObjs := []runtime.Object{}
51485080

51495081
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&cc.appSet).WithStatusSubresource(&cc.appSet).Build()
51505082
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
51515083

51525084
r := ApplicationSetReconciler{
5153-
Client: client,
5154-
Scheme: scheme,
5155-
Recorder: record.NewFakeRecorder(1),
5156-
Generators: map[string]generators.Generator{},
5157-
ArgoDB: &argoDBMock,
5158-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
5159-
KubeClientset: kubeclientset,
5160-
Metrics: metrics,
5085+
Client: client,
5086+
Scheme: scheme,
5087+
Recorder: record.NewFakeRecorder(1),
5088+
Generators: map[string]generators.Generator{},
5089+
ArgoDB: &argoDBMock,
5090+
KubeClientset: kubeclientset,
5091+
Metrics: metrics,
51615092
}
51625093

51635094
appStatuses, err := r.updateApplicationSetApplicationStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps, cc.appStepMap)
@@ -5178,9 +5109,6 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) {
51785109
err := v1alpha1.AddToScheme(scheme)
51795110
require.NoError(t, err)
51805111

5181-
err = v1alpha1.AddToScheme(scheme)
5182-
require.NoError(t, err)
5183-
51845112
for _, cc := range []struct {
51855113
name string
51865114
appSet v1alpha1.ApplicationSet
@@ -5898,20 +5826,18 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) {
58985826
t.Run(cc.name, func(t *testing.T) {
58995827
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
59005828
argoDBMock := dbmocks.ArgoDB{}
5901-
argoObjs := []runtime.Object{}
59025829

59035830
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&cc.appSet).WithStatusSubresource(&cc.appSet).Build()
59045831
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
59055832

59065833
r := ApplicationSetReconciler{
5907-
Client: client,
5908-
Scheme: scheme,
5909-
Recorder: record.NewFakeRecorder(1),
5910-
Generators: map[string]generators.Generator{},
5911-
ArgoDB: &argoDBMock,
5912-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
5913-
KubeClientset: kubeclientset,
5914-
Metrics: metrics,
5834+
Client: client,
5835+
Scheme: scheme,
5836+
Recorder: record.NewFakeRecorder(1),
5837+
Generators: map[string]generators.Generator{},
5838+
ArgoDB: &argoDBMock,
5839+
KubeClientset: kubeclientset,
5840+
Metrics: metrics,
59155841
}
59165842

59175843
appStatuses, err := r.updateApplicationSetApplicationStatusProgress(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.appSyncMap, cc.appStepMap)
@@ -5932,9 +5858,6 @@ func TestUpdateResourceStatus(t *testing.T) {
59325858
err := v1alpha1.AddToScheme(scheme)
59335859
require.NoError(t, err)
59345860

5935-
err = v1alpha1.AddToScheme(scheme)
5936-
require.NoError(t, err)
5937-
59385861
for _, cc := range []struct {
59395862
name string
59405863
appSet v1alpha1.ApplicationSet
@@ -6114,20 +6037,18 @@ func TestUpdateResourceStatus(t *testing.T) {
61146037
t.Run(cc.name, func(t *testing.T) {
61156038
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
61166039
argoDBMock := dbmocks.ArgoDB{}
6117-
argoObjs := []runtime.Object{}
61186040

61196041
client := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(&cc.appSet).WithObjects(&cc.appSet).Build()
61206042
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
61216043

61226044
r := ApplicationSetReconciler{
6123-
Client: client,
6124-
Scheme: scheme,
6125-
Recorder: record.NewFakeRecorder(1),
6126-
Generators: map[string]generators.Generator{},
6127-
ArgoDB: &argoDBMock,
6128-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
6129-
KubeClientset: kubeclientset,
6130-
Metrics: metrics,
6045+
Client: client,
6046+
Scheme: scheme,
6047+
Recorder: record.NewFakeRecorder(1),
6048+
Generators: map[string]generators.Generator{},
6049+
ArgoDB: &argoDBMock,
6050+
KubeClientset: kubeclientset,
6051+
Metrics: metrics,
61316052
}
61326053

61336054
err := r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
@@ -6206,20 +6127,18 @@ func TestResourceStatusAreOrdered(t *testing.T) {
62066127
t.Run(cc.name, func(t *testing.T) {
62076128
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
62086129
argoDBMock := dbmocks.ArgoDB{}
6209-
argoObjs := []runtime.Object{}
62106130

62116131
client := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(&cc.appSet).WithObjects(&cc.appSet).Build()
62126132
metrics := appsetmetrics.NewFakeAppsetMetrics(client)
62136133

62146134
r := ApplicationSetReconciler{
6215-
Client: client,
6216-
Scheme: scheme,
6217-
Recorder: record.NewFakeRecorder(1),
6218-
Generators: map[string]generators.Generator{},
6219-
ArgoDB: &argoDBMock,
6220-
ArgoAppClientset: appclientset.NewSimpleClientset(argoObjs...),
6221-
KubeClientset: kubeclientset,
6222-
Metrics: metrics,
6135+
Client: client,
6136+
Scheme: scheme,
6137+
Recorder: record.NewFakeRecorder(1),
6138+
Generators: map[string]generators.Generator{},
6139+
ArgoDB: &argoDBMock,
6140+
KubeClientset: kubeclientset,
6141+
Metrics: metrics,
62236142
}
62246143

62256144
err := r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)

‎cmd/argocd-applicationset-controller/commands/applicationset_controller.go

-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
appsetmetrics "github.com/argoproj/argo-cd/v2/applicationset/metrics"
3939
"github.com/argoproj/argo-cd/v2/applicationset/services"
4040
appv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
41-
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
4241
"github.com/argoproj/argo-cd/v2/util/cli"
4342
"github.com/argoproj/argo-cd/v2/util/db"
4443
"github.com/argoproj/argo-cd/v2/util/errors"
@@ -162,7 +161,6 @@ func NewCommand() *cobra.Command {
162161
errors.CheckError(err)
163162

164163
argoSettingsMgr := argosettings.NewSettingsManager(ctx, k8sClient, namespace)
165-
appSetConfig := appclientset.NewForConfigOrDie(mgr.GetConfig())
166164
argoCDDB := db.NewDB(namespace, argoSettingsMgr, k8sClient)
167165

168166
scmConfig := generators.NewSCMConfig(scmRootCAPath, allowedScmProviders, enableScmProviders, github_app.NewAuthCredentials(argoCDDB.(db.RepoCredsDB)))
@@ -211,7 +209,6 @@ func NewCommand() *cobra.Command {
211209
Renderer: &utils.Render{},
212210
Policy: policyObj,
213211
EnablePolicyOverride: enablePolicyOverride,
214-
ArgoAppClientset: appSetConfig,
215212
KubeClientset: k8sClient,
216213
ArgoDB: argoCDDB,
217214
ArgoCDNamespace: namespace,

0 commit comments

Comments
 (0)
Please sign in to comment.