Commit Graph

47 Commits

Author SHA1 Message Date
Kevin McDermott f7105ea736 Implement Size field on archived artifacts
This adds a Size field to Artifacts, which reflects the number of bytes
written to the artifact when it's being archived.

Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
2022-02-28 16:01:34 +01:00
Sunny 9b5613732f storage: Return details about the deleted items
Update Storage.RemoveAll() and Storage.RemoveAllButCurrent() to return
the details about the deleted items. This helps emit useful information
about garbage collection in the controllers and ignore no-op garbage
collections.

RemoveAll() returns the path of the deleted directory if any.
RemoveAllButCurrent() returns a slice of path of all the deleted items
from a resource's artifact dir.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-02-23 12:35:30 +01:00
Hidde Beydals 349739b7e4 Implement new runtime interfaces, prepare testenv
This commit ensures all API objects implement the interfaces used by
the runtime package to work with conditions, etc., and prepares the
test suite to work with the `pkg/runtime/testenv` wrapper.

Changes are made in a backwards compatible way (that being: the
existing code can still be build and works as expected), but without
proper dependency boundaries. The result of this is that the API
package temporary depends on the runtime package, which is resolved
when all reconcilers have been refactored and the API package does
no longer contain condition modifying functions.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-02-23 12:35:30 +01:00
Hidde Beydals 7c3c14997e Switch to v1beta2 API package
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-02-23 12:35:25 +01:00
Kevin McDermott c397ff902b Ensure that directories are included.
This avoids skipping the directories when generating the archive
tarball.

This makes it easier to scan directory trees.

Signed-off-by: Kevin McDermott <kevin@weave.works>

Ensure that directories are included.

This avoids skipping the directories when generating the archive
tarball.

This makes it easier to scan directory trees.

Signed-off-by: Kevin McDermott <kevin@weave.works>
2022-01-20 13:58:44 +00:00
Tom Huang 5bb428349e
proper file close operation based on feedback
Signed-off-by: Tom Huang <tom.huang@weave.works>
2022-01-11 15:50:25 -05:00
Tom Huang 8868d3938a
Update file close operation to not use defer and add test case for CopyFromPath
Signed-off-by: Tom Huang <tom.huang@weave.works>
2022-01-11 13:23:17 -05:00
Hidde Beydals fb688ffe8a
storage: change Artifact checksum to SHA256
This changes the format of the Artifact checksum from SHA1 to SHA256 to
mitigate chosen-prefix and length extension attacks, and ensures it can
be used to secure content against malicious modifications.

Source consumers (including our own {kustomize,helm}-controllers)
should ensure the SHA256 of a downloaded artifact matches the
advertised checksum before making use of it.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-11-11 22:47:49 +01:00
Hidde Beydals 3ac39b6137 storage: strip env specific data during archive
This ensures the checksum is predictable, and not influenced by e.g.
different runtime configuration settings, or FS specific data.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-08-05 12:42:40 +02:00
Hidde Beydals 77d1c9ccba Ensure rel path never traverses outside Storage
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-08-05 12:40:21 +02:00
Hidde Beydals c4d7e46b90 Drop deprecated `io/ioutil`
The package has been deprecated since Go 1.16, see:
https://golang.org/doc/go1.16#ioutil

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-07-29 09:58:00 +02:00
Stefan Prodan add5444f16
Fix GitRepository include for nested paths
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-05-28 01:17:40 +03:00
Philip Laine fcf7048992 Add include property to GitRepositories
Signed-off-by: Philip Laine <philip.laine@gmail.com>
Signed-off-by: Philip Laine <philip.laine@xenit.se>
2021-05-11 09:46:50 +02:00
Hidde Beydals b5004a93bc Make Storage#Archive file filtering configurable
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>
2021-04-13 15:34:20 +02:00
Hidde Beydals cca2c4a362 Check ignore matches before Bucket item downloads
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-04-13 15:34:20 +02:00
Stefan Prodan 9a08c0cc52
Add well-known CI configs to exclusion list
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-03-31 14:39:12 +03:00
Hidde Beydals 582c2092b6 Change copyright to Flux authors
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-10-27 17:54:22 +01:00
stefanprodan f16e5f041a Promote API to v1beta1 2020-09-30 16:11:00 +03:00
Hidde Beydals 4da80b65e5 storage: add CopyFromPath method 2020-09-21 23:16:13 +02:00
stefanprodan c2c61b10a1 Implement S3 Bucket controller 2020-09-18 16:11:24 +03:00
Hidde Beydals d03f4fa4c4 Change advertised artifact URLs on hostname change 2020-09-10 14:13:46 +02:00
Hidde Beydals 42706a342b Calculate checksums during file writes 2020-09-10 13:00:08 +02:00
Hidde Beydals 1ab12869ac Make storage file writes atomic 2020-09-10 12:02:32 +02:00
Hidde Beydals 68ccf2598f storage: actually record relative path in artifact 2020-09-09 16:32:25 +02:00
Hidde Beydals 99b74da044 api/artifact: add checksum field to artifact
This includes a change to how the revision for HelmRepository sources is
recorded, as this will now equal to the generated timestamp from the index
in RFC3339Nano format.
2020-09-09 13:41:56 +02:00
Hidde Beydals 0b752178b1 storage: only store relative path in artifact
As the storage base directory is determined during runtime, and
artifacts may live longer than that if they are e.g. stored in a
persistent volume but the mount path configuration changes.
2020-09-08 17:21:56 +02:00
Hidde Beydals f8c4bd31ca api/artifact: add ArtifactDir helper func
To make it easier to construct just the directory path for the
artifact (relative to the storage base path).
2020-09-08 15:16:58 +02:00
Hidde Beydals b7603f9fd3 storage: change logic of `ArtifactExist` method
Given that:

