From 34c4290cda757232dd41672bc303fe30e9690774 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 18 Jan 2021 17:01:54 +0100 Subject: [PATCH] Alin HelmChart source indexer and watches Signed-off-by: Hidde Beydals --- api/v1beta1/source.go | 12 +++--------- controllers/helmchart_controller.go | 9 +++++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/api/v1beta1/source.go b/api/v1beta1/source.go index dc509616..5c10d00f 100644 --- a/api/v1beta1/source.go +++ b/api/v1beta1/source.go @@ -21,15 +21,9 @@ import ( ) const ( - // GitRepositoryIndexKey is the key used for indexing resources - // resources based on their GitRepository source. - GitRepositoryIndexKey string = ".metadata.gitRepository" - // HelmRepositoryIndexKey is the key used for indexing resources - // resources based on their HelmRepository source. - HelmRepositoryIndexKey string = ".meta.helmRepository" - // BucketIndexKey is the key used for indexing resources based on - // their Bucket source. - BucketIndexKey string = ".meta.bucket" + // SourceIndexKey is the key used for indexing resources + // resources based on their Source. + SourceIndexKey string = ".metadata.source" ) // Source interface must be supported by all API types. diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index b6444562..d48bd2e2 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -86,7 +86,7 @@ func (r *HelmChartReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts r.indexHelmRepositoryByURL); err != nil { return fmt.Errorf("failed setting index fields: %w", err) } - if err := mgr.GetCache().IndexField(context.TODO(), &sourcev1.HelmChart{}, sourcev1.GitRepositoryIndexKey, + if err := mgr.GetCache().IndexField(context.TODO(), &sourcev1.HelmChart{}, sourcev1.SourceIndexKey, r.indexHelmChartBySource); err != nil { return fmt.Errorf("failed setting index fields: %w", err) } @@ -845,7 +845,7 @@ func (r *HelmChartReconciler) requestsForHelmRepositoryChange(o client.Object) [ ctx := context.Background() var list sourcev1.HelmChartList if err := r.List(ctx, &list, client.MatchingFields{ - sourcev1.HelmRepositoryIndexKey: util.ObjectKey(o).String(), + sourcev1.SourceIndexKey: fmt.Sprintf("%s/%s", sourcev1.HelmRepositoryKind, repo.Name), }); err != nil { return nil } @@ -866,6 +866,7 @@ func (r *HelmChartReconciler) requestsForGitRepositoryChange(o client.Object) [] if !ok { panic(fmt.Sprintf("Expected a GitRepository, got %T", o)) } + // If we do not have an artifact, we have no requests to make if repo.GetArtifact() == nil { return nil @@ -873,7 +874,7 @@ func (r *HelmChartReconciler) requestsForGitRepositoryChange(o client.Object) [] var list sourcev1.HelmChartList if err := r.List(context.TODO(), &list, client.MatchingFields{ - sourcev1.GitRepositoryIndexKey: util.ObjectKey(o).String(), + sourcev1.SourceIndexKey: fmt.Sprintf("%s/%s", sourcev1.GitRepositoryKind, repo.Name), }); err != nil { return nil } @@ -902,7 +903,7 @@ func (r *HelmChartReconciler) requestsForBucketChange(o client.Object) []reconci var list sourcev1.HelmChartList if err := r.List(context.TODO(), &list, client.MatchingFields{ - sourcev1.BucketIndexKey: util.ObjectKey(o).String(), + sourcev1.SourceIndexKey: fmt.Sprintf("%s/%s", sourcev1.BucketKind, bucket.Name), }); err != nil { return nil }