kubewebhook

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2018 License: Apache-2.0

README

kubewebhook

kubewebhook Build Status Go Report Card GoDoc

Kubewebhook is a small Go framework to create external admission webhooks for Kubernetes.

With Kubewebhook you can make validating and mutating webhooks very fast and focusing mainly on the domain logic of the webhook itself.

Features

  • Ready for mutating and validating webhook kinds.
  • Easy and testable API.
  • Simple, extensible and flexible.
  • Multiple webhooks on the same server.
  • Webhook metrics (RED) for Prometheus with Grafana dashboard included.

Status

At this moment the project is being tested on production but not ready to mark as production-ready, that's why there is no release yet.

Example

Here is a simple example of mutating webhook that will add mutated=true and mutator=pod-annotate annotations.

func main() {
    logger := &log.Std{Debug: true}

    cfg := initFlags()

    // Create our mutator
    mt := mutatingwh.MutatorFunc(func(_ context.Context, obj metav1.Object) (bool, error) {
        pod, ok := obj.(*corev1.Pod)
        if !ok {
            // If not a pod just continue the mutation chain(if there is one) and don't do nothing.
            return false, nil
        }

        // Mutate our object with the required annotations.
        if pod.Annotations == nil {
            pod.Annotations = make(map[string]string)
        }
        pod.Annotations["mutated"] = "true"
        pod.Annotations["mutator"] = "pod-annotate"

        return false, nil
    })

    wh, err := mutatingwh.NewStaticWebhook(mt, &corev1.Pod{}, logger)
    if err != nil {
        fmt.Fprintf(os.Stderr, "error creating webhook: %s", err)
        os.Exit(1)
    }

    // Get the handler for our webhook.
    whHandler := whhttp.HandlerFor(wh)
    logger.Infof("Listening on :8080")
    err = http.ListenAndServeTLS(":8080", cfg.certFile, cfg.keyFile, whHandler)
    if err != nil {
        fmt.Fprintf(os.Stderr, "error serving webhook: %s", err)
        os.Exit(1)
    }
}

You can get more examples in here

Compatibility matrix

Kubernetes 1.10 Kubernetes 1.11
kubewebhook 0.1 ?
kubewebhook HEAD ?+

Documentation

Directories

Path Synopsis
examples
Package mocks will have all the mocks of the library, we'll try to use mocking using blackbox testing and integration tests whenever is possible.
Package mocks will have all the mocks of the library, we'll try to use mocking using blackbox testing and integration tests whenever is possible.
observability/metrics
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0
webhook
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0
webhook/mutating
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0
webhook/validating
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0
pkg
log

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL