Skip to content

Commit

Permalink
skip deactivating state if deactivatingNotificationDays is zero (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek authored Jan 15, 2025
1 parent 000ed51 commit 94aad5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
7 changes: 4 additions & 3 deletions controllers/deactivation/deactivation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package deactivation
import (
"context"
"fmt"
usersignup2 "github.com/codeready-toolchain/host-operator/controllers/usersignup"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
"time"

usersignup2 "github.com/codeready-toolchain/host-operator/controllers/usersignup"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/host-operator/controllers/toolchainconfig"
"github.com/codeready-toolchain/host-operator/pkg/metrics"
Expand Down Expand Up @@ -192,7 +193,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}

// If the usersignup state hasn't been set to deactivating, then set it now
if !states.Deactivating(usersignup) {
if !states.Deactivating(usersignup) && deactivatingNotificationDays > 0 {

// Before we update the UserSignup in order to set the deactivating state, we should reset the scheduled
// deactivation time if required just in case the current value is nil or has somehow changed. Since the UserSignup
Expand Down
27 changes: 8 additions & 19 deletions controllers/deactivation/deactivation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package deactivation
import (
"context"
"fmt"
commontier "github.com/codeready-toolchain/toolchain-common/pkg/test/tier"
"github.com/codeready-toolchain/toolchain-common/pkg/test/usersignup"
"github.com/pkg/errors"
"os"
"testing"
"time"

commontier "github.com/codeready-toolchain/toolchain-common/pkg/test/tier"
"github.com/codeready-toolchain/toolchain-common/pkg/test/usersignup"
"github.com/pkg/errors"

"github.com/gofrs/uuid"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
Expand Down Expand Up @@ -763,7 +764,7 @@ func TestReconcile(t *testing.T) {
})
}

func TestAutomaticDeactivation(t *testing.T) {
func TestAutomaticDeactivationWithoutDeactivating(t *testing.T) {
config := commonconfig.NewToolchainConfigObjWithReset(t, testconfig.Deactivation().DeactivatingNotificationDays(0))

// UserTiers
Expand All @@ -788,21 +789,9 @@ func TestAutomaticDeactivation(t *testing.T) {
_, err := r.Reconcile(context.TODO(), req)
require.NoError(t, err)

// The user should be deactivating
reloaded := &toolchainv1alpha1.UserSignup{}
err = cl.Get(context.TODO(), types.NamespacedName{Name: userSignupMember1.Name, Namespace: operatorNamespace}, reloaded)
require.NoError(t, err)
require.True(t, states.Deactivating(reloaded))

// reconcile again
r, req, cl = prepareReconcile(t, mur.Name, userTier30, mur, reloaded, config)
_, err = r.Reconcile(context.TODO(), req)
require.NoError(t, err)

// Reload the usersignup, they should now be in a deactivated state
err = cl.Get(context.TODO(), types.NamespacedName{Name: userSignupMember1.Name, Namespace: operatorNamespace}, reloaded)
require.NoError(t, err)
require.True(t, states.Deactivated(reloaded))
// then
// the usersignup should be in a deactivated state
assertThatUserSignupStateIsDeactivated(t, cl, userSignupMember1.Name, true)
}

func prepareReconcile(t *testing.T, name string, initObjs ...runtimeclient.Object) (reconcile.Reconciler, reconcile.Request, *commontest.FakeClient) {
Expand Down

0 comments on commit 94aad5e

Please sign in to comment.