-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from appuio/reconcile-fixes
Reconcile even if no `EmailSent` condition can be found
- Loading branch information
Showing
3 changed files
with
66 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ func ControllerCommand() *cobra.Command { | |
invEmailBackend := cmd.Flags().String("email-backend", "stdout", "Backend to use for sending invitation mails (one of stdout, mailgun)") | ||
invEmailSender := cmd.Flags().String("email-sender", "[email protected]", "Sender address for invitation mails") | ||
invEmailSubject := cmd.Flags().String("email-subject", "You have been invited to APPUiO Cloud", "Subject for invitation mails") | ||
invEmailRetryInterval := cmd.Flags().Duration("email-retry-interval", 5*time.Minute, "Retry interval for sending e-mail messages") | ||
invEmailBaseRetryDelay := cmd.Flags().Duration("email-base-retry-interval", 15*time.Second, "Retry interval for sending e-mail messages. There is also an exponential back-off applied by the controller.") | ||
|
||
invEmailMailgunToken := cmd.Flags().String("mailgun-token", "CHANGEME", "Token used to access Mailgun API") | ||
invEmailMailgunDomain := cmd.Flags().String("mailgun-domain", "example.com", "Mailgun Domain to use") | ||
|
@@ -108,7 +108,7 @@ func ControllerCommand() *cobra.Command { | |
*beRefreshJitter, | ||
*invTokenValidFor, | ||
*redeemedInvitationTTL, | ||
*invEmailRetryInterval, | ||
*invEmailBaseRetryDelay, | ||
mailSender, | ||
ctrl.Options{ | ||
Scheme: scheme, | ||
|
@@ -142,7 +142,7 @@ func setupManager( | |
beRefreshJitter, | ||
invTokenValidFor time.Duration, | ||
redeemedInvitationTTL time.Duration, | ||
invEmailRetryInterval time.Duration, | ||
invEmailBaseRetryDelay time.Duration, | ||
mailSender mailsenders.MailSender, | ||
opt ctrl.Options, | ||
) (ctrl.Manager, error) { | ||
|
@@ -219,11 +219,11 @@ func setupManager( | |
return nil, err | ||
} | ||
invmail := &controllers.InvitationEmailReconciler{ | ||
Client: mgr.GetClient(), | ||
Scheme: mgr.GetScheme(), | ||
Recorder: mgr.GetEventRecorderFor("invitation-cleanup-controller"), | ||
RetryInterval: invEmailRetryInterval, | ||
MailSender: mailSender, | ||
Client: mgr.GetClient(), | ||
Scheme: mgr.GetScheme(), | ||
Recorder: mgr.GetEventRecorderFor("invitation-email-controller"), | ||
BaseRetryDelay: invEmailBaseRetryDelay, | ||
MailSender: mailSender, | ||
} | ||
if err = invmail.SetupWithManager(mgr); err != nil { | ||
return nil, err | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,14 +30,7 @@ func (s *SenderWithConstantId) Send(context.Context, string, string, string) (st | |
func Test_InvitationEmailReconciler_Reconcile_Success(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
subject := &userv1.Invitation{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "subject", | ||
}, | ||
Status: userv1.InvitationStatus{ | ||
Token: "abc", | ||
}, | ||
} | ||
subject := baseInvitation() | ||
apimeta.SetStatusCondition(&subject.Status.Conditions, metav1.Condition{ | ||
Type: userv1.ConditionEmailSent, | ||
Status: metav1.ConditionFalse, | ||
|
@@ -58,14 +51,7 @@ func Test_InvitationEmailReconciler_Reconcile_Success(t *testing.T) { | |
func Test_InvitationEmailReconciler_Reconcile_WithSendingFailure_Success(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
subject := &userv1.Invitation{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "subject", | ||
}, | ||
Status: userv1.InvitationStatus{ | ||
Token: "abc", | ||
}, | ||
} | ||
subject := baseInvitation() | ||
apimeta.SetStatusCondition(&subject.Status.Conditions, metav1.Condition{ | ||
Type: userv1.ConditionEmailSent, | ||
Status: metav1.ConditionFalse, | ||
|
@@ -75,26 +61,20 @@ func Test_InvitationEmailReconciler_Reconcile_WithSendingFailure_Success(t *test | |
|
||
r := invitationEmailReconcilerWithFailingSender(c) | ||
_, err := r.Reconcile(ctx, requestFor(subject)) | ||
require.NoError(t, err) | ||
require.Error(t, err) | ||
|
||
require.NoError(t, c.Get(ctx, client.ObjectKeyFromObject(subject), subject)) | ||
require.False(t, apimeta.IsStatusConditionTrue(subject.Status.Conditions, userv1.ConditionEmailSent)) | ||
condition := apimeta.FindStatusCondition(subject.Status.Conditions, userv1.ConditionEmailSent) | ||
require.NotNil(t, condition) | ||
require.Equal(t, "Err0r", condition.Reason) | ||
require.Equal(t, ReasonSendFailed, condition.Reason) | ||
} | ||
|
||
func Test_InvitationEmailReconciler_Reconcile_NoEmail_Success(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
subject := &userv1.Invitation{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "subject", | ||
}, | ||
Status: userv1.InvitationStatus{ | ||
Token: "abc", | ||
}, | ||
} | ||
subject := baseInvitation() | ||
subject.Spec.Email = "" | ||
|
||
c := prepareTest(t, subject) | ||
|
||
|
@@ -108,20 +88,34 @@ func Test_InvitationEmailReconciler_Reconcile_NoEmail_Success(t *testing.T) { | |
|
||
func invitationEmailReconciler(c client.WithWatch) *InvitationEmailReconciler { | ||
return &InvitationEmailReconciler{ | ||
Client: c, | ||
Scheme: c.Scheme(), | ||
Recorder: record.NewFakeRecorder(3), | ||
MailSender: &SenderWithConstantId{}, | ||
RetryInterval: time.Minute, | ||
Client: c, | ||
Scheme: c.Scheme(), | ||
Recorder: record.NewFakeRecorder(3), | ||
MailSender: &SenderWithConstantId{}, | ||
BaseRetryDelay: time.Minute, | ||
} | ||
} | ||
|
||
func invitationEmailReconcilerWithFailingSender(c client.WithWatch) *InvitationEmailReconciler { | ||
return &InvitationEmailReconciler{ | ||
Client: c, | ||
Scheme: c.Scheme(), | ||
Recorder: record.NewFakeRecorder(3), | ||
MailSender: &FailingSender{}, | ||
RetryInterval: time.Minute, | ||
Client: c, | ||
Scheme: c.Scheme(), | ||
Recorder: record.NewFakeRecorder(3), | ||
MailSender: &FailingSender{}, | ||
BaseRetryDelay: time.Minute, | ||
} | ||
} | ||
|
||
func baseInvitation() *userv1.Invitation { | ||
return &userv1.Invitation{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "subject", | ||
}, | ||
Spec: userv1.InvitationSpec{ | ||
Email: "[email protected]", | ||
}, | ||
Status: userv1.InvitationStatus{ | ||
Token: "abc", | ||
}, | ||
} | ||
} |