Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

admission: introduce Service/Ingress validation + mutation #8

Merged
merged 8 commits into from
Jan 22, 2019

Conversation

pires
Copy link
Contributor

@pires pires commented Jan 22, 2019

This PR introduces a mutating admission webhook to dklb. This admission webhook is called whenever an Ingress or Service resource is created/updated and is responsible for performing validation of such resources, as well as injecting defaults for all the annotations supported by dklb. This means that the creation of a Service resource such as

apiVersion: v1
kind: Service
metadata:
  annotations:
        kubernetes.dcos.io/edgelb-pool-name: "__invalid__"
(...)

will be rejected upfront by kubectl:

$ kubectl create svc invalid
Error from server (InternalError): error when creating "STDIN": Internal error occurred: admission webhook "dklb.kubernetes.dcos.io" denied the request: "*" is not valid as an edgelb pool name

It also means that a Service resource created as

apiVersion: v1
kind: Service
metadata:
  annotations:
        kubernetes.dcos.io/edgelb-pool-role: '*'
(...)

will be mutated by the admission webhook in order to look like this after creation:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kubernetes.dcos.io/edgelb-pool-cpus: 100m
    kubernetes.dcos.io/edgelb-pool-mem: 128Mi
    kubernetes.dcos.io/edgelb-pool-name: dev--kubernetes02--default--redis
    kubernetes.dcos.io/edgelb-pool-network: dcos
    kubernetes.dcos.io/edgelb-pool-portmap.6379: "6379"
    kubernetes.dcos.io/edgelb-pool-role: '*'
    kubernetes.dcos.io/edgelb-pool-size: "1"
(...)

Registration of the admission webhook is performed automatically by dklb, but can be disabled via feature gate shall the webhook ever prove to cause problems or be buggy.
The TLS material required to register and serve the webhook is sourced from the mke-cluster-info configmap and from the dklb-tls secret recently introduced to the kubernetes-cluster package. Hence, the only action required by users/testers right now is to update their MKE clusters to the latest nightly build.

@pires pires added the feature New feature or request label Jan 22, 2019
@pires pires requested a review from bmcustodio January 22, 2019 20:45
Copy link
Contributor

@bmcustodio bmcustodio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - this looks really, really good!

@bmcustodio bmcustodio merged commit 600c0ce into master Jan 22, 2019
@bmcustodio bmcustodio deleted the pires/admission_webhook branch January 22, 2019 20:48
@pires
Copy link
Contributor Author

pires commented Jan 22, 2019

Pairing is awesome 🙇

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants