Skip to content

Commit 1242840

Browse files
authored
chore: bumped controller-runtime and fixed tests (#342)
bumped controller-runtime and fixed tests
1 parent 5891f7f commit 1242840

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
k8s.io/cli-runtime v0.29.2
2424
k8s.io/client-go v0.29.2
2525
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
26-
sigs.k8s.io/controller-runtime v0.17.1
26+
sigs.k8s.io/controller-runtime v0.17.2
2727
sigs.k8s.io/yaml v1.4.0
2828
)
2929

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,8 @@ oras.land/oras-go v1.2.4/go.mod h1:DYcGfb3YF1nKjcezfX2SNlDAeQFKSXmf+qrFmrh4324=
963963
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
964964
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
965965
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
966-
sigs.k8s.io/controller-runtime v0.17.1 h1:V1dQELMGVk46YVXXQUbTFujU7u4DQj6YUj9Rb6cuzz8=
967-
sigs.k8s.io/controller-runtime v0.17.1/go.mod h1:+MngTvIQQQhfXtwfdGw/UOQ/aIaqsYywfCINOtwMO/s=
966+
sigs.k8s.io/controller-runtime v0.17.2 h1:FwHwD1CTUemg0pW2otk7/U5/i5m2ymzvOXdbeGOUvw0=
967+
sigs.k8s.io/controller-runtime v0.17.2/go.mod h1:+MngTvIQQQhfXtwfdGw/UOQ/aIaqsYywfCINOtwMO/s=
968968
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
969969
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
970970
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 h1:XX3Ajgzov2RKUdc5jW3t5jwY7Bo7dcRm+tFxT+NfgY0=

pkg/k8s/client_test.go

+9-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package k8s
22

33
import (
44
"context"
5+
"errors"
56
"testing"
67

78
"github.com/kyma-project/nats-manager/testutils"
@@ -18,6 +19,8 @@ import (
1819

1920
const testFieldManager = "nats-manager"
2021

22+
var errPatchNotAllowed = errors.New("apply patches are not supported in the fake client")
23+
2124
func Test_GetStatefulSet(t *testing.T) {
2225
t.Parallel()
2326

@@ -180,20 +183,11 @@ func Test_Delete(t *testing.T) {
180183
func Test_PatchApply(t *testing.T) {
181184
t.Parallel()
182185

183-
// NOTE: In real k8s client, the kubeClient.PatchApply creates the resource
184-
// if it does not exist on the cluster. But in the fake client the behaviour
185-
// is not properly replicated. As mentioned: "ObjectMeta's `Generation` and
186-
// `ResourceVersion` don't behave properly, Patch or Update operations that
187-
// rely on these fields will fail, or give false positives." in docs
188-
// https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client/fake
189-
// This scenario will be tested in integration tests with envTest pkg.
190-
191186
// define test cases
192187
testCases := []struct {
193188
name string
194189
givenStatefulSet *unstructured.Unstructured
195190
givenUpdateStatefulSet *unstructured.Unstructured
196-
wantReplicas int
197191
}{
198192
{
199193
name: "should update resource when exists in k8s",
@@ -203,7 +197,6 @@ func Test_PatchApply(t *testing.T) {
203197
givenUpdateStatefulSet: testutils.NewNATSStatefulSetUnStruct(
204198
testutils.WithSpecReplicas(3),
205199
),
206-
wantReplicas: 3,
207200
},
208201
}
209202

@@ -226,14 +219,12 @@ func Test_PatchApply(t *testing.T) {
226219
err := kubeClient.PatchApply(context.Background(), tc.givenUpdateStatefulSet)
227220

228221
// then
229-
require.NoError(t, err)
230-
// check that it should exist on k8s.
231-
gotSTS, err := kubeClient.GetStatefulSet(context.Background(),
232-
tc.givenStatefulSet.GetName(), tc.givenStatefulSet.GetNamespace())
233-
require.NoError(t, err)
234-
require.Equal(t, tc.givenUpdateStatefulSet.GetName(), gotSTS.Name)
235-
require.Equal(t, tc.givenUpdateStatefulSet.GetNamespace(), gotSTS.Namespace)
236-
require.Equal(t, int32(tc.wantReplicas), *gotSTS.Spec.Replicas)
222+
// NOTE: The kubeClient.PatchApply is not supported in the fake client.
223+
// (https://github.com/kubernetes/kubernetes/issues/115598)
224+
// So in unit test we only check that the client.Patch with client.Apply
225+
// is called or not.
226+
// The real behaviour will be tested in integration tests with envTest pkg.
227+
require.ErrorContains(t, err, errPatchNotAllowed.Error())
237228
})
238229
}
239230
}

0 commit comments

Comments
 (0)