Skip to content

Commit 912706f

Browse files
committed
Fieldvalidation wrapper: Do nothing for Apply
1 parent 91cc1f5 commit 912706f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/client/fieldvalidation.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package client
1818

1919
import (
2020
"context"
21-
"errors"
2221

2322
"k8s.io/apimachinery/pkg/api/meta"
2423
"k8s.io/apimachinery/pkg/runtime"
@@ -55,7 +54,7 @@ func (c *clientWithFieldValidation) Patch(ctx context.Context, obj Object, patch
5554
}
5655

5756
func (c *clientWithFieldValidation) Apply(ctx context.Context, obj runtime.ApplyConfiguration, opts ...ApplyOption) error {
58-
return errors.New("Apply is not supported with field validation")
57+
return c.client.Apply(ctx, obj, opts...)
5958
}
6059

6160
func (c *clientWithFieldValidation) Delete(ctx context.Context, obj Object, opts ...DeleteOption) error {

pkg/client/fieldvalidation_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import (
2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
28+
"k8s.io/apimachinery/pkg/runtime"
2829
"k8s.io/apimachinery/pkg/runtime/schema"
30+
corev1applyconfigurations "k8s.io/client-go/applyconfigurations/core/v1"
2931
"sigs.k8s.io/controller-runtime/pkg/client"
3032
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3133
"sigs.k8s.io/controller-runtime/pkg/client/interceptor"
@@ -104,6 +106,7 @@ func TestWithStrictFieldValidation(t *testing.T) {
104106

105107
_ = wrappedClient.Create(ctx, dummyObj)
106108
_ = wrappedClient.Update(ctx, dummyObj)
109+
_ = wrappedClient.Apply(ctx, corev1applyconfigurations.ConfigMap("foo", "bar"))
107110
_ = wrappedClient.Patch(ctx, dummyObj, nil)
108111
_ = wrappedClient.Status().Create(ctx, dummyObj, dummyObj)
109112
_ = wrappedClient.Status().Update(ctx, dummyObj)
@@ -112,7 +115,7 @@ func TestWithStrictFieldValidation(t *testing.T) {
112115
_ = wrappedClient.SubResource("some-subresource").Update(ctx, dummyObj)
113116
_ = wrappedClient.SubResource("some-subresource").Patch(ctx, dummyObj, nil)
114117

115-
if expectedCalls := 9; calls != expectedCalls {
118+
if expectedCalls := 10; calls != expectedCalls {
116119
t.Fatalf("wrong number of calls to assertions: expected=%d; got=%d", expectedCalls, calls)
117120
}
118121
}
@@ -188,6 +191,10 @@ func testFieldValidationClient(t *testing.T, expectedFieldValidation string, cal
188191
}
189192
return nil
190193
},
194+
Apply: func(ctx context.Context, client client.WithWatch, obj runtime.ApplyConfiguration, opts ...client.ApplyOption) error {
195+
callback()
196+
return nil
197+
},
191198
Patch: func(ctx context.Context, c client.WithWatch, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
192199
callback()
193200
out := &client.PatchOptions{}

0 commit comments

Comments
 (0)