From a996462048a165e56b53a919a58860d92a3595db Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Thu, 16 Jun 2022 14:09:46 +0100 Subject: [PATCH 1/2] Fix subtest references Subtests are not supposed to use the parent t reference but rather to use their own. This change ensures that is the case. Signed-off-by: Paulo Gomes --- controllers/update_test.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/controllers/update_test.go b/controllers/update_test.go index 2908858b..99952b71 100644 --- a/controllers/update_test.go +++ b/controllers/update_test.go @@ -479,8 +479,10 @@ func TestImageAutomationReconciler_e2e(t *testing.T) { // test cases and cleanup at the end. t.Run("PushSpec", func(t *testing.T) { + g := NewWithT(t) + // Clone the repo locally. - cloneCtx, cancel := context.WithTimeout(ctx, time.Second*10) + cloneCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() localRepo, err := clone(cloneCtx, cloneLocalRepoURL, branch) g.Expect(err).ToNot(HaveOccurred(), "failed to clone git repo") @@ -499,6 +501,8 @@ func TestImageAutomationReconciler_e2e(t *testing.T) { pushBranch := "pr-" + randStringRunes(5) t.Run("update with PushSpec", func(t *testing.T) { + g := NewWithT(t) + preChangeCommitId := commitIdFromBranch(localRepo, branch) commitInRepo(g, cloneLocalRepoURL, branch, "Install setter marker", func(tmp string) { g.Expect(replaceMarker(tmp, policyKey)).To(Succeed()) @@ -536,6 +540,8 @@ func TestImageAutomationReconciler_e2e(t *testing.T) { }) t.Run("push branch gets updated", func(t *testing.T) { + g := NewWithT(t) + initialHead, err := headFromBranch(localRepo, branch) g.Expect(err).ToNot(HaveOccurred()) defer initialHead.Free() @@ -566,6 +572,8 @@ func TestImageAutomationReconciler_e2e(t *testing.T) { }) t.Run("still pushes to the push branch after it's merged", func(t *testing.T) { + g := NewWithT(t) + initialHead, err := headFromBranch(localRepo, branch) g.Expect(err).ToNot(HaveOccurred()) defer initialHead.Free() @@ -610,13 +618,15 @@ func TestImageAutomationReconciler_e2e(t *testing.T) { }) t.Run("with update strategy setters", func(t *testing.T) { + g := NewWithT(t) + // Clone the repo locally. // NOTE: A new localRepo is created here instead of reusing the one // in the previous case due to a bug in some of the git operations // test helper. When switching branches, the localRepo seems to get // stuck in one particular branch. As a workaround, create a // separate localRepo. - cloneCtx, cancel := context.WithTimeout(ctx, time.Second*10) + cloneCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() localRepo, err := clone(cloneCtx, cloneLocalRepoURL, branch) g.Expect(err).ToNot(HaveOccurred(), "failed to clone git repo") @@ -677,6 +687,8 @@ func TestImageAutomationReconciler_e2e(t *testing.T) { }) t.Run("no reconciliation when object is suspended", func(t *testing.T) { + g := NewWithT(t) + err = createImagePolicyWithLatestImage(testEnv, imagePolicyName, namespace, "not-expected-to-exist", "1.x", latestImage) g.Expect(err).ToNot(HaveOccurred(), "failed to create ImagePolicy resource") @@ -863,7 +875,7 @@ func compareRepoWithExpected(g *WithT, repoURL, branch, fixture string, changeFi copy.Copy(fixture, expected) changeFixture(expected) - cloneCtx, cancel := context.WithTimeout(ctx, time.Second*10) + cloneCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() repo, err := clone(cloneCtx, repoURL, branch) g.Expect(err).ToNot(HaveOccurred()) @@ -909,7 +921,7 @@ func configureTransportOptsForRepo(repo *libgit2.Repository) (func(), error) { } func commitInRepo(g *WithT, repoURL, branch, msg string, changeFiles func(path string)) *libgit2.Oid { - cloneCtx, cancel := context.WithTimeout(ctx, time.Second*10) + cloneCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() repo, err := clone(cloneCtx, repoURL, branch) g.Expect(err).ToNot(HaveOccurred()) @@ -1443,7 +1455,7 @@ func testWithCustomRepoAndImagePolicy( // Clone the repo. repoURL := gitServer.HTTPAddressWithCredentials() + repositoryPath - cloneCtx, cancel := context.WithTimeout(ctx, time.Second*10) + cloneCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() localRepo, err := clone(cloneCtx, repoURL, args.branch) g.Expect(err).ToNot(HaveOccurred(), "failed to clone git repo") From ec89ad41b9b7a125b3264734e04f45aaf3d2673e Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Thu, 16 Jun 2022 14:20:12 +0100 Subject: [PATCH 2/2] Update source-controller to v0.25.7 This version of source-controller introduces a fix for the SSH connections leak issue reported at: https://github.com/fluxcd/image-automation-controller/issues/334 Signed-off-by: Paulo Gomes --- api/go.mod | 2 +- api/go.sum | 4 ++-- controllers/suite_test.go | 3 +-- go.mod | 4 ++-- go.sum | 8 ++++---- main.go | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/api/go.mod b/api/go.mod index bf60c046..7049b367 100644 --- a/api/go.mod +++ b/api/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/fluxcd/pkg/apis/meta v0.14.2 - github.com/fluxcd/source-controller/api v0.25.5 + github.com/fluxcd/source-controller/api v0.25.7 k8s.io/apimachinery v0.24.1 sigs.k8s.io/controller-runtime v0.11.2 ) diff --git a/api/go.sum b/api/go.sum index 97ac5ef8..bec3f6c1 100644 --- a/api/go.sum +++ b/api/go.sum @@ -21,8 +21,8 @@ github.com/fluxcd/pkg/apis/acl v0.0.3 h1:Lw0ZHdpnO4G7Zy9KjrzwwBmDZQuy4qEjaU/RvA6 github.com/fluxcd/pkg/apis/acl v0.0.3/go.mod h1:XPts6lRJ9C9fIF9xVWofmQwftvhY25n1ps7W9xw0XLU= github.com/fluxcd/pkg/apis/meta v0.14.2 h1:/Hf7I/Vz01vv3m7Qx7DtQvrzAL1oVt0MJcLb/I1Y1HE= github.com/fluxcd/pkg/apis/meta v0.14.2/go.mod h1:ijZ61VG/8T3U17gj0aFL3fdtZL+mulD6V8VrLLUCAgM= -github.com/fluxcd/source-controller/api v0.25.5 h1:64rLb5cuHhZ3LcRIxkp+/oAVCyVtjOhQ9kbphdFfR/s= -github.com/fluxcd/source-controller/api v0.25.5/go.mod h1:/e7YRDOqb8z8I3N8ifbDF1mknf8zFsoADtS/Q93iWPs= +github.com/fluxcd/source-controller/api v0.25.7 h1:vXGKBTGT9bcx9sRI7MbmaebEeKoq17vQoPI8IOObpXk= +github.com/fluxcd/source-controller/api v0.25.7/go.mod h1:/e7YRDOqb8z8I3N8ifbDF1mknf8zFsoADtS/Q93iWPs= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 7d6a2817..f28695e8 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -24,7 +24,6 @@ import ( "testing" "time" - "github.com/go-logr/logr" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" @@ -63,7 +62,7 @@ func TestMain(m *testing.M) { filepath.Join("testdata", "crds"), )) - managed.InitManagedTransport(logr.Discard()) + managed.InitManagedTransport() controllerName := "image-automation-controller" if err := (&ImageUpdateAutomationReconciler{ diff --git a/go.mod b/go.mod index 72b61b0c..ebe0839d 100644 --- a/go.mod +++ b/go.mod @@ -15,8 +15,8 @@ require ( github.com/fluxcd/pkg/gittestserver v0.5.4 github.com/fluxcd/pkg/runtime v0.16.2 github.com/fluxcd/pkg/ssh v0.5.0 - github.com/fluxcd/source-controller v0.25.5 - github.com/fluxcd/source-controller/api v0.25.5 + github.com/fluxcd/source-controller v0.25.7 + github.com/fluxcd/source-controller/api v0.25.7 github.com/go-logr/logr v1.2.3 github.com/google/go-containerregistry v0.9.0 github.com/libgit2/git2go/v33 v33.0.9 diff --git a/go.sum b/go.sum index 9eda0bc4..3abac595 100644 --- a/go.sum +++ b/go.sum @@ -198,10 +198,10 @@ github.com/fluxcd/pkg/ssh v0.5.0 h1:jE9F2XvUXC2mgseeXMATvO014fLqdB30/VzlPLKsk20= github.com/fluxcd/pkg/ssh v0.5.0/go.mod h1:KGgOUOy1uI6RC6+qxIBLvP1AeOOs/nLB25Ca6TZMIXE= github.com/fluxcd/pkg/version v0.1.0 h1:v+SmCanmCB5Tj2Cx9TXlj+kNRfPGbAvirkeqsp7ZEAQ= github.com/fluxcd/pkg/version v0.1.0/go.mod h1:V7Z/w8dxLQzv0FHqa5ox5TeyOd2zOd49EeuWFgnwyj4= -github.com/fluxcd/source-controller v0.25.5 h1:a96qa3/PQPXZ7OcfLTaDmMKee/Qhxr9G8C21+/MnqhM= -github.com/fluxcd/source-controller v0.25.5/go.mod h1:401D+j+jFZcy9iuH7RrOMbkXJazsQK4Ce5q8pgKaXBI= -github.com/fluxcd/source-controller/api v0.25.5 h1:64rLb5cuHhZ3LcRIxkp+/oAVCyVtjOhQ9kbphdFfR/s= -github.com/fluxcd/source-controller/api v0.25.5/go.mod h1:/e7YRDOqb8z8I3N8ifbDF1mknf8zFsoADtS/Q93iWPs= +github.com/fluxcd/source-controller v0.25.7 h1:gksopk/IVPnL+bkBRwpFnvQUr+72tJvxzJ+D+UZohD4= +github.com/fluxcd/source-controller v0.25.7/go.mod h1:ZUZGoDPpDE8PDamRLbaXcjFfpVGhgu9bAx9sfohLs2k= +github.com/fluxcd/source-controller/api v0.25.7 h1:vXGKBTGT9bcx9sRI7MbmaebEeKoq17vQoPI8IOObpXk= +github.com/fluxcd/source-controller/api v0.25.7/go.mod h1:/e7YRDOqb8z8I3N8ifbDF1mknf8zFsoADtS/Q93iWPs= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= diff --git a/main.go b/main.go index e8d944ba..83c92406 100644 --- a/main.go +++ b/main.go @@ -162,7 +162,7 @@ func main() { // +kubebuilder:scaffold:builder if enabled, _ := features.Enabled(features.GitManagedTransport); enabled { - managed.InitManagedTransport(ctrl.Log.WithName("managed-transport")) + managed.InitManagedTransport() } setupLog.Info("starting manager")