开源软件名称(OpenSource Name):slok/kubewebhook开源软件地址(OpenSource Url):https://github.com/slok/kubewebhook开源编程语言(OpenSource Language):Go 95.3%开源软件介绍(OpenSource Introduction):kubewebhookKubewebhook 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
Getting startedUse 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 exampleThis 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 webhooksWe have 2 kinds of webhooks:
Compatibility matrixThe 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
DocumentationYou can access here. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论