-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check ignore matches before Bucket item downloads #337
Conversation
Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit makes the filtering applied during the archiving configurable by introducing an optional `ArchiveFileFilter` callback argument and a `SourceIgnoreFilter` implementation. `SourceIgnoreFilter` filters out files matching sourceignore.VCSPatterns and any of the provided patterns. If an empty gitignore.Pattern slice is given, the matcher is set to sourceignore.NewDefaultMatcher. The `GitRepository` now loads the ignore patterns before archiving the repository contents by calling `sourceignore.LoadIgnorePatterns` and other helpers. The loading behavior is **breaking** as `.sourceignore` files in the (subdirectories of the) repository are now still taken into account if `spec.ignore` for a resource is defined, overwriting is still possible by creating an overwriting rule in the `spec.ignore` of the resource. This change also makes it possible for the `BucketReconciler` to not configure a callback at all and prevent looking for ignore matches twice. To finalize the bucket refactor, a change to the reconciler has been made to look for a `.sourceignore` file in the root of the bucket to provide an additional way of configuring (global) exclusions. Signed-off-by: Hidde Beydals <hello@hidde.co>
376f72a
to
101814d
Compare
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.
Shaping up well I reckon!
return func(p string, fi os.FileInfo) bool { | ||
// The directory is always false as the archiver does already skip | ||
// directories. | ||
return matcher.Match(strings.Split(p, string(filepath.Separator)), false) |
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.
Would https://pkg.go.dev/path/filepath@go1.16.2#SplitList work here?
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 somehow went looking for this method but could not find it :-S. Thanks!
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.
Or no, it was not. I came across this method as well but it splits them by filepath.ListSeparator
, resulting in e.g. [/a/b/c, /d/f/g]
instead of the [a, b, c]
we are after for the domain
.
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.
Curses! I have made exactly this mistake three or four times now aaaaa
This commit updates Go to 1.16, a required change because of the use of `os.WriteFile` in one of the tests introduced by commit b5004a9. Normally _just_ this would not justify the change, but given the introduction of breaking changes (and thereby forcing a MINOR update anyway), and the various file{system, path} improvements introduced in Go 1.16 like [`filepath#WalkDir`](https://golang.org/pkg/path/filepath/#WalkDir), going ahead with this should be fine. Signed-off-by: Hidde Beydals <hello@hidde.co>
101814d
to
d3bcc6a
Compare
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.
LGTM
Thanks @hiddeco ☕
Fixes #333
This PR makes the
BucketReconciler
more efficient by looking forexclusions while downloading files, instead of during the archiving of
the downloaded contents.
It also makes the filtering applied during the archiving
configurable by introducing an optional
ArchiveFileFilter
callback argument and a
SourceIgnoreFilter
implementation.SourceIgnoreFilter
filters out files matchingsourceignore.VCSPatterns and any of the provided patterns.
If an empty gitignore.Pattern slice is given, the matcher is set to
sourceignore.NewDefaultMatcher.
The
GitRepositoryReconciler
now loads the ignore patternsbefore archiving the repository contents by calling
sourceignore.LoadIgnorePatterns
and other helpers. The loadingbehavior is breaking as
.sourceignore
files in the (subdirectories of the)repository are now still taken into account if
spec.ignore
for a resourceis defined, overwriting is still possible by creating an overwriting rule
in the
spec.ignore
of the resource.