File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
staging/src/k8s.io/apiserver/pkg/admission/plugin/policy/mutating Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import (
27
27
k8serrors "k8s.io/apimachinery/pkg/api/errors"
28
28
"k8s.io/apimachinery/pkg/api/meta"
29
29
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
30
31
"k8s.io/apimachinery/pkg/runtime/schema"
31
32
"k8s.io/apimachinery/pkg/types"
32
33
"k8s.io/apiserver/pkg/admission"
@@ -249,9 +250,20 @@ func (d *dispatcher) dispatchOne(
249
250
return err
250
251
}
251
252
253
+ switch versionedAttributes .VersionedObject .(type ) {
254
+ case * unstructured.Unstructured :
255
+ // No conversion needed before defaulting for the patch object if the admitted object is unstructured.
256
+ default :
257
+ // Before defaulting, if the admitted object is a typed object, convert unstructured patch result back to a typed object.
258
+ newVersionedObject , err = o .GetObjectConvertor ().ConvertToVersion (newVersionedObject , versionedAttributes .GetKind ().GroupVersion ())
259
+ if err != nil {
260
+ return err
261
+ }
262
+ }
263
+ o .GetObjectDefaulter ().Default (newVersionedObject )
264
+
252
265
versionedAttributes .Dirty = true
253
266
versionedAttributes .VersionedObject = newVersionedObject
254
- o .GetObjectDefaulter ().Default (newVersionedObject )
255
267
return nil
256
268
}
257
269
You can’t perform that action at this time.
0 commit comments