Commit Graph

96 Commits

Author SHA1 Message Date
Hidde Beydals dbbef5add8 controllers: use `time.Since`
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-11-23 09:51:44 +01:00
Kingdon Barrett d400c8e9e8 Fix error during public key import
For signed commit verification, this code errors out on line 303:

✗ GitRepository reconciliation failed: ''PGP public keys secret error: expected pointer, but got nil

Pointer was not initialized with a concrete instance of the Secret struct

Signed-off-by: Kingdon Barrett <yebyen@gmail.com>
2021-10-29 10:54:16 -04:00
Sunny a7f2e870bf transportAuth(): Add checks for invalid transports
Update GitRepositoryReconciler to use a nil authOpts unless it's
configured.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2021-10-27 16:59:26 +05:30
Hidde Beydals b7376ce94c gogit: allow checkout of commit without branch
This commit changes the `gogit` behavior for commit checkouts,
now allowing one to reference to just a commit while omitting any
branch reference. Doing this creates an Artifact with a
`HEAD/<commit>` revision.

If both a `branch` and `commit` are defined, the commit is expected
to exist within the branch. This results in a more efficient clone
of just the target branch, and also makes this change backwards
compatible.

Fixes #407
Fixes #315

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-10-27 00:43:31 +05:30
Hidde Beydals 5a1fcc213b git: standardise commit and (PGP) verification
This commit refactors the previous `Commit` interface into a
standardised `Commit` struct. This object contains sufficient
information for referencing, observating and (PGP) verification.

- `libgit2` commit checkout does now return `HEAD/<SHA1>` as
  the branch is not taken into account.
- `git2go` objects are now properly `Free`d everywhere
- `Verify` logic is tested.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-10-27 00:43:31 +05:30
Hidde Beydals 0cf0d4e756 git: refactor AuthStrategy into AuthOptions
This commit moves the previous `AuthStrategy` wiring to a more generic
`AuthOptions`, breaking free from implementation specific details in
the `git` package.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-10-27 00:43:31 +05:30
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 b8128cf58b
Reinstate Git cloning timeout
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-06-02 14:21:29 +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 8c27e0ad5a Configure ignore domain for GitRepository rules
Unlike Bucket resources which are matched by key as presented by S3,
ignore rules for GitRepository objects do have a domain: the temporary
directory of the Git repository.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-04-23 11:01:15 +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
Stefan Prodan 664a568822
Add support for Git submodules with go-git
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-03-30 13:00:13 +03:00
Somtochi Onyekwere 2624ba93a3 Record suspension metric
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2021-03-17 14:04:21 +01:00
Hidde Beydals fac1afa2a8 Move `git/common` to `git`
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-02-08 14:05:05 +01:00
Hidde Beydals 566ce8aa15 Upgrade runtime package to v0.6.2
To include a bug fix to the `ReconcilateAtChangedPredicate`
and renaming to `ReconcileRequestedPredicate`.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-01-14 11:39:47 +01:00
Hidde Beydals fda481efe9 Upgrade controller-runtime to v0.7.0
This commit upgrades the `controller-runtime` dependency to `v0.7.0`,
including all changes required to make all wiring work again.

- Upgrade `runtime` to v0.6.0 to include `controller-runtime` changes.
- Loggers have been removed from the reconcilers and are now retrieved
  from the `context.Context` passed to the `Reconcile` method and
  downwards functions.
- Logger configuration flags are now bound to the flag set using
  `BindFlags` from `runtime/logger`, ensuring the same contract across
  GitOps Toolkit controllers, and the `--log-json` flag has been
  deprecated in favour of the `--log-encoding=json` default.
- The `ChangePredicate` from `runtime` has changed to a
  `ReconcilateAtChangedPredicate`, and is now chained with the
  `GenerationChangedPredicate` from `controller-runtime` using
  `predicate.Or`.
- Signatures that made use of `runtime.Object` have changed to
  `client.Object`, removing the requirement to e.g. call
  `runtime.Object#Object`.
- The `client.MatchingField` function was deprecated, and has been
  replaced with `client.MatchingFields{}`.
- The `leader-election-role` was changed, as leader election now works
  via the `coordination/v1` API.

Other notable changes:

- `util.ObjectKey` was added to easily construct a `client.ObjectKey` /
  `types.NamespacedName` from a `metav1.Object`.
- The `SourceIndexKey` constant has been split out into
  `{GitRepository,HelmRepository,Bucket}IndexKey` constants.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-12-18 19:17:10 +01:00
Philip Laine 1b4eacc588 Refactor argument name to enable git2go
Signed-off-by: Philip Laine <philip.laine@xenit.se>
2020-12-04 10:07:17 +01:00
Philip Laine 5ff65d7ae7 Add user support to git2go implementation
Signed-off-by: Philip Laine <philip.laine@gmail.com>
2020-12-02 20:18:29 +01:00
Philip Laine 2cb3754953 Add support for gitv2 servers
Signed-off-by: Philip Laine <philip.laine@xenit.se>
2020-12-02 20:18:29 +01:00
Hidde Beydals 67b10aad22 Respect configured user in SSH Git repository URL
We had a hardcoded assumption that the SSH user for a Git repository is
always "git". This is however not true in all scenarios, for example
when one is making use of Gerrit for team code collaboration, as users
there have their own username for (SSH) Git operations.

