Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SANDBOX-560 update controller-runtime to v0.15 #1057

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
09cb2e4
update dependecies versions
ranakan19 Apr 2, 2024
0076914
add context to eventHandlers
ranakan19 Apr 2, 2024
c131f66
update watches signature
ranakan19 Apr 2, 2024
324a1cf
Merge branch 'master' of github.com:codeready-toolchain/host-operator…
ranakan19 Apr 2, 2024
26e1c33
add context to eventHandlers after pulling
ranakan19 Apr 3, 2024
107ca15
updated watch signature usage - after pulling
ranakan19 Apr 3, 2024
3646ad4
update replace versions
ranakan19 Apr 10, 2024
6f91a19
resolve merge upstream master conflict
ranakan19 Apr 10, 2024
8ad1348
update option to SubResourceUpdateOption
ranakan19 Apr 11, 2024
876fdf9
Add context to eventHandler
ranakan19 Apr 11, 2024
c4acfd0
replace runtime object with runtimeClient Object
ranakan19 Apr 15, 2024
19fce7c
add context to eventHandler calls in tests
ranakan19 Apr 16, 2024
cedfcf4
replace with SubResourceUpdateOption for MockStatusUpdate
ranakan19 Apr 16, 2024
f8f8e5c
mur unit tests fixed to add finalizer with deletionTS
ranakan19 Apr 18, 2024
301f417
add notification to the subStatus resource
ranakan19 Apr 30, 2024
332dcdc
update common, and add finalizer to nstemplateset test
ranakan19 May 1, 2024
9552b40
prev changes
ranakan19 Jun 20, 2024
524b8a9
merge conflict resolve attempt
ranakan19 Jun 27, 2024
f9bcec7
runtimeclient options
ranakan19 Jun 28, 2024
17bde78
Add finalizers when deletionTS is present
ranakan19 Jul 5, 2024
6463c77
add notification obj by default in newController
ranakan19 Jul 9, 2024
2c9919b
merge conflict resolve, other unit test failures
ranakan19 Aug 7, 2024
7ecab05
Merge branch 'master' into runtime_15_host
ranakan19 Aug 7, 2024
90278f1
merge master, update common version
ranakan19 Aug 15, 2024
b1d4d83
Merge branch 'master' into runtime_15_host
ranakan19 Aug 15, 2024
6a2da79
merge resolve, update replaced toolchain-common version
ranakan19 Aug 15, 2024
2bdbf6b
options.Namespace is deprecated, replace it
ranakan19 Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions controllers/deactivation/deactivation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// SetupWithManager sets up the controller with the Manager.
func (r *Reconciler) SetupWithManager(mgr manager.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Named("deactivation").
For(&toolchainv1alpha1.MasterUserRecord{}, builder.WithPredicates(CreateAndUpdateOnlyPredicate{})).
Watches(&source.Kind{Type: &toolchainv1alpha1.UserSignup{}},
Watches(&toolchainv1alpha1.UserSignup{},

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

View check run for this annotation

Codecov / codecov/patch

controllers/deactivation/deactivation_controller.go#L37

Added line #L37 was not covered by tests
handler.EnqueueRequestsFromMapFunc(MapUserSignupToMasterUserRecord())).
Complete(r)
}
Expand Down Expand Up @@ -194,7 +193,6 @@

// If the usersignup state hasn't been set to deactivating, then set it now
if !states.Deactivating(usersignup) {
states.SetDeactivating(usersignup, true)
MatousJobanek marked this conversation as resolved.
Show resolved Hide resolved

// 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 All @@ -208,6 +206,7 @@
}

logger.Info("setting usersignup state to deactivating")
states.SetDeactivating(usersignup, true)
MatousJobanek marked this conversation as resolved.
Show resolved Hide resolved
if err := r.Client.Update(ctx, usersignup); err != nil {
logger.Error(err, "failed to update usersignup")
return reconcile.Result{}, err
Expand Down
15 changes: 7 additions & 8 deletions controllers/deactivation/deactivation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -164,7 +163,7 @@ func TestReconcile(t *testing.T) {

r, req, fakeClient := prepareReconcile(t, mur.Name, userTier30, mur, userSignupFoobar, config)

fakeClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
fakeClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
switch obj.(type) {
case *toolchainv1alpha1.UserSignup:
return errors.New("mock error")
Expand Down Expand Up @@ -261,7 +260,7 @@ func TestReconcile(t *testing.T) {
r, req, cl := prepareReconcile(t, mur.Name, userTier30, mur, userSignupRedhat, config)

// First cause the status update to fail
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
switch obj.(type) {
case *toolchainv1alpha1.UserSignup:
return errors.New("mock error")
Expand Down Expand Up @@ -310,7 +309,7 @@ func TestReconcile(t *testing.T) {
r, req, cl := prepareReconcile(t, mur.Name, userTier30, mur, userSignupFoobar, config)

// First cause the status update to fail
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
switch obj.(type) {
case *toolchainv1alpha1.UserSignup:
return errors.New("mock error")
Expand Down Expand Up @@ -350,7 +349,7 @@ func TestReconcile(t *testing.T) {
r, req, cl := prepareReconcile(t, mur.Name, userTier30, mur, userSignupFoobar, config)

// First cause the status update to fail
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
switch obj.(type) {
case *toolchainv1alpha1.UserSignup:
return errors.New("mock error")
Expand Down Expand Up @@ -405,7 +404,7 @@ func TestReconcile(t *testing.T) {
r, req, cl := prepareReconcile(t, mur.Name, userTier30, mur, userSignupFoobar, config)

// First cause the status update to fail
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
switch obj.(type) {
case *toolchainv1alpha1.UserSignup:
return errors.New("mock error")
Expand Down Expand Up @@ -659,7 +658,7 @@ func TestReconcile(t *testing.T) {
require.False(t, states.Deactivating(userSignupFoobar))

// Mock client which returns an error when the update fails
fakeClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
fakeClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
switch obj.(type) {
case *toolchainv1alpha1.UserSignup:
return errors.New("mock error")
Expand Down Expand Up @@ -806,7 +805,7 @@ func TestAutomaticDeactivation(t *testing.T) {
require.True(t, states.Deactivated(reloaded))
}

func prepareReconcile(t *testing.T, name string, initObjs ...runtime.Object) (reconcile.Reconciler, reconcile.Request, *commontest.FakeClient) {
func prepareReconcile(t *testing.T, name string, initObjs ...runtimeclient.Object) (reconcile.Reconciler, reconcile.Request, *commontest.FakeClient) {
os.Setenv("WATCH_NAMESPACE", commontest.HostOperatorNs)
metrics.Reset()
s := scheme.Scheme
Expand Down
5 changes: 3 additions & 2 deletions controllers/deactivation/mapper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deactivation

import (
"context"
"errors"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
Expand All @@ -13,8 +14,8 @@ import (

var mapperLog = ctrl.Log.WithName("UserSignupToMasterUserRecordMapper")

func MapUserSignupToMasterUserRecord() func(object runtimeclient.Object) []reconcile.Request {
return func(obj runtimeclient.Object) []reconcile.Request {
func MapUserSignupToMasterUserRecord() func(ctx context.Context, object runtimeclient.Object) []reconcile.Request {
return func(ctx context.Context, obj runtimeclient.Object) []reconcile.Request {
if userSignup, ok := obj.(*toolchainv1alpha1.UserSignup); ok {

if userSignup.Status.CompliantUsername != "" {
Expand Down
7 changes: 4 additions & 3 deletions controllers/deactivation/mapper_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deactivation

import (
"context"
"testing"

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

// when
req := MapUserSignupToMasterUserRecord()(userSignup)
req := MapUserSignupToMasterUserRecord()(context.TODO(), userSignup)

// then
require.Len(t, req, 1)
Expand All @@ -53,7 +54,7 @@ func TestUserSignupToMasterUserRecordMapper(t *testing.T) {
}

// when
req := MapUserSignupToMasterUserRecord()(userSignup)
req := MapUserSignupToMasterUserRecord()(context.TODO(), userSignup)

// then
require.Empty(t, req)
Expand All @@ -76,7 +77,7 @@ func TestUserSignupToMasterUserRecordMapper(t *testing.T) {
}

// when
req := MapUserSignupToMasterUserRecord()(mur)
req := MapUserSignupToMasterUserRecord()(context.TODO(), mur)

// then
require.Empty(t, req)
Expand Down
4 changes: 2 additions & 2 deletions controllers/masteruserrecord/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

// MapSpaceToMasterUserRecord maps events on Spaces to MasterUserRecords by labels at SpaceBindings
func MapSpaceToMasterUserRecord(cl runtimeclient.Client) func(object runtimeclient.Object) []reconcile.Request {
return func(obj runtimeclient.Object) []reconcile.Request {
func MapSpaceToMasterUserRecord(cl runtimeclient.Client) func(ctx context.Context, object runtimeclient.Object) []reconcile.Request {
return func(ctx context.Context, obj runtimeclient.Object) []reconcile.Request {
var logger = ctrl.Log.WithName("SpaceToMasterUserRecordMapper").WithValues("object-name", obj.GetName(), "object-kind", obj.GetObjectKind())
spaceBindings := &toolchainv1alpha1.SpaceBindingList{}
err := cl.List(context.TODO(), spaceBindings,
Expand Down
8 changes: 4 additions & 4 deletions controllers/masteruserrecord/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestBannedUserToUserSignupMapper(t *testing.T) {
client := test.NewFakeClient(t, spaceBinding, noise)

// when
requests := MapSpaceToMasterUserRecord(client)(space)
requests := MapSpaceToMasterUserRecord(client)(context.TODO(), space)

// then
assert.Len(t, requests, 1)
Expand All @@ -38,7 +38,7 @@ func TestBannedUserToUserSignupMapper(t *testing.T) {
client := test.NewFakeClient(t, spaceBinding, spaceBindingJane, noise)

// when
requests := MapSpaceToMasterUserRecord(client)(space)
requests := MapSpaceToMasterUserRecord(client)(context.TODO(), space)

// then
assert.Len(t, requests, 2)
Expand All @@ -51,7 +51,7 @@ func TestBannedUserToUserSignupMapper(t *testing.T) {
client := test.NewFakeClient(t, noise)

// when
requests := MapSpaceToMasterUserRecord(client)(space)
requests := MapSpaceToMasterUserRecord(client)(context.TODO(), space)

// then
assert.Empty(t, requests)
Expand All @@ -65,7 +65,7 @@ func TestBannedUserToUserSignupMapper(t *testing.T) {
}

// when
requests := MapSpaceToMasterUserRecord(client)(space)
requests := MapSpaceToMasterUserRecord(client)(context.TODO(), space)

// then
assert.Empty(t, requests)
Expand Down
6 changes: 3 additions & 3 deletions controllers/masteruserrecord/masteruserrecord_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
func (r *Reconciler) SetupWithManager(mgr manager.Manager, memberClusters map[string]cluster.Cluster) error {
b := ctrl.NewControllerManagedBy(mgr).
For(&toolchainv1alpha1.MasterUserRecord{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&source.Kind{Type: &toolchainv1alpha1.SpaceBinding{}}, handler.EnqueueRequestsFromMapFunc(
Watches(&toolchainv1alpha1.SpaceBinding{}, handler.EnqueueRequestsFromMapFunc(

Check warning on line 43 in controllers/masteruserrecord/masteruserrecord_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/masteruserrecord/masteruserrecord_controller.go#L43

Added line #L43 was not covered by tests
controllers.MapToOwnerByLabel(r.Namespace, toolchainv1alpha1.SpaceBindingMasterUserRecordLabelKey))).
Watches(&source.Kind{Type: &toolchainv1alpha1.Space{}}, handler.EnqueueRequestsFromMapFunc(
Watches(&toolchainv1alpha1.Space{}, handler.EnqueueRequestsFromMapFunc(

Check warning on line 45 in controllers/masteruserrecord/masteruserrecord_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/masteruserrecord/masteruserrecord_controller.go#L45

Added line #L45 was not covered by tests
MapSpaceToMasterUserRecord(r.Client)), builder.WithPredicates(predicate.GenerationChangedPredicate{}))

// watch UserAccounts in all the member clusters
for _, memberCluster := range memberClusters {
b = b.Watches(source.NewKindWithCache(&toolchainv1alpha1.UserAccount{}, memberCluster.Cache),
b = b.WatchesRawSource(source.Kind(memberCluster.Cache, &toolchainv1alpha1.UserAccount{}),

Check warning on line 50 in controllers/masteruserrecord/masteruserrecord_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/masteruserrecord/masteruserrecord_controller.go#L50

Added line #L50 was not covered by tests
handler.EnqueueRequestsFromMapFunc(mapper.MapByResourceName(r.Namespace)),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ func TestCreateSynchronizeOrDeleteUserAccountFailed(t *testing.T) {
hostClient := commontest.NewFakeClient(t, provisionedMur, toolchainStatus, spaceBinding, space)
InitializeCounters(t, toolchainStatus)

hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
hostClient.MockStatusUpdate = nil // mock only once
return fmt.Errorf("unable to update MUR %s", provisionedMur.Name)
}
Expand Down Expand Up @@ -1236,8 +1236,7 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) {
s := apiScheme(t)
mur := murtest.NewMasterUserRecord(t, "john-wait-for-ua",
murtest.ToBeDeleted())
userAcc := uatest.NewUserAccountFromMur(mur,
uatest.DeletedUa())
userAcc := uatest.NewUserAccountFromMur(mur, uatest.DeletedUa(), uatest.WithFinalizer())

hostClient := commontest.NewFakeClient(t, mur, toolchainStatus)
memberClient := commontest.NewFakeClient(t, userAcc)
Expand All @@ -1252,8 +1251,11 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) {
murtest.AssertThatMasterUserRecord(t, "john-wait-for-ua", hostClient).
HasFinalizer()

err = memberClient.Delete(context.TODO(), userAcc)
// remove finalizer on UserAcc to delete
userAcc.SetFinalizers(nil)
err = memberClient.Client.Update(context.TODO(), userAcc)
require.NoError(t, err)

result2, err2 := cntrl.Reconcile(context.TODO(), newMurRequest(mur))

// then
Expand Down Expand Up @@ -1287,7 +1289,7 @@ func TestDeleteUserAccountViaMasterUserRecordBeingDeleted(t *testing.T) {

mur := murtest.NewMasterUserRecord(t, "john-wait-for-ua",
murtest.ToBeDeleted())
userAcc := uatest.NewUserAccountFromMur(mur)
userAcc := uatest.NewUserAccountFromMur(mur, uatest.WithFinalizer())
// set deletion timestamp to indicate UserAccount deletion is in progress
userAcc.DeletionTimestamp = &metav1.Time{Time: time.Now().Add(-60 * time.Second)}

Expand Down
10 changes: 6 additions & 4 deletions controllers/masteruserrecord/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestSynchronizeStatus(t *testing.T) {
t.Run("failed on the host side", func(t *testing.T) {
// given
hostClient := test.NewFakeClient(t, mur, readyToolchainStatus)
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
return fmt.Errorf("some error")
}
sync, _ := prepareSynchronizer(t, userAccount, mur, hostClient)
Expand Down Expand Up @@ -235,6 +235,8 @@ func TestSyncMurStatusWithUserAccountStatusWhenUpdated(t *testing.T) {

// when
preSyncTime := metav1.Now()
// add a delay of a second to avoid flakiness
time.Sleep(1 * time.Second)
ranakan19 marked this conversation as resolved.
Show resolved Hide resolved
err := sync.synchronizeStatus(context.TODO())

// then
Expand All @@ -247,7 +249,7 @@ func TestSyncMurStatusWithUserAccountStatusWhenUpdated(t *testing.T) {
t.Run("failed on the host side", func(t *testing.T) {
// given
hostClient := test.NewFakeClient(t, mur)
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
return fmt.Errorf("some error")
}
sync, _ := prepareSynchronizer(t, userAccount, mur, hostClient)
Expand Down Expand Up @@ -295,7 +297,7 @@ func TestSyncMurStatusWithUserAccountStatusWhenDisabled(t *testing.T) {
t.Run("failed on the host side", func(t *testing.T) {
// given
hostClient := test.NewFakeClient(t, mur.DeepCopy())
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
return fmt.Errorf("some error")
}
sync, _ := prepareSynchronizer(t, userAccount, mur, hostClient)
Expand Down Expand Up @@ -663,7 +665,7 @@ func TestSynchronizeUserAccountFailed(t *testing.T) {
uatest.StatusCondition(toBeNotReady("somethingFailed", "")))
memberClient := test.NewFakeClient(t, userAcc)
hostClient := test.NewFakeClient(t, provisionedMur, readyToolchainStatus)
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
hostClient.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
return fmt.Errorf("unable to update MUR %s", provisionedMur.Name)
}
sync := Synchronizer{
Expand Down
3 changes: 1 addition & 2 deletions controllers/notification/notification_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -378,7 +377,7 @@ func deletionCond(msg string) toolchainv1alpha1.Condition {
}

func newController(t *testing.T, deliveryService DeliveryService,
initObjs ...runtime.Object) (*Reconciler, *test.FakeClient) {
initObjs ...runtimeclient.Object) (*Reconciler, *test.FakeClient) {
restore := test.SetEnvVarAndRestore(t, commonconfig.WatchNamespaceEnvVar, test.HostOperatorNs)
t.Cleanup(restore)

Expand Down
17 changes: 8 additions & 9 deletions controllers/nstemplatetier/nstemplatetier_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
Expand All @@ -40,7 +39,7 @@ func TestReconcile(t *testing.T) {
t.Run("without previous entry", func(t *testing.T) {
// given
base1nsTier := tiertest.Base1nsTier(t, tiertest.CurrentBase1nsTemplates)
initObjs := []runtime.Object{base1nsTier}
initObjs := []runtimeclient.Object{base1nsTier}
r, req, cl := prepareReconcile(t, base1nsTier.Name, initObjs...)
// when
res, err := r.Reconcile(context.TODO(), req)
Expand All @@ -66,7 +65,7 @@ func TestReconcile(t *testing.T) {
StartTime: metav1.Now(),
Hash: "def456",
}))
initObjs := []runtime.Object{base1nsTier}
initObjs := []runtimeclient.Object{base1nsTier}
r, req, cl := prepareReconcile(t, base1nsTier.Name, initObjs...)
// when
res, err := r.Reconcile(context.TODO(), req)
Expand All @@ -90,7 +89,7 @@ func TestReconcile(t *testing.T) {
base1nsTier := tiertest.Base1nsTier(t, tiertest.CurrentBase1nsTemplates,
tiertest.WithCurrentUpdate()) // current update already exists

initObjs := []runtime.Object{base1nsTier}
initObjs := []runtimeclient.Object{base1nsTier}
r, req, cl := prepareReconcile(t, base1nsTier.Name, initObjs...)
// when
res, err := r.Reconcile(context.TODO(), req)
Expand All @@ -113,7 +112,7 @@ func TestReconcile(t *testing.T) {
t.Run("tier not found", func(t *testing.T) {
// given
base1nsTier := tiertest.Base1nsTier(t, tiertest.CurrentBase1nsTemplates)
initObjs := []runtime.Object{base1nsTier}
initObjs := []runtimeclient.Object{base1nsTier}
r, req, cl := prepareReconcile(t, base1nsTier.Name, initObjs...)
cl.MockGet = func(ctx context.Context, key types.NamespacedName, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error {
if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok {
Expand All @@ -131,7 +130,7 @@ func TestReconcile(t *testing.T) {
t.Run("other error", func(t *testing.T) {
// given
base1nsTier := tiertest.Base1nsTier(t, tiertest.CurrentBase1nsTemplates)
initObjs := []runtime.Object{base1nsTier}
initObjs := []runtimeclient.Object{base1nsTier}
r, req, cl := prepareReconcile(t, base1nsTier.Name, initObjs...)
cl.MockGet = func(ctx context.Context, key types.NamespacedName, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error {
if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok {
Expand All @@ -153,9 +152,9 @@ func TestReconcile(t *testing.T) {
t.Run("when adding new update", func(t *testing.T) {
// given
base1nsTier := tiertest.Base1nsTier(t, tiertest.CurrentBase1nsTemplates)
initObjs := []runtime.Object{base1nsTier}
initObjs := []runtimeclient.Object{base1nsTier}
r, req, cl := prepareReconcile(t, base1nsTier.Name, initObjs...)
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
if _, ok := obj.(*toolchainv1alpha1.NSTemplateTier); ok {
return fmt.Errorf("mock error")
}
Expand All @@ -173,7 +172,7 @@ func TestReconcile(t *testing.T) {

}

func prepareReconcile(t *testing.T, name string, initObjs ...runtime.Object) (reconcile.Reconciler, reconcile.Request, *test.FakeClient) {
func prepareReconcile(t *testing.T, name string, initObjs ...runtimeclient.Object) (reconcile.Reconciler, reconcile.Request, *test.FakeClient) {
os.Setenv("WATCH_NAMESPACE", test.HostOperatorNs)
s := scheme.Scheme
err := apis.AddToScheme(s)
Expand Down
Loading
Loading