-
Notifications
You must be signed in to change notification settings - Fork 220
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gregsidelinger, I like the idea! cc @andresmgot @absoludity
cmd/chart-repo/utils_test.go
Outdated
filter := new(filters) | ||
filter.Names = append(filter.Names, "wordpress") | ||
filter.Names = append(filter.Names, "not-found") | ||
charts = chartsFromIndex(index, r, filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you run gofmt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/chart-repo/utils_test.go
Outdated
assert.Equal(t, len(charts), 2, "number of charts") | ||
// filter on name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we split this up into sub-tests using t.Run
? (e.g.
monocular/cmd/chartsvc/handler_test.go
Line 73 in 4043fe3
t.Run(tt.name, func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I broke them out into separate tests but did not use a loop using r.Run
cmd/chart-repo/utils_test.go
Outdated
filter.Annotations["sync"] = "true" | ||
filter.Annotations["not-found"] = "missing" | ||
filter.Annotations["no-value"] = "" | ||
assert.Equal(t, len(charts), 1, "number of charts") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what chart does this test pick up? I can't see any annotations in https://github.com/helm/monocular/blob/master/cmd/chart-repo/testdata/valid-index.yaml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I was doing some cleanup and the updated test yam l did got get committed. It will be there in the next push.
Nice. Yes storing extra data for charts when they are synced, and being able to query based on that data is also something we're needing in Kubeapps (though we're now using a different codebase for sync which supports postgresql as a backend). |
cmd/chart-repo/utils.go
Outdated
if v, ok := entry[0].Annotations[a]; ok { | ||
if len(av) == 0 { | ||
charts = append(charts, newChart(entry, r)) | ||
continue ENTRYLOOP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can avoid this and improve the readability here by splitting out these filters into separate functions. Also, there might be a bug here. What if I have a name filter and an annotation filter, only the annotation filter will hold?
Something like:
if !matchesAnnotationsFilter(filter.Annotations, entry) || !matchesNamesFilter(filter.Names, entry) {
// log skipping chart
continue
}
charts = append(charts, newChart(entry, r))
Those functions can return true if filter.Annotations or filter.Names is empty.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I was thinking the same thing when using the ENTRYLOOP label but was being lazy. Since my intention was to sync if any of the filters matched I did a single function that returns true if a filter matched.
filter.Annotations["sync-by-name-only"] = "" | ||
charts := chartsFromIndex(index, r, filter) | ||
assert.Equal(t, len(charts), 1, "number of charts") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a test for both an annotation and name filter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
filter := new(filters) | ||
filter.Annotations = make(map[string]string) | ||
filter.Annotations["sync"] = "true" | ||
filter.Annotations["not-found"] = "missing" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the expectation here that it only needs to match one of the annotations and not all of the annotations? I would have assumed that all the annotations need to match for the entry to be selected (I believe this is also how kubectl
label filters work).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point I did not think about that. My intend was if any of them matched it synced. That is actually how I just rewrote the code as a function.
// return true if entry matches any filter
func filterEntry( entry *helmrepo.ChartVersion, filter *filters) bool {
cmd/chart-repo/utils_test.go
Outdated
filter.Annotations = make(map[string]string) | ||
filter.Annotations["sync"] = "true" | ||
filter.Annotations["not-found"] = "missing" | ||
filter.Annotations["sync-by-name-only"] = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not testing the same thing as Test_chartsFromIndexFilterByAnnotationDuplicateMatches
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, filter.Annotations["sync-by-name-only"] = ""
should not be there, too much copy and pasting.
cmd/chart-repo/utils.go
Outdated
if len(filter.Annotations) > 0 || | ||
len(filter.Names) > 0 { | ||
if filterEntry(entry[0], filter){ | ||
charts = append(charts, newChart(entry, r)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: it might be simpler to flip this condition and continue if it enters it, and just fallback to the append on line 291 if it matches the filter. i.e. similar to the deprecation condition above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I ended up adding more test data to valid-index.yaml as I removed the ! from if !filterEntry(entry[0], filter)
to make the test fail and realized with only two charts of data the test would pass no mater what when filtering.
cmd/chart-repo/utils.go
Outdated
if filterEntry(entry[0], filter){ | ||
charts = append(charts, newChart(entry, r)) | ||
} | ||
log.WithFields(log.Fields{"name": entry[0].GetName()}).Info("skipping chart as filters did not match") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need to be in an else block?
Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
Add filter on annoation name only Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
Updating filter tests Signed-off-by: Greg Sidelinger <sidelig@nationwide.com> Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
Co-Authored-By: Adnan Abdulhussein <adnan@prydoni.us> Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
Co-Authored-By: Adnan Abdulhussein <adnan@prydoni.us> Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
Adding more test data Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
b608901
to
c95b4f0
Compare
Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the delay - I was on holiday.
This looks great, can you just run gofmt one more time to ensure it's all properly formatted?
gofmt looks happy on my end. |
Thanks! |
@andresmgot do you want to create a new Monocular release with this change? |
sure, thanks for the review! |
Signed-off-by: Greg Sidelinger gate@ilive4code.net
Here are my basic filter changes mentioned in #657