Skip to content

Commit 2c7c188

Browse files
authored
Merge pull request #260 from fluxcd/watch-chart-sources
Align HelmChart source indexer and watches
2 parents 97b6bed + 34c4290 commit 2c7c188

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

api/v1beta1/source.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,9 @@ import (
2121
)
2222

2323
const (
24-
// GitRepositoryIndexKey is the key used for indexing resources
25-
// resources based on their GitRepository source.
26-
GitRepositoryIndexKey string = ".metadata.gitRepository"
27-
// HelmRepositoryIndexKey is the key used for indexing resources
28-
// resources based on their HelmRepository source.
29-
HelmRepositoryIndexKey string = ".meta.helmRepository"
30-
// BucketIndexKey is the key used for indexing resources based on
31-
// their Bucket source.
32-
BucketIndexKey string = ".meta.bucket"
24+
// SourceIndexKey is the key used for indexing resources
25+
// resources based on their Source.
26+
SourceIndexKey string = ".metadata.source"
3327
)
3428

3529
// Source interface must be supported by all API types.

controllers/helmchart_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (r *HelmChartReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts
8686
r.indexHelmRepositoryByURL); err != nil {
8787
return fmt.Errorf("failed setting index fields: %w", err)
8888
}
89-
if err := mgr.GetCache().IndexField(context.TODO(), &sourcev1.HelmChart{}, sourcev1.GitRepositoryIndexKey,
89+
if err := mgr.GetCache().IndexField(context.TODO(), &sourcev1.HelmChart{}, sourcev1.SourceIndexKey,
9090
r.indexHelmChartBySource); err != nil {
9191
return fmt.Errorf("failed setting index fields: %w", err)
9292
}
@@ -845,7 +845,7 @@ func (r *HelmChartReconciler) requestsForHelmRepositoryChange(o client.Object) [
845845
ctx := context.Background()
846846
var list sourcev1.HelmChartList
847847
if err := r.List(ctx, &list, client.MatchingFields{
848-
sourcev1.HelmRepositoryIndexKey: util.ObjectKey(o).String(),
848+
sourcev1.SourceIndexKey: fmt.Sprintf("%s/%s", sourcev1.HelmRepositoryKind, repo.Name),
849849
}); err != nil {
850850
return nil
851851
}
@@ -866,14 +866,15 @@ func (r *HelmChartReconciler) requestsForGitRepositoryChange(o client.Object) []
866866
if !ok {
867867
panic(fmt.Sprintf("Expected a GitRepository, got %T", o))
868868
}
869+
869870
// If we do not have an artifact, we have no requests to make
870871
if repo.GetArtifact() == nil {
871872
return nil
872873
}
873874

874875
var list sourcev1.HelmChartList
875876
if err := r.List(context.TODO(), &list, client.MatchingFields{
876-
sourcev1.GitRepositoryIndexKey: util.ObjectKey(o).String(),
877+
sourcev1.SourceIndexKey: fmt.Sprintf("%s/%s", sourcev1.GitRepositoryKind, repo.Name),
877878
}); err != nil {
878879
return nil
879880
}
@@ -902,7 +903,7 @@ func (r *HelmChartReconciler) requestsForBucketChange(o client.Object) []reconci
902903

903904
var list sourcev1.HelmChartList
904905
if err := r.List(context.TODO(), &list, client.MatchingFields{
905-
sourcev1.BucketIndexKey: util.ObjectKey(o).String(),
906+
sourcev1.SourceIndexKey: fmt.Sprintf("%s/%s", sourcev1.BucketKind, bucket.Name),
906907
}); err != nil {
907908
return nil
908909
}

0 commit comments

Comments
 (0)