Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into member-info-in-sp…
Browse files Browse the repository at this point in the history
…c-status_capacity-manager-part
  • Loading branch information
metlos committed Jan 16, 2025
2 parents f292135 + 79d4b4d commit 39fa57e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 78 deletions.
37 changes: 0 additions & 37 deletions config/crd/bases/toolchain.dev.openshift.com_nstemplatetiers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,43 +169,6 @@ spec:
is updated.
type: object
x-kubernetes-map-type: atomic
updates:
description: Updates is an array of all NSTemplateTier updates
items:
description: NSTemplateTierHistory a track record of an update
properties:
completionTime:
description: CompletionTime is the time when the last MasterUserRecord
was updated
format: date-time
type: string
failedAccounts:
description: FailedAccounts
items:
type: string
type: array
failures:
description: Failures is the number of MasterUserRecords which
failed to be updated
type: integer
hash:
description: Hash the hash matching on the templateRefs in the
resource spec
type: string
startTime:
description: StartTime is the time when the NSTemplateTier was
updated
format: date-time
type: string
required:
- failures
- hash
- startTime
type: object
type: array
x-kubernetes-list-map-keys:
- startTime
x-kubernetes-list-type: map
type: object
type: object
x-kubernetes-preserve-unknown-fields: true
Expand Down
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
2 changes: 1 addition & 1 deletion controllers/usersignup/usersignup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3122,7 +3122,7 @@ func TestUserSignupBannedWithoutMURAndSpace(t *testing.T) {

func TestUserSignupVerificationRequired(t *testing.T) {
// given
userSignup := commonsignup.NewUserSignup(commonsignup.VerificationRequired(0))
userSignup := commonsignup.NewUserSignup(commonsignup.VerificationRequired())

r, req, _ := prepareReconcile(t, userSignup.Name, userSignup, commonconfig.NewToolchainConfigObjWithReset(t, testconfig.AutomaticApproval().Enabled(true)), baseNSTemplateTier)
InitializeCounters(t, NewToolchainStatus(
Expand Down
30 changes: 15 additions & 15 deletions controllers/usersignupcleanup/usersignup_cleanup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestUserCleanup(t *testing.T) {
userSignup := commonsignup.NewUserSignup(
commonsignup.ApprovedManuallyAgo(fiveYears),
commonsignup.WithStateLabel(toolchainv1alpha1.UserSignupStateLabelValueApproved),
commonsignup.DeactivatedWithLastTransitionTime(time.Duration(5*time.Minute)),
commonsignup.DeactivatedAgo(5*time.Minute),
commonsignup.CreatedBefore(fiveYears),
)

Expand All @@ -85,7 +85,7 @@ func TestUserCleanup(t *testing.T) {
userSignup := commonsignup.NewUserSignup(
commonsignup.WithStateLabel(toolchainv1alpha1.UserSignupStateLabelValueApproved),
commonsignup.ApprovedManuallyAgo(fiveYears),
commonsignup.DeactivatedWithLastTransitionTime(fiveYears),
commonsignup.DeactivatedAgo(fiveYears),
commonsignup.CreatedBefore(fiveYears),
)

Expand All @@ -111,7 +111,7 @@ func TestUserCleanup(t *testing.T) {

userSignup := commonsignup.NewUserSignup(
commonsignup.CreatedBefore(days(8)),
commonsignup.VerificationRequired(days(8)),
commonsignup.VerificationRequiredAgo(days(8)),
commonsignup.WithActivations("0"),
)

Expand Down Expand Up @@ -142,7 +142,7 @@ func TestUserCleanup(t *testing.T) {
// given
userSignup := commonsignup.NewUserSignup(
commonsignup.CreatedBefore(days(8)),
commonsignup.VerificationRequired(days(8)),
commonsignup.VerificationRequiredAgo(days(8)),
)
r, req, _ := prepareReconcile(t, userSignup.Name, userSignup)
// when
Expand All @@ -167,7 +167,7 @@ func TestUserCleanup(t *testing.T) {
// given
userSignup := commonsignup.NewUserSignup(
commonsignup.CreatedBefore(days(8)),
commonsignup.VerificationRequired(days(8)),
commonsignup.VerificationRequiredAgo(days(8)),
commonsignup.WithAnnotation(toolchainv1alpha1.UserSignupVerificationCodeAnnotationKey, "12345"),
)
r, req, _ := prepareReconcile(t, userSignup.Name, userSignup)
Expand All @@ -194,7 +194,7 @@ func TestUserCleanup(t *testing.T) {
userSignup := commonsignup.NewUserSignup(
commonsignup.CreatedBefore(fiveYears),
commonsignup.ApprovedManuallyAgo(days(40)),
commonsignup.VerificationRequired(days(10)),
commonsignup.VerificationRequiredAgo(days(10)),
commonsignup.WithActivations("1"),
)

Expand All @@ -216,7 +216,7 @@ func TestUserCleanup(t *testing.T) {
userSignup := commonsignup.NewUserSignup(
commonsignup.CreatedBefore(fiveYears),
commonsignup.ApprovedManuallyAgo(days(730+21)),
commonsignup.VerificationRequired(days(730+1)),
commonsignup.VerificationRequiredAgo(days(730+1)),
commonsignup.WithActivations("2"),
)

Expand Down Expand Up @@ -266,43 +266,43 @@ func TestUserCleanup(t *testing.T) {
}{
"test that a UserSignup older than 2 years, with 1 activation and not banned, is deleted": {
userSignup: commonsignup.NewUserSignup(
commonsignup.DeactivatedWithLastTransitionTime(twoYears),
commonsignup.DeactivatedAgo(twoYears),
commonsignup.WithActivations("1")),
expectedError: "",
expectedToBeDeleted: true,
},
"test that a UserSignup older than 2 years, with indeterminate activations and not banned, is deleted": {
userSignup: commonsignup.NewUserSignup(
commonsignup.DeactivatedWithLastTransitionTime(twoYears),
commonsignup.DeactivatedAgo(twoYears),
commonsignup.WithActivations("unknown")),
expectedError: "",
expectedToBeDeleted: true,
},
"test that a UserSignup 1 year old, with 1 activation and not banned, is not deleted": {
userSignup: commonsignup.NewUserSignup(
commonsignup.DeactivatedWithLastTransitionTime(oneYear),
commonsignup.DeactivatedAgo(oneYear),
commonsignup.WithActivations("1")),
expectedError: "",
expectedToBeDeleted: false,
},
"test that a UserSignup older than 2 years, with 2 activations and not banned, is not deleted": {
userSignup: commonsignup.NewUserSignup(
commonsignup.DeactivatedWithLastTransitionTime(twoYears),
commonsignup.DeactivatedAgo(twoYears),
commonsignup.WithActivations("2")),
expectedError: "",
expectedToBeDeleted: false,
},
"test that a UserSignup older than 2 years, with 1 activation but has been banned, is not deleted": {
userSignup: commonsignup.NewUserSignup(
commonsignup.DeactivatedWithLastTransitionTime(twoYears),
commonsignup.DeactivatedAgo(twoYears),
commonsignup.WithActivations("1")),
banned: true,
expectedError: "",
expectedToBeDeleted: false,
},
"test that a banned UserSignup with an invalid email hash returns an error and is not deleted": {
userSignup: commonsignup.NewUserSignup(
commonsignup.DeactivatedWithLastTransitionTime(twoYears),
commonsignup.DeactivatedAgo(twoYears),
commonsignup.WithActivations("1"),
commonsignup.WithName("invalid-email-user"),
commonsignup.WithLabel(toolchainv1alpha1.UserSignupUserEmailHashLabelKey, "INVALID")),
Expand All @@ -312,7 +312,7 @@ func TestUserCleanup(t *testing.T) {
},
"test that a UserSignup without an email address returns an error and is not deleted": {
userSignup: commonsignup.NewUserSignup(
commonsignup.DeactivatedWithLastTransitionTime(twoYears),
commonsignup.DeactivatedAgo(twoYears),
commonsignup.WithActivations("1"),
commonsignup.WithName("without-email-user"),
commonsignup.WithEmail("")),
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestUserCleanup(t *testing.T) {
t.Run("test propagation policy", func(t *testing.T) {
userSignup := commonsignup.NewUserSignup(
commonsignup.CreatedBefore(fiveYears),
commonsignup.VerificationRequired(days(8)),
commonsignup.VerificationRequiredAgo(days(8)),
)

r, req, fakeClient := prepareReconcile(t, userSignup.Name, userSignup)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/codeready-toolchain/host-operator
require (
cloud.google.com/go/recaptchaenterprise/v2 v2.13.0
github.com/codeready-toolchain/api v0.0.0-20241119094246-f6581d52dc80
github.com/codeready-toolchain/toolchain-common v0.0.0-20241128143121-e2e3546a35e9
github.com/codeready-toolchain/toolchain-common v0.0.0-20250113092648-1078d683961b
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/go-logr/logr v1.4.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBS
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/codeready-toolchain/api v0.0.0-20241119094246-f6581d52dc80 h1:OpZkP3OGAdrDHOb1TtHVnLSVuevEiQhOH//plnpVL/c=
github.com/codeready-toolchain/api v0.0.0-20241119094246-f6581d52dc80/go.mod h1:DUq1ffy9Mbersdgji48i/cm9Y+6NMwAdAQJNlfOrPRo=
github.com/codeready-toolchain/toolchain-common v0.0.0-20241128143121-e2e3546a35e9 h1:urMWj0TK944x2zZhVEvcNklLzPbarWBaxLGhyeXdLi0=
github.com/codeready-toolchain/toolchain-common v0.0.0-20241128143121-e2e3546a35e9/go.mod h1:4MD8PrbljFH7qSF44EjzAs2HVdr1R/vrsii2eO8Im+4=
github.com/codeready-toolchain/toolchain-common v0.0.0-20250113092648-1078d683961b h1:zlLUDN9ddogCX8hzuPrIdS/YpAF8siucA5b56zGUz00=
github.com/codeready-toolchain/toolchain-common v0.0.0-20250113092648-1078d683961b/go.mod h1:wLXGFyEan+RJHZEEMmvTxNa2BrlizIA+4+Lsi1cyuAk=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down

0 comments on commit 39fa57e

Please sign in to comment.