@@ -37,14 +37,14 @@ type CustomDefaulter interface {
3737}
3838
3939type defaulterOptions struct {
40- preserveUnknownFields bool
40+ removeUnknownFields bool
4141}
4242
4343type defaulterOption func (* defaulterOptions )
4444
45- // DefaulterPreserveUnknownFields stops the defaulter from pruning the fields that are not recognized in the local scheme.
46- func DefaulterPreserveUnknownFields (o * defaulterOptions ) {
47- o .preserveUnknownFields = true
45+ // DefaulterRemoveUnknownFields makes the defaulter prune the fields that are not recognized in the local scheme.
46+ func DefaulterRemoveUnknownFields (o * defaulterOptions ) {
47+ o .removeUnknownFields = true
4848}
4949
5050// WithCustomDefaulter creates a new Webhook for a CustomDefaulter interface.
@@ -54,15 +54,15 @@ func WithCustomDefaulter(scheme *runtime.Scheme, obj runtime.Object, defaulter C
5454 o (options )
5555 }
5656 return & Webhook {
57- Handler : & defaulterForType {object : obj , defaulter : defaulter , decoder : NewDecoder (scheme ), preserveUnknownFields : options .preserveUnknownFields },
57+ Handler : & defaulterForType {object : obj , defaulter : defaulter , decoder : NewDecoder (scheme ), removeUnknownFields : options .removeUnknownFields },
5858 }
5959}
6060
6161type defaulterForType struct {
62- defaulter CustomDefaulter
63- object runtime.Object
64- decoder Decoder
65- preserveUnknownFields bool
62+ defaulter CustomDefaulter
63+ object runtime.Object
64+ decoder Decoder
65+ removeUnknownFields bool
6666}
6767
6868// Handle handles admission requests.
@@ -97,7 +97,7 @@ func (h *defaulterForType) Handle(ctx context.Context, req Request) Response {
9797
9898 // Keep a copy of the object if needed
9999 var originalObj runtime.Object
100- if h . preserveUnknownFields {
100+ if ! h . removeUnknownFields {
101101 originalObj = obj .DeepCopyObject ()
102102 }
103103
@@ -117,7 +117,7 @@ func (h *defaulterForType) Handle(ctx context.Context, req Request) Response {
117117 }
118118
119119 handlerResponse := PatchResponseFromRaw (req .Object .Raw , marshalled )
120- if h . preserveUnknownFields {
120+ if ! h . removeUnknownFields {
121121 handlerResponse = h .dropSchemeRemovals (handlerResponse , originalObj , req .Object .Raw )
122122 }
123123 return handlerResponse
0 commit comments