From 06236ebe82a9d4150226ac179b1f4bbdc1a0324f Mon Sep 17 00:00:00 2001 From: Francesco Ilario Date: Fri, 26 Jan 2024 21:27:44 +0100 Subject: [PATCH] fix: forward context in common's notification pkg (#956) * fix: forward context in controllers forwarding ctx as per changes in Signed-off-by: Francesco Ilario * Add ref to filariow/toolchain-common Signed-off-by: Francesco Ilario * Remove replace rule, and update toolchain-common Signed-off-by: Francesco Ilario --------- Signed-off-by: Francesco Ilario Co-authored-by: Matous Jobanek --- controllers/masteruserrecord/sync.go | 2 +- .../notification/notification_controller_test.go | 14 +++++++------- .../toolchainstatus/toolchainstatus_controller.go | 2 +- controllers/usersignup/usersignup_controller.go | 4 ++-- go.mod | 2 +- go.sum | 6 ++++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/controllers/masteruserrecord/sync.go b/controllers/masteruserrecord/sync.go index 055761a7e..8a54d0f60 100644 --- a/controllers/masteruserrecord/sync.go +++ b/controllers/masteruserrecord/sync.go @@ -244,7 +244,7 @@ func alignReadiness(ctx context.Context, scheme *runtime.Scheme, hostClient runt WithTemplate(notificationtemplates.UserProvisionedTemplateName). WithUserContext(userSignup). WithKeysAndValues(keysAndVals). - Create(userSignup.Spec.IdentityClaims.Email) + Create(ctx, userSignup.Spec.IdentityClaims.Email) if err != nil { return false, err diff --git a/controllers/notification/notification_controller_test.go b/controllers/notification/notification_controller_test.go index 731fc0c40..6962d3646 100644 --- a/controllers/notification/notification_controller_test.go +++ b/controllers/notification/notification_controller_test.go @@ -50,7 +50,7 @@ func TestNotificationSuccess(t *testing.T) { ds, _ := mockDeliveryService(defaultTemplateLoader()) controller, cl := newController(t, ds, toolchainConfig) - notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs).Create("jane@acme.com") + notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs).Create(context.TODO(), "jane@acme.com") require.NoError(t, err) notification.Status.Conditions = []toolchainv1alpha1.Condition{sentCond()} require.NoError(t, cl.Update(context.TODO(), notification)) @@ -72,7 +72,7 @@ func TestNotificationSuccess(t *testing.T) { ds, _ := mockDeliveryService(defaultTemplateLoader()) controller, cl := newController(t, ds, toolchainConfig) - notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs).Create("jane@acme.com") + notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs).Create(context.TODO(), "jane@acme.com") require.NoError(t, err) notification.Status.Conditions = []toolchainv1alpha1.Condition{sentCond()} notification.Status.Conditions[0].LastTransitionTime = metav1.Time{Time: time.Now().Add(-cast.ToDuration("10s"))} @@ -101,7 +101,7 @@ func TestNotificationSentFailure(t *testing.T) { notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs). WithSubjectAndContent("test", "test content"). - Create("abc123@acme.com") + Create(context.TODO(), "abc123@acme.com") require.NoError(t, err) notification.Status.Conditions = []toolchainv1alpha1.Condition{sentCond()} notification.Status.Conditions[0].LastTransitionTime = metav1.Time{Time: time.Now().Add(-cast.ToDuration("10s"))} @@ -148,7 +148,7 @@ func TestNotificationDelivery(t *testing.T) { notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs). WithUserContext(userSignup). WithSubjectAndContent("foo", "test content"). - Create("foo@redhat.com") + Create(context.TODO(), "foo@redhat.com") require.NoError(t, err) // when @@ -195,7 +195,7 @@ func TestNotificationDelivery(t *testing.T) { notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs). WithSubjectAndContent("Alert", "Something bad happened"). - Create("sandbox-admin@developers.redhat.com") + Create(context.TODO(), "sandbox-admin@developers.redhat.com") require.NoError(t, err) // when @@ -256,7 +256,7 @@ func TestNotificationDelivery(t *testing.T) { controller, cl := newController(t, nil, userSignup, toolchainConfig) notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs). - Create("jane@redhat.com") + Create(context.TODO(), "jane@redhat.com") require.NoError(t, err) // when @@ -297,7 +297,7 @@ func TestNotificationDelivery(t *testing.T) { controller, cl := newController(t, mds, userSignup) notification, err := notify.NewNotificationBuilder(cl, test.HostOperatorNs). - Create("foo@redhat.com") + Create(context.TODO(), "foo@redhat.com") require.NoError(t, err) // when diff --git a/controllers/toolchainstatus/toolchainstatus_controller.go b/controllers/toolchainstatus/toolchainstatus_controller.go index 149da5dc4..36cc0e7b2 100644 --- a/controllers/toolchainstatus/toolchainstatus_controller.go +++ b/controllers/toolchainstatus/toolchainstatus_controller.go @@ -533,7 +533,7 @@ func (r *Reconciler) sendToolchainStatusNotification(ctx context.Context, WithName(fmt.Sprintf("toolchainstatus-%s-%s", string(status), tsValue)). WithControllerReference(toolchainStatus, r.Scheme). WithSubjectAndContent(subjectString, contentString). - Create(config.Notifications().AdminEmail()) + Create(ctx, config.Notifications().AdminEmail()) if err != nil { logger.Error(err, fmt.Sprintf("Failed to create toolchain status %s notification resource", status)) diff --git a/controllers/usersignup/usersignup_controller.go b/controllers/usersignup/usersignup_controller.go index 980a98bcd..485284e29 100644 --- a/controllers/usersignup/usersignup_controller.go +++ b/controllers/usersignup/usersignup_controller.go @@ -871,7 +871,7 @@ func (r *Reconciler) sendDeactivatingNotification(ctx context.Context, config to WithControllerReference(userSignup, r.Scheme). WithUserContext(userSignup). WithKeysAndValues(keysAndVals). - Create(userSignup.Spec.IdentityClaims.Email) + Create(ctx, userSignup.Spec.IdentityClaims.Email) logger := log.FromContext(ctx) if err != nil { @@ -907,7 +907,7 @@ func (r *Reconciler) sendDeactivatedNotification(ctx context.Context, config too WithControllerReference(userSignup, r.Scheme). WithUserContext(userSignup). WithKeysAndValues(keysAndVals). - Create(userSignup.Spec.IdentityClaims.Email) + Create(ctx, userSignup.Spec.IdentityClaims.Email) logger := log.FromContext(ctx) if err != nil { diff --git a/go.mod b/go.mod index 31395e439..7405ba568 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/codeready-toolchain/host-operator require ( github.com/codeready-toolchain/api v0.0.0-20240103194050-d5c7803671c1 - github.com/codeready-toolchain/toolchain-common v0.0.0-20240125161658-0594a843cd4e + github.com/codeready-toolchain/toolchain-common v0.0.0-20240126111814-12ab087b62d2 github.com/davecgh/go-spew v1.1.1 // indirect github.com/ghodss/yaml v1.0.0 github.com/go-bindata/go-bindata v3.1.2+incompatible diff --git a/go.sum b/go.sum index 4786a3462..e2a110205 100644 --- a/go.sum +++ b/go.sum @@ -138,8 +138,8 @@ github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoC github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= github.com/codeready-toolchain/api v0.0.0-20240103194050-d5c7803671c1 h1:R+5BmQrz9hBfj6QFL+ojExD6CiZ5EuuVUbeb3pqxdds= github.com/codeready-toolchain/api v0.0.0-20240103194050-d5c7803671c1/go.mod h1:FO7kgXH1x1LqkF327D5a36u0WIrwjVCbeijPkzgwaZc= -github.com/codeready-toolchain/toolchain-common v0.0.0-20240125161658-0594a843cd4e h1:8feOhHhHCTUdtAK3Ykyvat8bq0KFnvlyFbXRI5BMqHE= -github.com/codeready-toolchain/toolchain-common v0.0.0-20240125161658-0594a843cd4e/go.mod h1:1oIpmgqMMIir4IjrVkmBaC3GXsObl0vmOFmnYhpbSAQ= +github.com/codeready-toolchain/toolchain-common v0.0.0-20240126111814-12ab087b62d2 h1:wObz6g5TFOzn7AZF6hsd7vI+GQRytxQcVAL6/DnNex8= +github.com/codeready-toolchain/toolchain-common v0.0.0-20240126111814-12ab087b62d2/go.mod h1:1oIpmgqMMIir4IjrVkmBaC3GXsObl0vmOFmnYhpbSAQ= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= @@ -194,6 +194,8 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/filariow/toolchain-common v0.0.0-20240126090853-36d0b2eb856c h1:c64J9YTrUuZLHJJAED8dUtIDoFTozDSzFDu9vCVGdrg= +github.com/filariow/toolchain-common v0.0.0-20240126090853-36d0b2eb856c/go.mod h1:1oIpmgqMMIir4IjrVkmBaC3GXsObl0vmOFmnYhpbSAQ= 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= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=