This commit changes the logic of the auth strategy helpers to:

1. Select the auth strategy based on the protocol of the parsed URL,
   instead of a simple rely on a correct prefix.
2. Use the user information from the parsed URL to configure the user
   for the public key authentication strategy, with a fallback to `git`
   if none is defined.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-30 16:26:23 +01:00
Stefan Prodan 5579dc8c96
Implement source suspension
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-11-26 12:58:00 +02:00
Hidde Beydals 0b4586253c Add LastHandledReconcileAt to source statuses
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-19 13:21:59 +01:00
Aurel Canciu b80f450b68
Switch to new pkg/apis/meta SetResourceCondition
Use SetResourceCondition as a generic method to set conditions for CRs,
implmeneting the ObjectWithStatusConditions interface used as input
type.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-11-19 13:08:33 +02:00
Aurel Canciu 00bb853d0e
Refactor to adopt k8s standardized Condition type
Updates to use metav1.Condition type and removes references for
deprecated corev1.Condition* constants and uses the new k8s api/meta
helpers in place of the old pkg/apis/meta types.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-11-19 13:08:33 +02:00
Hidde Beydals 2f50e3ff59 Make GC behavior depend on deletion timestamp
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-18 23:03:44 +01:00
Hidde Beydals 93d1559b50 Prevent GC from wiping artifacts in the same NS
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-18 22:56:08 +01:00
Stefan Prodan 81d3ecf612
Patch status sub-resource
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-11-12 17:02:39 +02:00
Stefan Prodan 08d98ff214
Add finalizers to RBAC
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-10-28 14:39:53 +02: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
Hidde Beydals 504ae25954 Switch to controller-runtime utils for finalizers 2020-10-21 11:50:13 +02:00
Stefan Prodan 03e32491bf
Implement Prometheus instrumentation
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-10-13 13:59:30 +03:00
Stefan Prodan c8c2eec3a6
Update fluxcd/pkg/runtime to v0.1.0
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-10-13 13:34:47 +03:00
stefanprodan f16e5f041a Promote API to v1beta1 2020-09-30 16:11:00 +03:00
Hidde Beydals 431ea05427 Implement `fluxcd/pkg/meta/api` in APIs 2020-09-30 10:18:43 +02:00
Hidde Beydals b9576d56f1 Prevent resources getting stuck on transient err
This commit ensures that resources will only return early if they are
already in a `Ready==True` state. If not, but the status object somehow
still reports that it has an artifact, the reconciliation will continue
to ensure and/or guarantee state, and to prevent a deadlock from
happening.
2020-09-22 17:00:54 +02:00
Hidde Beydals 270b6a5c0c api: add HasRevision method to Artifact 2020-09-21 22:41:51 +02:00
stefanprodan c2c61b10a1 Implement S3 Bucket controller 2020-09-18 16:11:24 +03:00
Hidde Beydals f40a42115b Conditionally remove artifact from source status
We only want to remove it if it is no longer in storage, otherwise we
still want to keep it around till we have a new artifact.
2020-09-11 10:10:47 +02:00
Hidde Beydals b5d869db03 Include PATCH rule for events in manager-role
During high custom resource count / low interval tests, I was greated
with a `cannot patch resource "events"` message. This happened due to
event compaction, where it will perform a patch instead of a create.
By giving the role the permission to do so this should no longer pose
a problem.
2020-09-10 21:17:10 +02:00
Hidde Beydals d03f4fa4c4 Change advertised artifact URLs on hostname change 2020-09-10 14:13:46 +02:00
Hidde Beydals 7a3a5938d3 Mark resources as progressing on spec changes 2020-09-10 14:13:41 +02:00
Hidde Beydals 42706a342b Calculate checksums during file writes 2020-09-10 13:00:08 +02:00
Michael Bridgen 901463eaaa Use pkg/runtime for predicate and logger 2020-09-09 17:57:16 +01:00
Hidde Beydals 68947cfca6 controllers: resolve issue with gc on delete
When a delete of a resource is requested a `deletionTimestamp` is set
on the resource by the requester, this also results in a generation
change of the resource.

If the resource is under reconciliation while this timestamp is set, and
had not produced an artifact earlier on, this becomes a problem as the
artifact metadata is used to determine what should be garbage collected
on a deletion, resulting in stray files for resources that are no longer
present.

To resolve this for now, we always create a new artifact object for the
resource when `all==true` on the GC method call, and no longer rely on
the presence of the artifact object on the resource itself.
2020-09-09 13:41:56 +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 8e1b213da5 Change CRD domain to 'source.toolkit.fluxcd.io'
Due to required domain changes for the helm-controller so that it
can co-exist in a cluster with the Helm Operator, other Toolkit
components are moving to a *.toolklit.fluxcd.io domain too.
2020-07-30 21:50:46 +02:00
stefanprodan e65e2f0623 Make git package public 2020-07-20 13:10:18 +03:00
Hidde Beydals e72855f88d Refactor garbage collectors to finalizers 2020-07-16 14:18:33 +02:00
stefanprodan eb20a8f465 Improve error handling and reporting
- return reconciliation error so that controller runtime metrics record failures
- change structure logging labels to match the controller runtime format
- log the reconciliation duration for all kinds
- normalise log messages and labels across all controllers
2020-07-15 12:24:11 +03: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