Skip to content

use the SSA apply client for create/update of the ToolchainStatus #1176

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

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions controllers/toolchainstatus/creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions controllers/toolchainstatus/creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ 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
err = CreateOrUpdateResources(context.TODO(), cl, commontest.HostOperatorNs, name)

// 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())
})
}
Loading