k8snetworkplumbingwg / net-attach-def-admission-controller

An admission controller to check resources as defined by the NPWG spec
Apache License 2.0
4 stars 15 forks source link

Detects if spec.config is in JSON format #37

Closed dougbtv closed 4 years ago

dougbtv commented 4 years ago

Detects if spec.config is in JSON format before trying to elements are added to struct

as reported in: https://bugzilla.redhat.com/show_bug.cgi?id=1782301

can be replicated (prior to this fix) with a net-attach-def such as:

apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: asdf-bad-config
spec:
  config: 'asdf'

Demonstration of the error in go playground here @ https://play.golang.org/p/aA7IIO-SBmk Demonstration of the fix @ https://play.golang.org/p/vuiJI7YCv9g

Also removes the errors.Wrap() in this section as some errors wouldn't be reported back to the admission review, such as:

Error from server: error when creating "def.yaml": admission webhook "net-attach-def-admission-controller-validating-config.k8s.io" denied the request without explanation

With that removed, we can get an error such as:

Error from server: error when creating "def.yaml": admission webhook "net-attach-def-admission-controller-validating-config.k8s.io" denied the request: configuration string is not in JSON format
s1061123 commented 4 years ago

Looks good to me, so let me merge it. Thank you for the fix!