Commit Graph

102 Commits

Author SHA1 Message Date
Hidde Beydals 49639638b9 Rewrite `HelmRepositoryReconciler` to new standards
This commit rewrites the `HelmRepositoryReconciler` to new standards,
while implementing the newly introduced Condition types, and trying to
adhere better to Kubernetes API conventions.

More specifically it introduces:

- Implementation of more explicit Condition types to highlight
  abnormalities.
- Extensive usage of the `conditions` subpackage from `runtime`.
- Better and more conflict-resilient (status)patching of reconciled
  objects using the `patch` subpackage from runtime.
- Proper implementation of kstatus' `Reconciling` and `Stalled`
  conditions.
- Refactoring of some Helm elements to make them easier to use within
  the new reconciler logic.
- Integration tests that solely rely on `testenv` and do not
  use Ginkgo.

There are a couple of TODOs marked in-code, these are suggestions for
the future and should be non-blocking.
In addition to the TODOs, more complex and/or edge-case test scenarios
may be added as well.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-08-12 11:47:56 +02:00
Stefan Prodan 525be388ec Add ACL optional field to Source API
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-08-12 10:04:35 +02:00
Hidde Beydals 15bc9e71b1 Consolidate condition types into `FetchFailed`
This commit consolidates the `DownloadFailed` and `CheckoutFailed`
Condition types into a new more generic `FetchFailed` type to simplify
the API and observations by consumers.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-08-10 22:15:06 +02:00
Hidde Beydals 588ccbfe99 Rewrite `BucketReconciler` to new standards
This commit rewrites the `BucketReconciler` to new standards, while
implementing the newly introduced Condition types, and trying to
adhere better to Kubernetes API conventions.

More specifically it introduces:

- Implementation of more explicit Condition types to highlight
  abnormalities.
- Extensive usage of the `conditions` subpackage from `runtime`.
- Better and more conflict-resilient (status)patching of reconciled
  objects using the `patch` subpackage from runtime.
- Proper implementation of kstatus' `Reconciling` and `Stalled`
  conditions.
- Refactor of reconciler logic, including more efficient detection of
  changes to bucket objects by making use of the etag data available,
  and downloading of object files in parallel with a limited number of
  workers (4).
- Integration tests that solely rely on `testenv` and do not
  use Ginkgo.

There are a couple of TODOs marked in-code, these are suggestions for
the future and should be non-blocking.
In addition to the TODOs, more complex and/or edge-case test scenarios
may be added as well.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-08-10 22:11:04 +02:00
Hidde Beydals e79b5734ad 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-08-10 10:30:06 +02:00
Hidde Beydals a1ed1fc4b4 source: `GetRequeueAfter` in place of `GetInterval`
The problem with `GetInterval()` was that the returned type was of
`metav1.Duration`, while almost anywhere it was used, a type of
`time.Duration` was requested. The result of this was that we had to
call `GetInterval().Duration` all the time, which would become a bit
cumbersome after awhile.

To prevent this, we introduce a new `GetRequeueAfter() time.Duration`
method, which both results the right type, and bears a name that is
easier to remember where the value is used most; while setting the
`Result.RequeueAfter` during reconcile operations.

The introduced of this method deprecates `GetInterval()`, which should
be removed in a future MINOR release.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-08-03 13:36:12 +02:00
Hidde Beydals 08ce0c95fc Rewrite `GitRepositoryReconciler` to new standards
This commit rewrites the `GitRepositoryReconciler` to new standards,
while implementing the newly introduced Condition types, and trying
to adhere better to Kubernetes API conventions.

More specifically it introduces:

- Implementation of more explicit Condition types to highlight
  abnormalities.
- Extensive usage of the `conditions` subpackage from `runtime`.
- Better and more conflict-resilient (status)patching of reconciled
  objects using the `patch` subpackage from runtime.
- Proper implementation of kstatus' `Reconciling` and `Stalled`
  conditions.
