Commit Graph

379 Commits

Author SHA1 Message Date
Soule BA fba6477bc3
Merge HelmChart Reconcile tests
If implemented this merges
TestHelmChartReconciler_reconcileFromHelmRepository and
TestHelmChartReconciler_Reconcile

Signed-off-by: Soule BA <soule@weave.works>
2022-07-27 14:06:23 +02:00
York Chen d5a75f6b2f feat: cache helmrepo early after reconcile
1. moved chartRepo.Unload() from reconcileSource() to the defer func in reconcileArtifact to allow caching index in memory
2. added step to init memory cache in reconcileArtifact()
3. added step to save helmrepo index into memory cache in reconcileArtifact()

Signed-off-by: York Chen <ychen@d2iq.com>
2022-07-21 18:17:26 +01:00
Sanskar Jaiswal 0978a7ab61 gitrepo: update reconciler to be injected with transport initialization knowledge
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-07-20 18:56:37 +05:30
Sanskar Jaiswal f5ada743d5 libgit2: decommission unmanaged transport
Decommission libgit2 unmanaged transport and remove the related feature
gate, making managed transport the default.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-07-20 18:56:37 +05:30
Paulo Gomes 9c21f8a7a1
tests: fix error message for invalid x509 in darwin
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-07-14 19:02:45 +01:00
Soule BA f3ab2e0d46
Fix Panic when no artifact in source
If implemented, the helmrepository type will be used to decide whether a
reconciliation can continue in the absence of source artifact, instead
of url.

Signed-off-by: Soule BA <soule@weave.works>
2022-07-14 10:57:22 +02:00
Paulo Gomes 60e46d139c
Decrease fs perms to 0o700
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-07-07 09:57:51 +01:00
Soule BA 361b975bf4
Enable remote dependencies from OCI repositories
If implemented, the source controller will be able to resolve charts
dependencies from OCI repositories.

The remote builder has been refactored as part of this work.

Signed-off-by: Soule BA <soule@weave.works>
2022-07-06 19:11:01 +02:00
Soule BA b402e546bc
Refactor repository logic
Signed-off-by: Soule BA <soule@weave.works>
2022-07-06 19:11:00 +02:00
Sunny e345e71eca
Minor comment updates
- Update the comments around artifact retention fields in Storage.
- Update the comments around reconcileStorage regarding artifact
  retention and garbage collection.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-07-04 19:58:26 +05:30
Paulo Gomes f1799dcb6b
git: fix reconcileSource_authStrategy
Co-authored-by: Sunny <darkowlzz@protonmail.com>
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-06-14 09:25:54 +01:00
Paulo Gomes 42dcb87345
Add reconcileID to all reconcilers
GitRepository introduced correlation ID to improve
transport level logging. This change aligns the other
reconcilers to the same approach.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-06-14 08:59:44 +01:00
Paulo Gomes cea9ea9142
libgit2: improve subtransport logging
Debugging connection issues can be extremely difficult, even more so at scale or when
concurrent connections are required to trigger specific issues.

