From 972c12982927bf2939375eaff9129b391e12cada Mon Sep 17 00:00:00 2001 From: York Chen Date: Mon, 19 Sep 2022 23:10:27 -0400 Subject: [PATCH] feat: pass repoRecorder into helm* controllers --- controllers/helmchart_controller.go | 5 +++-- controllers/helmrepository_controller.go | 3 ++- controllers/helmrepository_controller_test.go | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index 965ddcedc..bb8aa3a2c 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -128,6 +128,7 @@ type HelmChartReconciler struct { Cache *cache.Cache TTL time.Duration *cache.CacheRecorder + RepoRecorder *repository.Recorder } func (r *HelmChartReconciler) SetupWithManager(mgr ctrl.Manager) error { @@ -585,7 +586,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj * } } default: - httpChartRepo, err := repository.NewChartRepository(normalizedURL, r.Storage.LocalPath(*repo.GetArtifact()), r.Getters, tlsConfig, clientOpts, + httpChartRepo, err := repository.NewChartRepository(normalizedURL, r.Storage.LocalPath(*repo.GetArtifact()), r.Getters, tlsConfig, clientOpts, repo.Namespace, r.RepoRecorder, repository.WithMemoryCache(r.Storage.LocalPath(*repo.GetArtifact()), r.Cache, r.TTL, func(event string) { r.IncCacheEvents(event, obj.Name, obj.Namespace) })) @@ -1038,7 +1039,7 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont chartRepo = ociChartRepo } else { - httpChartRepo, err := repository.NewChartRepository(normalizedURL, "", r.Getters, tlsConfig, clientOpts) + httpChartRepo, err := repository.NewChartRepository(normalizedURL, "", r.Getters, tlsConfig, clientOpts, namespace, r.RepoRecorder) if err != nil { return nil, err } diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index ea72a51b6..c1f2ef52a 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -109,6 +109,7 @@ type HelmRepositoryReconciler struct { Cache *cache.Cache TTL time.Duration *cache.CacheRecorder + RepoRecorder *repository.Recorder } type HelmRepositoryReconcilerOptions struct { @@ -398,7 +399,7 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, obj *sou } // Construct Helm chart repository with options and download index - newChartRepo, err := repository.NewChartRepository(obj.Spec.URL, "", r.Getters, tlsConfig, clientOpts) + newChartRepo, err := repository.NewChartRepository(obj.Spec.URL, "", r.Getters, tlsConfig, clientOpts, obj.Namespace, r.RepoRecorder) if err != nil { switch err.(type) { case *url.Error: diff --git a/controllers/helmrepository_controller_test.go b/controllers/helmrepository_controller_test.go index 2e8df4873..5c17c2cdc 100644 --- a/controllers/helmrepository_controller_test.go +++ b/controllers/helmrepository_controller_test.go @@ -600,9 +600,9 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) { if serr != nil { validSecret = false } - newChartRepo, err = repository.NewChartRepository(obj.Spec.URL, "", testGetters, tOpts, clientOpts) + newChartRepo, err = repository.NewChartRepository(obj.Spec.URL, "", testGetters, tOpts, clientOpts, obj.Namespace, testRepoRecorder) } else { - newChartRepo, err = repository.NewChartRepository(obj.Spec.URL, "", testGetters, nil, nil) + newChartRepo, err = repository.NewChartRepository(obj.Spec.URL, "", testGetters, nil, nil, obj.Namespace, testRepoRecorder) } g.Expect(err).ToNot(HaveOccurred()) @@ -736,7 +736,7 @@ func TestHelmRepositoryReconciler_reconcileArtifact(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(cacheFile.Close()).ToNot(HaveOccurred()) - chartRepo, err := repository.NewChartRepository(obj.Spec.URL, "", testGetters, nil, nil) + chartRepo, err := repository.NewChartRepository(obj.Spec.URL, "", testGetters, nil, nil, obj.Namespace, testRepoRecorder) g.Expect(err).ToNot(HaveOccurred()) chartRepo.CachePath = cachePath