- First (integration) tests that solely rely on `testenv` and do not
  use Ginkgo.

There are a couple of TODOs marked in-code, these are suggestions for
the future and should be non-blocking.
In addition to the TODOs, more complex and/or edge-case test scenarios
may be added as well.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-07-30 19:36:32 +02:00
Hidde Beydals 82583f2247 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>
2021-07-30 12:33:18 +02:00
Hidde Beydals 48ebbcd64e Introduce more explicit Condition types
This commit introduces new Condition types to the v1beta1 API,
facilitating easier observation of (potentially) problematic state for
end-users.

- `ArtifactUnavailableCondition`: indicates there is no artifact
  available for the resource. This Condition should be set by the
  reconciler as soon as it observes the absence of an artifact for a
  source.
- `CheckoutFailedCondition`: indicates a transient or persistent
  checkout failure. This Condition should be set by the reconciler as
  soon as it observes a Git checkout failure, including any
  prerequisites like the unavailability of the referenced Secret used
  for authentication. It should be deleted as soon as a successful
  checkout has been observed again.
- `SourceVerifiedCondition`: indicates the integrity of the source has
  been verified. The Condition should be set to True or False by the
  reconciler based on the result of the integrity check.
  If there is no verification mode and/or secret configured, the
  Condition should be removed.
- `IncludeUnavailableCondition`: indicates one of the referenced
  includes is not available. This Condition should for example be set
  by the reconciler when the include does not exist, or does not have
  an artifact. If the includes become available, it should be deleted.
- `ArtifactOutdatedCondition`: indicates the current artifact of the
  source is outdated. This Condition should for example be set by the
  reconciler when it notices there is a newer revision for an artifact,
  or the previously included artifacts differ from the current available
  ones. The Condition should be removed after writing a new artifact
  to the storage.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-07-30 12:20:26 +02:00
Hidde Beydals 1f27410b34 Update Helm to v3.6.1
v3.6.1 is a a security update from Helm, ensuring that credentials are
always only passed to the defined repository host.

Based on Helm user reports, disabling this behavior may be required for
some Helm repository solutions like Artifactory, and may be done by
setting `PassCredentials` in the `HelmRepositorySpec`.

