All Projects → slok → Kubewebhook

slok / Kubewebhook

Licence: apache-2.0
Go framework to create Kubernetes mutating and validating webhooks

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Kubewebhook

kube-code-generator
Kubernetes code generator docker image
Stars: ✭ 60 (-78.18%)
Mutual labels:  controller, k8s
Kooper
Kooper is a simple Go library to create Kubernetes operators and controllers.
Stars: ✭ 388 (+41.09%)
Mutual labels:  controller, k8s
Ingressmonitorcontroller
A Kubernetes controller to watch ingresses and create liveness alerts for your apps/microservices in UptimeRobot, StatusCake, Pingdom, etc. – [✩Star] if you're using it!
Stars: ✭ 306 (+11.27%)
Mutual labels:  controller, k8s
Kubernetes Pfsense Controller
Integrate Kubernetes and pfSense
Stars: ✭ 100 (-63.64%)
Mutual labels:  controller, k8s
Gardener
Kubernetes-native system managing the full lifecycle of conformant Kubernetes clusters as a service on Alicloud, AWS, Azure, GCP, OpenStack, EquinixMetal, vSphere, MetalStack, and Kubevirt with minimal TCO.
Stars: ✭ 2,093 (+661.09%)
Mutual labels:  controller, k8s
Apisix Ingress Controller
ingress controller for K8s
Stars: ✭ 139 (-49.45%)
Mutual labels:  controller, k8s
Lotus
Kubernetes controller for running load testing
Stars: ✭ 92 (-66.55%)
Mutual labels:  controller, k8s
carvel-secretgen-controller
secretgen-controller provides CRDs to specify what secrets need to be on Kubernetes cluster (to be generated or not)
Stars: ✭ 54 (-80.36%)
Mutual labels:  controller, k8s
bilrost
Kubernetes controller/operator to set up OAUTH2/OIDC security on any ingress based service
Stars: ✭ 17 (-93.82%)
Mutual labels:  controller, k8s
unity-gameplay-framework
A gameplay framework to simplify Unity development.
Stars: ✭ 30 (-89.09%)
Mutual labels:  controller
Azure Key Vault To Kubernetes
Azure Key Vault to Kubernetes (akv2k8s for short) makes it simple and secure to use Azure Key Vault secrets, keys and certificates in Kubernetes.
Stars: ✭ 253 (-8%)
Mutual labels:  controller
flekszible
Kubernetes resource/manifest file preprocessor, generator and manager.
Stars: ✭ 34 (-87.64%)
Mutual labels:  k8s
ESPressIoT
This project covers somewhat advances features for an espresso machine controller.
Stars: ✭ 31 (-88.73%)
Mutual labels:  controller
Csi S3
A Container Storage Interface for S3
Stars: ✭ 255 (-7.27%)
Mutual labels:  k8s
AMLeaksFinder
A small tool for automatically detecting the [controller, view memory leak] in the project. 一款用于自动检测项目中【控制器内存泄漏,View 内存泄漏】的小工具,支持 ObjC,Swift。
Stars: ✭ 89 (-67.64%)
Mutual labels:  controller
K8s Tew
Kubernetes - The Easier Way
Stars: ✭ 269 (-2.18%)
Mutual labels:  k8s
k8s-trigger-controller
External controller that trigger Kubernetes Deployments on ConfigMap or Secret changes
Stars: ✭ 47 (-82.91%)
Mutual labels:  controller
tichi
TiChi ☯️ contains the tidb community collaboration automation basic framework and tool set.
Stars: ✭ 36 (-86.91%)
Mutual labels:  k8s
Dragon Iss Docking Autopilot
Autopilot in Go for docking the SpaceX Dragon capsule in the simulator
Stars: ✭ 276 (+0.36%)
Mutual labels:  controller
Polyaxon
Machine Learning Platform for Kubernetes (MLOps tools for experimentation and automation)
Stars: ✭ 2,966 (+978.55%)
Mutual labels:  k8s

