Commit Graph

1395 Commits

Author SHA1 Message Date
Sunny f2e55059a2
gitrepo: Handle no-op failure recovery notification
Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-18 13:58:47 +05:30
Sunny 09db10ad73
Reintroduce reconcile skip
Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-17 17:59:59 +05:30
Sunny 71d3870e0a
Avoid skipping reconciliation
- Attempt short-circuiting clone only when the artifact is already in the
  storage.
- A successful no-op clone need not return an error, but a partial
  commit which contains only a hash + reference.
- On no-op clone, reconcileSource() populates the source build dir by
  copying the existing artifact and lets the reconciliation continue.
- Reconciliation is not skipped to allow other subreconcilers to operate
  on other parts of GitRepo object like include, ignore, etc, when
  attributes associated with them change but the remote repo has not
  changed.
- Add a function IsConcreteCommit() to differentiate between partial and
  concrete commit.
- Update and simplify go-git and libgit2 no-op clone tests.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-16 17:06:44 +05:30
Sunny aea21cdde7
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-13 20:41:20 +05:30
Sunny 29bc08f547
gogit: error message typo fix
Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-13 18:29:39 +05:30
Sunny 2803a8684b
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-13 18:29:31 +05:30
Sunny efafedd5a7
Introduce Generic error in reconcile
Add Generic error in RuntimeResultBuilder and ComputeReconcileResult
implementation with consideration to the error configurations.

Safeguards are added in the runtime result builder to ensure default
requeue after interval is set when is's set to zero or unset.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-13 18:29:09 +05:30
Sunny 9241218484
Introduce ErrorActionHandler ResultProcessor
ErrorActionHandler processes the reconciliation error results based on
their configurations. It performs actions like logging and event
recording based on the error configuration. More actions can be
accommodated in the future with more error configurations.

It can be a replacement for RecordContextualError() which does the same
operations but can't be configured much.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-13 16:10:29 +05:30
Sunny 0a29e3e44e
Introduce Generic error and error Config
Generic error is an attempt to avoid creating new error type for every
new unique scenario. It can be used to configure and build custom error
handling behavior, logging and event recording at present.
Contextual errors, Stalling and Waiting error, have special meaning for
the reconciliation results. But the Event error type can be replaced
with Generic error with some specific configurations. The Event error
is kept for a gradual migation to Generic error. Similarly, the Generic
error can be used to easily create new error handling behaviors.

The error Config can be used to configure any of the errors, including
contextual errors, without altering their contextual meaning, to modify
how they are handled.

The error constructors configure the errors with common default
configurations. These configurations can be modified to alter the
behavior.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-05-13 16:10:17 +05:30
Paulo Gomes e180b3c944
Merge pull request #713 from pjbgf/libgit2-cacheless-conns
libgit2: Disable connection caching
2022-05-13 11:23:15 +01:00
Paulo Gomes ce92881013
libgit2: remove connection caching
Connection caching was a feature created to resolve
upstream issues raised from concurrent ssh connections.
Some scenarios were based on multiple key exchange
operations happening at the same time.

This PR removes the connection caching, and instead:
- Services Session.StdoutPipe() as soon as possible,
  as it is a known source of blocking SSH connections.
- Reuse SSH connection within the same subtransport,
  eliminating the need for new handshakes when talking
  with the same server.
- Simplifies the entire transport logic for better
  maintainability.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-13 11:09:02 +01:00