Changes:
- Add a correlation identifier for each reconciliation, which allows for greater traceability when
going through all the reconciliation operations - including at transport level.
- Add transportType to segregate HTTP and SSH transport logging.
- SSH operations are now enriched with addr containing server address, and HTTP url.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-06-13 07:35:12 +01:00
Sanskar Jaiswal 4ce31319ee libgit2: refactor tests to use managed and unmanaged transport cleanly
Refactors libgit2 checkout tests to test managed and unmanaged
transport by making sure the tests requiring unmanaged transport are run
before, any tests that require managed transport (since disabling
managed transport isn't possible). This is done via arranging the tests
carefully in alphabetically sorted names, i.e. the tests with unmanaged
transport go in `checkout_test.go`, which forces golang to run the tests
in that file before any other tests.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-06-09 21:01:17 +05:30
Soule BA 0d4d78fc6b
Fix repository cache regression
If implemented this make sure we don't unload an index before caching it
during a chart build phase.

Signed-off-by: Soule BA <soule@weave.works>
2022-06-06 13:15:10 +02:00
Stefan Prodan 2441f1f0e9
Log on new artifact and failure recovery
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2022-06-03 15:58:19 +03:00
Sunny 9fe287d912
helmrepo: rm stale condition when type switching
Remove stale condition from HelmRepo during garbage collection when a
type switch to OCI HelmRepo occurs. This ensures the OCI HelmRepo does
not have any conditions from the previous type.

Co-authored-by: Soule BA <soule@weave.works>
Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-31 03:53:33 +05:30
Sunny d22758643b
oci-helmrepo: handle conditions summary in-line
Refactor the OCI HelmRepo reconciler to remove extra custom status
conditions and manage Ready, Reconciling and Stalled conditions within
the reconciler, in-line.
The internal/reconcile/summarize package uses the patch helper
conditions summary before patching which results in overwriting the
Ready condition with Reconciling condition as it's a negative polarity
condition.
For OCI HelmRepository, since it's a simple reconciler, it'd be better
to not introduce extra conditions and utilize the three base conditions
to represent the status. In order to have the same consistent status
conditions, a new summarization is written within the reconciler based
on the context. It takes into consideration a lot of the details from
the internal/reconcile/summarize package and handles certain scenarios
in context specific ways. All the result and error abstractions are
removed since they are only needed when using internal/reconcile
package.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-31 03:53:28 +05:30
Soule BA b98093d0a9
Replace stalling events in HelmChart and HelmRepository_OCI
The setupRegistryServer has been refactored to take into account #690
reviews.

Signed-off-by: Soule BA <soule@weave.works>
2022-05-27 15:35:49 +02:00
Paulo Gomes 978148ea71
libgit2: enforce context timeout
Some scenarios could lead a goroutine to be running indefinetely within managed ssh.
Previously between the two git operations, the reconciliation
could take twice the timeout set for the Flux object.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-27 13:59:50 +01:00
Sanskar Jaiswal 613ccc0ba5 gitrepo: set conditions in gitCheckout
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-05-27 16:05:02 +05:30
Sanskar Jaiswal 972d1cac2a fix docs, error handling and managed proxy auth
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-05-27 14:01:23 +05:30
Sanskar Jaiswal ec45a612b1 enable managed transport for controller tests
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-05-27 14:01:23 +05:30
Sanskar Jaiswal 7d2bc64f47 fix panics on unmanaged http and proxy on managed http
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-05-27 14:01:23 +05:30
Sanskar Jaiswal d4beacb6ad Remove dependency on libgit2 credentials callback
Injects transport and auth options at the transport level directly to
bypass the inbuilt credentials callback because of it's several
shortcomings. Moves some of the pre-existing logic from the reconciler
to the checkout implementation.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-05-27 14:01:23 +05:30
Sunny b70bdce3c1
gitrepo: gitCheckout() return typed errors only
gitCheckout() should return typed errors only. This helps prevent
error type assertions by the caller to determine how to handle the
error. gitCheckout() also sets the appropriate conditions associated
with the error, if any.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-26 00:26:00 +05:30
Paulo Gomes 49232cbd90
Fix tests failing in Ubuntu
Some test cases rely on checksum to match in order to pass.
Those checksums were calculated based on file headers which
contain their file modes.

In Ubuntu, the umask is set to 002 by default, resulting in
the tests files having different permissions then when the
same files are cloned on another Linux machine with umask
set to 022.

This change ensures that the files are always set (to 0644 and
the directories to 0755) before running the aforementioned tests.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-25 11:39:09 +01:00
Sunny b1ae9fcee3
helmrepo: Fix test flake in type update test
In TestHelmRepositoryReconciler_ReconcileTypeUpdatePredicateFilter, when
the type of HelmRepo is updated and immediately checked for the object
to be ready, if the check happens before the client cache is updated, it
results in observing the object to be ready in the previous generation.
This results in status check failure:

```
[Check-FAIL]: [Ready condition must be False when the ObservedGeneration is less than the object Generation, Ready condition must be False when any of the status condition's ObservedGeneration is less than the object Generation: [Ready ArtifactInStorage]]
```

Explicitly look for the object with the next generation to prevent such
failure.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-25 02:53:06 +05:30
Max Jonas Werner 55a594a4e1 introduce eventLogf to HelmRepositoryOCIReconciler; fix formatting
Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-05-24 16:13:42 +02:00
Max Jonas Werner 182e06e8d1 log when the OCI temp credentials file can't be deleted
Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-05-24 16:13:42 +02:00
Max Jonas Werner 09a2458cfd
fix import order
Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-05-24 10:32:42 +02:00
Max Jonas Werner c795da2280
introduce `internal/helm/registry` package
This new package holds all Helm OCI registry-specific code now so we
have a single location to look for such code which makes it easier to
find yourself around.

Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-05-24 10:32:38 +02:00
Max Jonas Werner d5e3c37833
fix code formatting
Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-05-24 10:31:37 +02:00
Max Jonas Werner ce072c7eda
better variable names; improved logging
When setup of one of the two controller reconciling HelmRepositories
fails, it's now possible to judge from the log which setup call failed
by regarding the "type" log field.

Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-05-24 10:31:37 +02:00
Max Jonas Werner bb4d886ba2
dockerconfigjson for OCI registry authentication
`loginOptionFromSecret` now derives username/password from a docker
config stored in Secrets of type "kubernetes.io/dockerconfigjson".

Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-05-24 10:31:37 +02:00
Max Jonas Werner 1070d1287a
fix nil pointer dereference
When the Secret referenced in an OCI HelmRepository doesn't contain a
username and password, the controller doesn't panic, anymore.

Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-05-24 10:31:36 +02:00
Sunny 581695b4d6
gitrepo: Intro contentConfigChecksum & improvement
Introduce contentConfigChecksum in the GitRepository.Status to track the
configurations that affect the content of the artifact. It is used to
detect a change in the configuration that requires rebuilding the whole
artifact. This helps skip the reconciliation early when we find out that
the remote repository has not changed.

Moves fetching the included repositories in reconcileSource() to collect
enough information in reconcileSource() to be able to decide if the full
reconciliation can be skipped. This results in reconcileInclude() to
just copy artifact to the source build directory.

Introduce a gitCheckout() method to perform construction of all the git
checkout options and perform the checkout operation. This helps to
easily perform checkout multiple times when we need it in
reconcileSource(). When we check with the remote repository if there's
an update, and find out that there's no update, we check if any other
configurations that affect the source content has changed, like
includes, ignore rules, etc. If there's a change, we need to perform a
full checkout of the remote repository in order to fetch the complete
source. The git checkout no-op optimization is enabled in this method
based on the presence of an artifact in the storage.

The failure notification handler is modifed to handle the recovery of a
no-op reconcile failure and create a notification message accordingly
with the partial commit.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-20 19:52:18 +05:30
Sunny 5b77f65f46
gitrepo: Enable default feature gates in tests
Introduce a new field in the GitRepositoryReconciler to set the enabled
features. This makes it test friendly compared to using global flags for
setting and checking flags in the tests.

Enable default feature gates in all the GitRepo reconciler tests.

Add test cases for reconcileSource() to test the behavior of optimized
git clone when the Repo is ready and not ready. This ensures that the
full reconciliation is not skipped when GitRepo is not ready.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-20 19:52:18 +05:30
Sunny 4882cea274
Replace Event error with Generic error in GitRepo
For gradual migration to Generic error, update only the GitRepo
reconciler to use Generic error.

Replace the Waiting error for git no change scenario with a Generic
error with proper no-op, early return, error configurations. This
ensures that the no-op only results in log and K8s native events at
normal level.

Fixes a reconciliation issue when recovering from a failure state (with
previous success state and artifact in the storage) and optimized git
clone feature is on, which results in failure to persist as the git
optimization prevented full reconciliation due to already existing
artifact and removal of failure negative conditions on the object
status. In order to allow failure recovery, the git clone optimizations
are now only applied when the object is already in a ready state.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-20 19:52:18 +05:30
Max Jonas Werner 841ed7ae66
[RFC 0002] Flux OCI support for Helm (#690)
* Add OCI Helm support

* users will be able to declare OCI HelmRepository by using the `.spec.type` field of the HelmRepository API. Contrary to the HTTP/S HelmRepository no index.yaml is reconciled from source, instead a simple url and credentials validation is performed.
* For backwards-compatibility, an empty `.spec.type` field leads to the HelmRepository being treated as a plain old HTTP Helm repository.
* users will be able to declare the new OCI HelmRepository type as source using the .Spec.SourceRef field of the HelmChart API. This will result in reconciling a chart from an OCI repository.
* Add registryTestServer in the test suite and OCI HelmRepository test case
* Add a new OCI chart repository type that manage tags and charts from an OCI registry.
* Adapat RemoteBuilder to accept both repository types
* discard output from OCI registry client; The client has no way to set a verbosity level and spamming the controller logs with "Login succeeded" every time the object is reconciled doesn't help much.

Signed-off-by: Soule BA <soule@weave.works>
Signed-off-by: Max Jonas Werner <mail@makk.es>
Co-authored-by: Soule BA <soule@weave.works>
2022-05-19 14:50:16 +02:00
Paulo Gomes 8b50367849
libgit2: Add support for hashed known_hosts
Hashed known_hosts was previously only supported when using
go-git. Now both Git implementations benefit from this
features, and the code coverage across them can ensure no
future regression.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-16 16:57:22 +01:00
Paulo Gomes 262efc08bc
Add git-optimized-clones feature gate
OptimizedGitClones decreases resource utilization for GitRepository
reconciliations. It supports both go-git and libgit2 implementations
when cloning repositories using branches or tags.

This is an opt-out feature, which can be disabled by starting the
controller with the argument '--feature-gates=OptimizedGitClones=false'.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-11 14:39:21 +01:00
Paulo Gomes 87e03431b0
Emit waiting error when no changes occurred since last reconciliation
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-11 11:40:10 +01:00
Sanskar Jaiswal 6a793a55f6
Optimize libgit2 checkout tag strategy through condition no-ops
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-05-11 11:40:05 +01:00
Paulo Gomes 860d7051da
libgit2: optimise checkout branch clones
No-op reconciliations are very inefficient, as they carry out
a full clone operation of the target repository even when
no changes have taken place.

This change will execute a remote-ls operation, and cancel
the clone operation if the remote tip commit is still the same
as the one observed on the last reconcilation. In such cases,
an git.NoChangesError is returned.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-11 11:40:04 +01:00
Paulo Gomes 2b59150fbe
tests: algorithms test coverage for go-git and libgit2
Assures support for:
- Authentication Key Types
  - rsa
  - ecdsa P256
  - ecdsa P384
  - ecdsa P521
  - ed25519
- Key Exchange Algoritms:
  - diffie-hellman-group14-sha1
  - diffie-hellman-group14-sha256
  - curve25519-sha256
  - ecdh-sha2-nistp256
  - ecdh-sha2-nistp384
  - ecdh-sha2-nistp521
  - curve25519-sha256@libssh.org
- HostKey Algoritms:
  - ssh-rsa
  - rsa-sha2-256
  - rsa-sha2-512
  - ecdsa-sha2-nistp256
  - ecdsa-sha2-nistp384
  - ecdsa-sha2-nistp521
  - ssh-ed25519

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-09 13:31:54 +01:00
Eng Zer Jun 10b92da433
test: use `T.TempDir` to create temporary test directory
This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `os.MkdirTemp`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-04-29 23:01:39 +08:00
Sunny eeaa958866
helmrepo: same revision different checksum condn
This change prevents Reconciling and ArtifactOutdated conditions to be
set on HelmRepo when the checksum of a cached repo index changes.

Adds some tests to ensure that when the repo index is cached, the
revision and checksum of the returned artifact are the same as on the
existing object status.
Also adds checks for the returned artifact and chartRepo from
reconcileSource, to ensure that chartRepo is populated and the checksum
of a new potential artifact is always empty, as it's populated when the
artifact is written in the storage.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-04-27 13:03:51 +05:30
Paulo Gomes 009504b294 helm: optimise repository index loading
Avoid validating (and thus loading) indexes if the checksum already exists in storage.
In other words, if the YAML is identical to the Artifact in storage, the reconciliation should
be a no-op, and therefore can short-circuit long/heavy operations.

Co-authored-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-04-25 17:00:27 +02:00
Alexander Block fa09aa2a39 tests: Use proper timeouts in gitrepository and helmrepository tests
I assume using "interval" for timeouts was an accident and "timeout" was
actually meant to be used. This also fixes flakiness of tests.

Signed-off-by: Alexander Block <ablock84@gmail.com>
2022-04-25 14:30:25 +02:00