@@ -20,88 +20,87 @@ import (
20
20
"context"
21
21
22
22
"k8s.io/apimachinery/pkg/api/meta"
23
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
23
"k8s.io/apimachinery/pkg/runtime"
25
24
"k8s.io/apimachinery/pkg/runtime/schema"
26
25
)
27
26
28
- // WithStrictFieldValidation wraps a Client and configures strict field
29
- // validation, by default, for all write requests from this client. Users
30
- // can override the field validation for individual requests.
31
- func WithStrictFieldValidation (c Client ) Client {
27
+ // WithFieldValidation wraps a Client and configures field validation, by
28
+ // default, for all write requests from this client. Users can override field
29
+ // validation for individual write requests.
30
+ func WithFieldValidation (c Client , validation FieldValidation ) Client {
32
31
return & clientWithFieldValidation {
33
- validation : metav1 . FieldValidationStrict ,
34
- c : c ,
32
+ validation : validation ,
33
+ client : c ,
35
34
Reader : c ,
36
35
}
37
36
}
38
37
39
38
type clientWithFieldValidation struct {
40
- validation string
41
- c Client
39
+ validation FieldValidation
40
+ client Client
42
41
Reader
43
42
}
44
43
45
- func (f * clientWithFieldValidation ) Create (ctx context.Context , obj Object , opts ... CreateOption ) error {
46
- return f . c . Create (ctx , obj , append ([]CreateOption {FieldValidation ( f .validation ) }, opts ... )... )
44
+ func (c * clientWithFieldValidation ) Create (ctx context.Context , obj Object , opts ... CreateOption ) error {
45
+ return c . client . Create (ctx , obj , append ([]CreateOption {c .validation }, opts ... )... )
47
46
}
48
47
49
- func (f * clientWithFieldValidation ) Update (ctx context.Context , obj Object , opts ... UpdateOption ) error {
50
- return f . c . Update (ctx , obj , append ([]UpdateOption {FieldValidation ( f .validation ) }, opts ... )... )
48
+ func (c * clientWithFieldValidation ) Update (ctx context.Context , obj Object , opts ... UpdateOption ) error {
49
+ return c . client . Update (ctx , obj , append ([]UpdateOption {c .validation }, opts ... )... )
51
50
}
52
51
53
- func (f * clientWithFieldValidation ) Patch (ctx context.Context , obj Object , patch Patch , opts ... PatchOption ) error {
54
- return f . c . Patch (ctx , obj , patch , append ([]PatchOption {FieldValidation ( f .validation ) }, opts ... )... )
52
+ func (c * clientWithFieldValidation ) Patch (ctx context.Context , obj Object , patch Patch , opts ... PatchOption ) error {
53
+ return c . client . Patch (ctx , obj , patch , append ([]PatchOption {c .validation }, opts ... )... )
55
54
}
56
55
57
- func (f * clientWithFieldValidation ) Delete (ctx context.Context , obj Object , opts ... DeleteOption ) error {
58
- return f . c .Delete (ctx , obj , opts ... )
56
+ func (c * clientWithFieldValidation ) Delete (ctx context.Context , obj Object , opts ... DeleteOption ) error {
57
+ return c . client .Delete (ctx , obj , opts ... )
59
58
}
60
59
61
- func (f * clientWithFieldValidation ) DeleteAllOf (ctx context.Context , obj Object , opts ... DeleteAllOfOption ) error {
62
- return f . c .DeleteAllOf (ctx , obj , opts ... )
60
+ func (c * clientWithFieldValidation ) DeleteAllOf (ctx context.Context , obj Object , opts ... DeleteAllOfOption ) error {
61
+ return c . client .DeleteAllOf (ctx , obj , opts ... )
63
62
}
64
63
65
- func (f * clientWithFieldValidation ) Scheme () * runtime.Scheme { return f . c .Scheme () }
66
- func (f * clientWithFieldValidation ) RESTMapper () meta.RESTMapper { return f . c .RESTMapper () }
67
- func (f * clientWithFieldValidation ) GroupVersionKindFor (obj runtime.Object ) (schema.GroupVersionKind , error ) {
68
- return f . c .GroupVersionKindFor (obj )
64
+ func (c * clientWithFieldValidation ) Scheme () * runtime.Scheme { return c . client .Scheme () }
65
+ func (c * clientWithFieldValidation ) RESTMapper () meta.RESTMapper { return c . client .RESTMapper () }
66
+ func (c * clientWithFieldValidation ) GroupVersionKindFor (obj runtime.Object ) (schema.GroupVersionKind , error ) {
67
+ return c . client .GroupVersionKindFor (obj )
69
68
}
70
69
71
- func (f * clientWithFieldValidation ) IsObjectNamespaced (obj runtime.Object ) (bool , error ) {
72
- return f . c .IsObjectNamespaced (obj )
70
+ func (c * clientWithFieldValidation ) IsObjectNamespaced (obj runtime.Object ) (bool , error ) {
71
+ return c . client .IsObjectNamespaced (obj )
73
72
}
74
73
75
- func (f * clientWithFieldValidation ) Status () StatusWriter {
74
+ func (c * clientWithFieldValidation ) Status () StatusWriter {
76
75
return & subresourceClientWithFieldValidation {
77
- validation : f .validation ,
78
- subresourceWriter : f . c .Status (),
76
+ validation : c .validation ,
77
+ subresourceWriter : c . client .Status (),
79
78
}
80
79
}
81
80
82
- func (f * clientWithFieldValidation ) SubResource (subresource string ) SubResourceClient {
83
- c := f . c .SubResource (subresource )
81
+ func (c * clientWithFieldValidation ) SubResource (subresource string ) SubResourceClient {
82
+ srClient := c . client .SubResource (subresource )
84
83
return & subresourceClientWithFieldValidation {
85
- validation : f .validation ,
86
- subresourceWriter : c ,
87
- SubResourceReader : c ,
84
+ validation : c .validation ,
85
+ subresourceWriter : srClient ,
86
+ SubResourceReader : srClient ,
88
87
}
89
88
}
90
89
91
90
type subresourceClientWithFieldValidation struct {
92
- validation string
91
+ validation FieldValidation
93
92
subresourceWriter SubResourceWriter
94
93
SubResourceReader
95
94
}
96
95
97
- func (f * subresourceClientWithFieldValidation ) Create (ctx context.Context , obj Object , subresource Object , opts ... SubResourceCreateOption ) error {
98
- return f .subresourceWriter .Create (ctx , obj , subresource , append ([]SubResourceCreateOption {FieldValidation ( f .validation ) }, opts ... )... )
96
+ func (c * subresourceClientWithFieldValidation ) Create (ctx context.Context , obj Object , subresource Object , opts ... SubResourceCreateOption ) error {
97
+ return c .subresourceWriter .Create (ctx , obj , subresource , append ([]SubResourceCreateOption {c .validation }, opts ... )... )
99
98
}
100
99
101
- func (f * subresourceClientWithFieldValidation ) Update (ctx context.Context , obj Object , opts ... SubResourceUpdateOption ) error {
102
- return f .subresourceWriter .Update (ctx , obj , append ([]SubResourceUpdateOption {FieldValidation ( f .validation ) }, opts ... )... )
100
+ func (c * subresourceClientWithFieldValidation ) Update (ctx context.Context , obj Object , opts ... SubResourceUpdateOption ) error {
101
+ return c .subresourceWriter .Update (ctx , obj , append ([]SubResourceUpdateOption {c .validation }, opts ... )... )
103
102
}
104
103
105
- func (f * subresourceClientWithFieldValidation ) Patch (ctx context.Context , obj Object , patch Patch , opts ... SubResourcePatchOption ) error {
106
- return f .subresourceWriter .Patch (ctx , obj , patch , append ([]SubResourcePatchOption {FieldValidation ( f .validation ) }, opts ... )... )
104
+ func (c * subresourceClientWithFieldValidation ) Patch (ctx context.Context , obj Object , patch Patch , opts ... SubResourcePatchOption ) error {
105
+ return c .subresourceWriter .Patch (ctx , obj , patch , append ([]SubResourcePatchOption {c .validation }, opts ... )... )
107
106
}
0 commit comments