From 1a795e6e47f2e3c25bbdd3ca43a179ebbe0b415b Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Tue, 13 May 2025 16:08:17 +0200 Subject: [PATCH] use the SSA apply client for create/update of the ToolchainStatus --- controllers/toolchainstatus/creation.go | 6 +++--- controllers/toolchainstatus/creation_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/controllers/toolchainstatus/creation.go b/controllers/toolchainstatus/creation.go index d662b3ebd..0ad726003 100644 --- a/controllers/toolchainstatus/creation.go +++ b/controllers/toolchainstatus/creation.go @@ -4,6 +4,7 @@ import ( "context" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" + "github.com/codeready-toolchain/host-operator/pkg/constants" commonclient "github.com/codeready-toolchain/toolchain-common/pkg/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -19,7 +20,6 @@ func CreateOrUpdateResources(ctx context.Context, client runtimeclient.Client, n }, Spec: toolchainv1alpha1.ToolchainStatusSpec{}, } - cl := commonclient.NewApplyClient(client) - _, err := cl.ApplyObject(ctx, toolchainStatus) - return err + cl := commonclient.NewSSAApplyClient(client, constants.HostOperatorFieldManager) + return cl.ApplyObject(ctx, toolchainStatus) } diff --git a/controllers/toolchainstatus/creation_test.go b/controllers/toolchainstatus/creation_test.go index 3a223055a..5213bd75f 100644 --- a/controllers/toolchainstatus/creation_test.go +++ b/controllers/toolchainstatus/creation_test.go @@ -39,8 +39,8 @@ func TestCreateOrUpdateResources(t *testing.T) { t.Run("should return an error if creation fails ", func(t *testing.T) { // given cl := commontest.NewFakeClient(t) - cl.MockCreate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.CreateOption) error { - return fmt.Errorf("creation failed") + cl.MockPatch = func(_ context.Context, _ runtimeclient.Object, _ runtimeclient.Patch, _ ...runtimeclient.PatchOption) error { + return fmt.Errorf("patch failed") } // when @@ -48,6 +48,6 @@ func TestCreateOrUpdateResources(t *testing.T) { // then require.Error(t, err) - require.Equal(t, "unable to create resource of kind: , version: : creation failed", err.Error()) + require.Equal(t, "unable to patch 'toolchain.dev.openshift.com/v1alpha1, Kind=ToolchainStatus' called 'toolchain-status' in namespace 'toolchain-host-operator': patch failed", err.Error()) }) }