Skip to content

Commit

Permalink
set scheduled deactivation time to nil when user in domain exclusion …
Browse files Browse the repository at this point in the history
…list
  • Loading branch information
sbryzak committed Apr 20, 2024
1 parent 3496763 commit 9fcee7c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controllers/deactivation/deactivation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
for _, domain := range config.Deactivation().DeactivationDomainsExcluded() {
if strings.HasSuffix(usersignup.Spec.IdentityClaims.Email, domain) {
logger.Info("user cannot be automatically deactivated because they belong to the exclusion list", "domain", domain)

// Also set the Scheduled deactivation time to nil if it's not already
if usersignup.Status.ScheduledDeactivationTimestamp != nil {
usersignup.Status.ScheduledDeactivationTimestamp = nil
if err := r.Client.Status().Update(ctx, usersignup); err != nil {
logger.Error(err, "failed to update usersignup status")
return reconcile.Result{}, err

Check warning on line 114 in controllers/deactivation/deactivation_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/deactivation/deactivation_controller.go#L113-L114

Added lines #L113 - L114 were not covered by tests
}
}

return reconcile.Result{}, nil
}
}
Expand Down
10 changes: 10 additions & 0 deletions controllers/deactivation/deactivation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func TestReconcile(t *testing.T) {
murProvisionedTime := &metav1.Time{Time: time.Now().Add(-time.Duration(expectedDeactivationTimeoutDeactivate30Tier*24) * time.Hour)}
mur := murtest.NewMasterUserRecord(t, username, murtest.TierName(userTier30.Name), murtest.Account("cluster1"), murtest.ProvisionedMur(murProvisionedTime), murtest.UserIDFromUserSignup(userSignupRedhat))
mur.Labels[toolchainv1alpha1.MasterUserRecordOwnerLabelKey] = userSignupRedhat.Name

now := metav1.NewTime(time.Now())
userSignupRedhat.Status.ScheduledDeactivationTimestamp = &now

r, req, cl := prepareReconcile(t, mur.Name, userTier30, mur, userSignupRedhat, config)
// when
res, err := r.Reconcile(context.TODO(), req)
Expand All @@ -203,6 +207,12 @@ func TestReconcile(t *testing.T) {
require.False(t, res.Requeue, "requeue should not be set")
require.Equal(t, time.Duration(0), res.RequeueAfter, "requeueAfter should not be set")
assertThatUserSignupStateIsDeactivated(t, cl, username, false)

// Reload the userSignup
require.NoError(t, cl.Get(context.TODO(), types.NamespacedName{Name: userSignupRedhat.Name, Namespace: operatorNamespace}, userSignupRedhat))

// Confirm the scheduled deactivation time is set to nil
require.Nil(t, userSignupRedhat.Status.ScheduledDeactivationTimestamp)
})
})
// in these tests, the controller should (eventually) deactivate the user
Expand Down

0 comments on commit 9fcee7c

Please sign in to comment.