tumblr / k8s-sidecar-injector

Kubernetes sidecar injection service
Apache License 2.0
345 stars 75 forks source link

Fix #20, improve unit tests #21

Closed byxorna closed 5 years ago

byxorna commented 5 years ago

What and why?

Fixes #20

Ive also taken the opportunity to improve the unit test suite drastically, to allow for actual testing of the AdmissionRequest and AdmissionResponse.Patch field contents, so we can explicitly see exactly what the mutate() handler does :)

It should be very easy now to create a new test case by:

  1. create a AdmissionRequest in yaml at test/fixtures/k8s/admissioncontrol/request/foo.yaml
  2. create a Patch JSON at test/fixtures/k8s/admissioncontrol/patch/foo.json
  3. register your test in the pkg/server/webhook_test.go list mutationTests

It helpfully does proper JSON diffing so we can easily see how a patch fails, which will help with functionality like expecting the injector to not overwrite env vars that are already in the pod spec, etc.

Testing Steps

Reviewers

Required reviewers: @komapa @byxorna Request reviews from other people you want to review this PR in the "Reviewers" section on the right.

:warning: this PR must have at least 2 thumbs from the MAINTAINERS.md of the project before merging!

noahgoldman commented 5 years ago

Awesome! Thanks for getting back so quickly 😄