Skip to content

Commit

Permalink
fix: forward context in common's notification pkg (#956)
Browse files Browse the repository at this point in the history
* fix: forward context in controllers

forwarding ctx as per changes in

Signed-off-by: Francesco Ilario <filario@redhat.com>

* Add ref to filariow/toolchain-common

Signed-off-by: Francesco Ilario <filario@redhat.com>

* Remove replace rule, and update toolchain-common

Signed-off-by: Francesco Ilario <filario@redhat.com>

---------

Signed-off-by: Francesco Ilario <filario@redhat.com>
Co-authored-by: Matous Jobanek <mjobanek@redhat.com>
  • Loading branch information
filariow and MatousJobanek authored Jan 26, 2024
1 parent 06bced6 commit 06236eb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion controllers/masteruserrecord/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions controllers/notification/notification_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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"))}
Expand Down Expand Up @@ -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"))}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion controllers/toolchainstatus/toolchainstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions controllers/usersignup/usersignup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down

0 comments on commit 06236eb

Please sign in to comment.