kubewebhook

kubewebhook Build Status Go Report Card GoDoc

master targets v2, if you are looking for v1, check this.

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

With Kubewebhook you can make validating and mutating webhooks in any version, fast, easy, and focusing mainly on the domain logic of the webhook itself.

Features

  • Ready for mutating and validating webhook kinds.
  • Abstracts webhook versioning (compatible with v1beta1 and v1).
  • Resource inference (compatible with CRDs and fallbacks to Unstructured).
  • Easy and testable API.
  • Simple, extensible and flexible.
  • Multiple webhooks on the same server.
  • Webhook metrics (RED) for Prometheus with Grafana dashboard included.
  • Supports warnings.

Getting started

Use github.com/slok/kubewebhook/v2 to import Kubewebhook v2.

func run() error {
    logger := &kwhlog.Std{Debug: true}

    // Create our mutator
    mt := kwhmutating.MutatorFunc(func(_ context.Context, _ *kwhmodel.AdmissionReview, obj metav1.Object) (*kwhmutating.MutatorResult, error) {
        pod, ok := obj.(*corev1.Pod)
        if !ok {
            return &kwhmutating.MutatorResult{}, 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 &kwhmutating.MutatorResult{MutatedObject: pod}, nil
    })

    // Create webhook.
    wh, err := kwhmutating.NewWebhook(kwhmutating.WebhookConfig{
        ID:      "pod-annotate",
        Mutator: mt,
        Logger:  logger,
    })
    if err != nil {
        return fmt.Errorf("error creating webhook: %w", err)
    }

    // Get HTTP handler from webhook.
    whHandler, err := kwhhttp.HandlerFor(kwhhttp.HandlerConfig{Webhook: wh, Logger: logger})
    if err != nil {
        return fmt.Errorf("error creating webhook handler: %w", err)
    }

    // Serve.
    logger.Infof("Listening on :8080")
    err = http.ListenAndServeTLS(":8080", cfg.certFile, cfg.keyFile, whHandler)
    if err != nil {
        return fmt.Errorf("error serving webhook: %w", err)
    }

    return nil

You can get more examples in here

Production ready example

This repository is a production ready webhook app: https://github.com/slok/k8s-webhook-example

It shows, different webhook use cases, app structure, testing domain logic, kubewebhook use case, how to deploy...

Static and dynamic webhooks

We have 2 kinds of webhooks:

  • Static: Common one, is a single resource type webhook.
  • Dynamic: Used when the same webhook act on multiple types, unknown types and/or is used for generic stuff (e.g labels).
    • To use this kind of webhook, don't set the type on the configuration or set to nil.
    • If a request for an unknown type is not known by the webhook libraries, it will fallback to runtime.Unstructured object type.
    • Very useful to manipulate multiple resources on the same webhook (e.g Deployments, Statfulsets).
    • CRDs are unknown types so they will fallback to runtime.Unstructured`.
    • If using CRDs, better use Static webhooks.
    • Very useful to maniputale any metadata based validation or mutations (e.g Labels, annotations...)

Compatibility matrix

The Kubernetes' version associated with Kubewebhook's versions means that this specific version is tested and supports the shown K8s version, however, this doesn't mean that doesn't work with other versions. Normally they work with multiple versions (e.g v1.18 and v1.19).

Kubewebhook version k8s version Supported admission reviews Support dynamic webhooks
v2.0 1.20 v1beta1, v1
v0.11 1.19 v1beta1
v0.10 1.18 v1beta1
v0.9 1.18 v1beta1
v0.8 1.17 v1beta1
v0.7 1.16 v1beta1
v0.6 1.15 v1beta1
v0.5 1.14 v1beta1
v0.4 1.13 v1beta1
v0.3 1.12 v1beta1
v0.2 1.11 v1beta1
v0.2 1.10 v1beta1

Documentation

You can access here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].