apiserver/pkg/admission
Dmitry Rozhkov d51f943047 fix field removal in mutating admission webhooks
A mutating admission controller webhook doesn't remove object fields
when instructed to.

E.g. when the JSON patch

  [
    {"op": "remove", "path": "/spec/containers/0/resources/limits/fpga-arria10"},
    {"op": "add", "path": "/spec/containers/0/resources/limits/fpga-interface-id-524abcf", "value": 1}
  ]

is applied to this pod

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  restartPolicy: Never
  containers:
    -
      name: test-pod-container
      image: ubuntu:bionic
      imagePullPolicy: IfNotPresent
      command: [ "ls", "-l", "/" ]
      resources:
        limits:
          fpga-arria10: 1

in order to replace the resource name "fpga-arria10" with something understandable
by the device plugin the resulting pod spec still contains the old field plus
a new one. The resulting pod looks like

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  restartPolicy: Never
  containers:
    -
      name: test-pod-container
      image: ubuntu:bionic
      imagePullPolicy: IfNotPresent
      command: [ "ls", "-l", "/" ]
      resources:
        limits:
          fpga-arria10: 1
          fpga-interface-id-524abcf: 1

The patch unmarshals patched JSON into a new empty object instead of
existing one. Otherwise JSON unmarshaling reuses existing maps, keeping
existing entries as specified in the "encoding/json" standard package.

Kubernetes-commit: 4a72e17bd227b79ed89981735691af3601043bf9
2018-05-23 16:57:54 +03:00
..
configuration sync: initially remove files BUILD */BUILD BUILD.bazel */BUILD.bazel 2018-03-15 09:38:17 +00:00
initializer sync: initially remove files BUILD */BUILD BUILD.bazel */BUILD.bazel 2018-03-15 09:38:17 +00:00
metrics sync: initially remove files BUILD */BUILD BUILD.bazel */BUILD.bazel 2018-03-15 09:38:17 +00:00
plugin fix field removal in mutating admission webhooks 2018-05-23 16:57:54 +03:00
attributes.go support AddAnnotation in admission attributes 2018-03-22 15:20:31 +08:00
attributes_test.go support AddAnnotation in admission attributes 2018-03-22 15:20:31 +08:00
audit.go add WithAudit admission decorator 2018-04-13 18:27:08 +08:00
audit_test.go add WithAudit admission decorator 2018-04-13 18:27:08 +08:00
chain.go admission: make metrics compositional and move to metrics sub-package 2017-11-17 11:49:55 +01:00
chain_test.go admission: make metrics compositional and move to metrics sub-package 2017-11-17 11:49:55 +01:00
config.go remove unused function negotiate() and writeYAML() 2018-02-23 14:53:51 +08:00
config_test.go remove duplicated import 2018-01-11 19:15:11 +08:00
decorator.go add an admission decorator chain 2018-02-14 09:27:25 -05:00
errors.go make admission tolerate object without objectmeta for errors 2017-08-29 13:13:06 +00:00
errors_test.go make admission tolerate object without objectmeta for errors 2017-08-29 13:13:06 +00:00
handler.go refactor admission handler and add UT 2017-11-03 16:40:15 +08:00
handler_test.go refactor admission handler and add UT 2017-11-03 16:40:15 +08:00
interfaces.go support AddAnnotation in admission attributes 2018-03-22 15:20:31 +08:00
plugins.go log enabled admission controller in order 2018-03-10 16:20:12 +08:00