* The produced artifact as advertisted in the path should always
  be a regular file (including the exclusion of symlinks).
* The produced artifact should be readable, so any type of error
  should count as "does not exist".

We should use `os.Lstat` to not follow symlinks; return `false`
on any error we run in to, or return if the file mode information
reports a regular file.
2020-09-01 16:01:19 +02:00
Hidde Beydals 24f47ac183 Support Helm charts from GitRepository sources 2020-08-31 16:21:53 +02:00
Erik Hollensbe 687b79a7dd Storage: fix a small bug in RemoveAllButCurrent when the directory is invalid
filepath.Walk can return a `nil` for the stat value, when it does, the
directory is invalid and the error will be set. This causes a
panic+crash if the directory does not currently exist when
RemoveAllButCurrent is called.

The following patch makes the behavior an error instead.

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
2020-07-15 18:50:09 +00:00
stefanprodan b9dc2ecf64 Add ignore field to GitRepository spec 2020-07-09 14:48:02 +03:00
Erik Hollensbe a723b9e3e7 Archive and storage tests
Signed-off-by: Erik Hollensbe <github@hollensbe.org>
2020-07-08 23:23:33 +00:00
Erik Hollensbe b1b1dbcec5 Support programming excluded patterns in gitrepository spec
-- More coming in this commit message soon

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
2020-07-08 14:38:44 +00:00
stefanprodan e92cbbdd45 Migrate to fluxcd/pkg 2020-06-30 17:30:21 +03:00
Hidde Beydals 39ee34897a Replace tar/gzip shell-out with Go implementation 2020-06-06 19:15:52 +02:00
Hidde Beydals 77822bd4d1 controllers: simple GitRepository test 2020-05-29 14:24:31 +02:00
Hidde Beydals e880a45474 controllers: control tar ignores w/ exclude files
This commit changes the file excludes for tarballs generated for
Git repository artifacts from a fixed set of strings to include
exclusion files files. It currently takes `.sourceignore` and
in the root of the given directory into account.

In addition to this the Git VCS related files that are ignored have
been extended to not only include the .git/ directory, but also the
.gitignore, .gitmodules and .gitattributes files. Mimicking part of
the --exclude-vcs flag not available on all tar versions.
2020-05-13 19:45:31 +02:00
stefanprodan 9540efe9de git: add archive integrity check 2020-04-27 13:39:36 +03:00
stefanprodan e88d7219ca Change artifact path format
- move artifact path composition to API
- change path format to `<source-kind>/<source-namespace>/<source-name>/<artifact-filename>`
2020-04-13 19:52:30 +03:00
Hidde Beydals 3e0810aefe Give namespace precedence in calc artifact path 2020-04-12 22:07:57 +02:00
Hidde Beydals 7e99998c5f Factor out injection of kind string in controllers 2020-04-12 22:07:53 +02:00
stefanprodan 2bbcd91544 Add artifact to Git and Helm repos status
- create index.yaml symlink for Helm repos
- set symlink URL in status
2020-04-12 17:39:07 +03:00
stefanprodan 786071fe3c Add symlink helper to storage 2020-04-12 09:56:03 +03:00
stefanprodan d1f76995ab Add ready condition helpers 2020-04-10 22:44:09 +03:00
stefanprodan 98deb3fa54 Add file lock helper to Storage
- use https://github.com/golang/go/tree/master/src/cmd/go/internal/lockedfile
2020-04-10 16:08:05 +03:00
stefanprodan 9dae1c43d7 Use storage helper in HelmRepositoryReconciler
- move checksum and file write operations to Storage
- implement GC
2020-04-10 15:16:31 +03:00
stefanprodan d1fb8e1ade Add storage helpers
- add storage and artifact types
- extract fs operations to storage functions
- construct artifact paths from Kubernetes objects metadata
2020-04-10 11:51:15 +03:00