For more information, see:
https://github.com/helm/helm/security/advisories/GHSA-56hp-xqp3-w2jf

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-06-18 12:31:23 +02:00
Hidde Beydals a76b10cebb Update K8s, controller-runtime and fluxcd/pkg deps
Controller-runtime has been updated to `v0.9.0`, K8s dependencies to
`v0.21.1`, and all `fluxcd/pkg` and other dependencies to the versions
that have matching dependencies and/or build constraints.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-06-08 13:41:34 +02: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
Stefan Prodan cb491c9f10
Update fluxcd/pkg/runtime to v0.11.0
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-04-21 15:04:16 +03:00
Dylan Arbour 4a834e1d2d Add `ValuesFiles` to HelmChart spec
Signed-off-by: Dylan Arbour <arbourd@users.noreply.github.com>
2021-04-19 09:16:53 -04:00
abhinav454 ae24285596 Add shortNames to api resources
Signed-off-by: abhinav454 <43758739+abhinav454@users.noreply.github.com>
2021-04-15 09:03:56 -04:00
Stefan Prodan d7c90a533d
Update Helm to v3.5.4
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-04-15 11:57:01 +03:00
Hidde Beydals d3bcc6a66b Update Go to 1.16
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
b5004a93bc.

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>
2021-04-13 16:35:41 +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
Stefan Prodan 2f04bd3043
Update dependencies
- helm.sh/helm/v3 v3.5.3
- github.com/minio/minio-go/v7 v7.0.10
- sigs.k8s.io/controller-runtime v0.8.3

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-03-12 12:39:23 +02:00
Stefan Prodan 22f5a6f6fb
Update dependencies
- helm.sh/helm/v3 v3.5.2 (forces us into pinning docker)
- sigs.k8s.io/controller-tools/cmd/controller-gen v0.4.1
- sigs.k8s.io/controller-runtime v0.8.2
- fluxcd/pkg/apis/meta v0.8.0
- fluxcd/pkg/runtime v0.8.3

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-02-23 13:18:21 +02:00
Hidde Beydals 7e63ef841c Rename Git packages to implementations
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-02-08 13:55:23 +01:00
Stefan Prodan 207ed99d72
Use LocalObjectReference from fluxcd/pkg/meta v0.7
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-01-21 14:18:42 +02:00
Stefan Prodan 8e3700ebd8
Add QPS/Burst flags using fluxcd/pkg/runtime v0.8
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-01-21 14:13:07 +02:00
Hidde Beydals 34c4290cda Alin HelmChart source indexer and watches
Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-01-18 17:08:25 +01:00
Stefan Prodan ab16dd7c2e
Update Kubernetes and Helm packages
- k8s.io/api v0.20.2
- controller-runtime v0.8.0
- helm v3.5.0

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2021-01-16 14:38:28 +02: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
Hidde Beydals 830b350339 Upgrade dependencies
* `github.com/fluxcd/pkg/apis/meta` to `v0.5.0`
* `github.com/fluxcd/pkg/helmtestserver` to `v0.1.0`
* `github.com/fluxcd/pkg/runtime` to `v0.4.0`
* `helm.sh/helm/v3` to `v3.4.2`
* `k8s.io/{api,apimachinery,client-go}` to `v0.19.4`
* `sigs.k8s.io/controller-runtime` to `v0.6.4`

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-12-09 18:22:27 +01:00
Philip Laine f044ebc253 Rename git2go option to libgit2
Signed-off-by: Philip Laine <philip.laine@xenit.se>
2020-12-06 23:19:57 +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 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 0c904a1879 Watch chart sources for revision changes
To enqueue a new reconciliation for the HelmChart sources as soon as
the revision of their upstream source changes.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-11-26 13:02:55 +01:00
Stefan Prodan 07d09e2c2e
Add suspend field to Source API
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2020-11-26 12:49:12 +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 69f9bbdaa6
Use SetStatusCondition vs FilterOutCondition
Change to rely on the upstream k8s api/meta SetStatusCondition to
set/update the resources status conditions rather than
FilterOutCondition from apis/meta which is due to be removed.

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
Philip Laine 0596513afd Add documentation for kind string constants
Signed-off-by: Philip Laine <philip.laine@xenit.se>
2020-11-02 09:55:39 +01:00
Philip Laine 01d0053871 Fix duration default values
Signed-off-by: Philip Laine <philip.laine@xenit.se>
2020-11-02 09:55:39 +01:00
Philip Laine d67dd6cd58 Set default values in api objects
Signed-off-by: Philip Laine <philip.laine@xenit.se>
2020-11-02 09:55:39 +01:00
Aurel Canciu 60d1dc8219
Update pkg components and k8s to 1.19
Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-11-01 18:11:27 +02:00
Hidde Beydals 54aaef5380
Index HelmRepository resources by their URL
To facilitate an inexpensive lookup when collecting credentials and
index artifacts while working with chart dependencies.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
2020-10-28 14:57:12 +02:00
Hidde Beydals c657e68ba1 Various API doc corrections
Signed-off-by: Hidde Beydals <hello@hidde.co>
2020-10-28 01:09:21 +01: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 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
Hidde Beydals 8cdb821946 docs: document Bucket support HelmChart 2020-09-21 12:40:15 +02:00
Hidde Beydals 03ce9d96da Support Helm charts from Bucket sources 2020-09-21 12:40:15 +02:00
stefanprodan 2ca47fb4ba Guard against missing S3 credentials 2020-09-18 16:11:24 +03:00