Paulo Gomes 9c1bbc45eb
Merge pull request #665 from pjbgf/optimise-clone
Optimise clone operations
2022-05-11 16:59:56 +01:00
Paulo Gomes 7f315f9807
gogit: use rem.ListContext instead of rem.List
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-11 16:36:55 +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 90ef278797
libgit2: return func to help callers free git2go objects
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-11 13:02:27 +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
Paulo Gomes 44e166e576
libgit2: dispose git2go objects when error != nil
getBlankRepoAndRemote's callers are responsible for the disposal
of the returned objects. However, the caller does not expect to
need to dispose objects when err != nil, which may result to memory
leaks.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-11 11:40:09 +01:00
Paulo Gomes 54e07d8783
libgit2: recover from panic in short-circuited clones
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-11 11:40:08 +01:00
Somtochi Onyekwere 2bb3a1fea9
Implements no-op before CheckoutTag in gogit
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2022-05-11 11:40:07 +01:00
Somtochiama 8a3df9da42
gogit: check if revision changed before cloning in checkout branch (#694)
* Check if revision has changed in gogit CheckoutBranch

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2022-05-11 11:40:06 +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 5b4750b87d
Merge pull request #715 from pjbgf/minio-region
Remove minio region
2022-05-10 15:41:17 +01:00
Paulo Gomes c666f50424
Remove minio region
Twice recently the minio region seemed to have changed
unsetting it seems to work consistently.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-10 14:28:54 +01:00
Paulo Gomes 39f1c5c217
Merge pull request #711 from pjbgf/add-hostkey-flag
Add new flag `--ssh-hostkey-algos`
2022-05-10 11:57:59 +01:00
Paulo Gomes 9fddf6947b
Add new flag --ssh-hostkey-algos
The new flag allow users to set the list of hostkey algorithms
to use for ssh connections, enabling them to ensure specific
are/aren't used.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-09 16:29:35 +01:00
Paulo Gomes 1a06b7ae49
Merge pull request #575 from pjbgf/fix-push
Ensure git status is checked at the correct time
2022-05-09 16:28:55 +01:00
Paulo Gomes 50cb97f331
Fix make verify failures
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-09 16:16:04 +01:00
Paulo Gomes c936fc145b
Ensure git status is tracked at the correct time
The previous version would verify git status at time of `make verify` execution, but before all its dependencies executed.
If one of the dependencies resulted in a dirty git, the check would still pass.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-09 15:54:55 +01:00
Paulo Gomes 43235df2b8
Merge pull request #708 from pjbgf/algo-tests
Add Git test coverage for supported algorithms
2022-05-09 14:24:03 +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
Paulo Gomes 4e3e62923b
git: Add git.HostKeyAlgos
Enables the setting of HostKey algorithms to be used from
a client perspective. This implementation supports go-git
and libgit2 when in ManagedTransport.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-06 17:58:09 +01:00
Paulo Gomes d425923a54
Merge pull request #707 from pjbgf/libgit2_panic
libgit2: recover from git2go panic
2022-05-06 09:31:53 +01:00
Paulo Gomes d86ea25e87
Fix minio test by changing region to us-west-2
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-06 08:59:56 +01:00
Paulo Gomes c0c5046e5f
libgit2: recover from git2go panic
Some specific scenarios may lead libgit2 or git2go to panic.
Adding a recovery logic, ensures a predictable execution path
for callers, and safeguards the controller's stability.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-05-06 08:39:00 +01:00
Hidde Beydals a952c25967
Merge pull request #706 from fluxcd/release-v0.24.4 2022-05-03 13:53:47 +02:00
Hidde Beydals fb383c9fcd Release v0.24.4
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-05-03 13:15:04 +02:00
Hidde Beydals dbd3113a79
Merge pull request #705 from fluxcd/update-deps
Update dependencies
2022-05-03 12:59:21 +02:00
Hidde Beydals 5b32ef8269 Update dependencies
- github.com/fluxcd/pkg/runtime to v0.14.2
- golang.org/x/crypto to v0.0.0-20220427172511-eb4f295cb31f
- google.golang.org/api to v0.77.0
- k8s.io/api to v0.23.6
- k8s.io/client-go to v0.23.6

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-05-03 12:44:15 +02:00
Hidde Beydals a5e5fe13bd api: update dependencies
- github.com/fluxcd/pkg/apis/meta to v0.13.0
- k8s.io/apimachinery to v0.23.6

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-05-03 12:44:08 +02:00
Stefan Prodan 4e30a4f63e
Merge pull request #703 from fluxcd/target-condition-in-result
summarize: Consider obj status condition in result
2022-05-03 13:26:25 +03:00
Sunny 2240106c8e
summarize: Consider obj status condition in result
SummarizeAndPatch() should also consider the object's status conditions
when computing and returning the runtime results to avoid any
inconsistency in the runtime result and status condition of the object.
When an object's Ready condition is False, the reconciler should retry
unless it's in stalled condition.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2022-04-30 10:12:21 +05:30
Alexander Block 065a760752 docs: Remove all traces of "identity.pub" from docs
"identity.pub" is referenced multiple times in CRDs and docs. This secret
is however never used in any place. Instead, the public key is derived from
the "identity" private key.

This commit/PR removes all traces of "identity.pub" from v1beta2 CRDs and
docs.

Signed-off-by: Alexander Block <ablock84@gmail.com>
2022-04-29 21:17:53 +02:00
Max Jonas Werner 1e83f0ecf5 fix API docs link
v0.3.0 of gen-crd-api-reference-docs has a bug that leads to it
rendering incorrect links for local types. This is fixed on the master
branch but not released, yet, so I'm pinning the version of the tool
to the latest current commit.

Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-04-29 19:27:53 +02:00
Hidde Beydals 89a4e52fe3
Merge pull request #701 from Juneezee/test/t.TempDir 2022-04-29 17:39:23 +02: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
Hidde Beydals bc5a47e821
Merge pull request #695 from fluxcd/release-v0.24.3 2022-04-28 09:43:25 +02:00
Hidde Beydals 57e7c79098 Release v0.24.3
Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-04-28 09:11:42 +02:00
Max Jonas Werner 9c6a6d91e8 build: let users pass test flags to `make test`
This comes in handy e.g. to only run a single test during development.

Signed-off-by: Max Jonas Werner <mail@makk.es>
2022-04-28 06:31:45 +02:00
Sunny 745d6ee0c5
Merge pull request #691 from fluxcd/cached-helmrepo-diff-checksum
helmrepo: same revision different checksum scenario
2022-04-27 15:28:29 +05:30