Coder Social home page Coder Social logo

tekton-admission-wehook's Introduction

tekton-webhook-admission-webhook

This is a webhook admission webhook that adds validation for Tekton pipelines and tasks.

Installation

This project can fully run locally and includes automation to deploy a local Kubernetes cluster (using Minkikube).

Requirements

  • Docker
  • kubectl
  • minikube
  • Go >=1.19

Usage

Create Cluster

First, we need to create a Kubernetes cluster:

โฏ minikube start

๐Ÿ”ง Creating Kubernetes cluster...
๐Ÿ˜„  minikube v1.30.1 on Darwin 13.6 (arm64)
๐ŸŽ‰  minikube 1.31.2 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.31.2
๐Ÿ’ก  To disable this notice, run: 'minikube config set WantUpdateNotification false'

โœจ  Using the docker driver based on existing profile
๐Ÿ‘  Starting control plane node minikube in cluster minikube
๐Ÿšœ  Pulling base image ...
๐Ÿคท  docker "minikube" container is missing, will recreate.
๐Ÿ”ฅ  Creating docker container (CPUs=2, Memory=7803MB) ...

๐Ÿณ  Preparing Kubernetes v1.26.3 on Docker 23.0.2 ...

๐Ÿ”—  Configuring bridge CNI (Container Networking Interface) ...
๐Ÿ”Ž  Verifying Kubernetes components...
    โ–ช Using image gcr.io/k8s-minikube/storage-provisioner:v5
๐ŸŒŸ  Enabled addons: storage-provisioner, default-storageclass
๐Ÿ„  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Make sure that the Kubernetes node is ready:

โฏ kubectl get nodes
NAME                 STATUS   ROLES                  AGE     VERSION
minikube             Ready    control-plane,master   3m25s   v1.26.3

And that system pods are running happily:

โฏ kubectl -n kube-system get pods
NAME                                         READY   STATUS    RESTARTS   AGE
coredns-558bd4d5db-thwvj                     1/1     Running   0          3m39s
etcd-minikube                                1/1     Running   0          3m56s
kube-apiserver-minikube                      1/1     Running   0          3m54s
kube-controller-manager-minikube             1/1     Running   0          3m56s
kube-proxy-4h6sj                             1/1     Running   0          3m40s
kube-scheduler-minikube                      1/1     Running   0          3m54s

Deploy Admission Webhook

To configure the cluster to use the admission webhook and to deploy said webhook, simply run:

โฏ make deploy

๐Ÿ“ฆ Building tekton-webhook Docker image...
docker build -t tekton-webhook:latest .
[+] Building 14.3s (13/13) FINISHED
...

๐Ÿ“ฆ Pushing admission-webhook image into Minikube's Docker daemon...
minikube image load tekton-webhook:latest

โš™๏ธ  Applying cluster config...
kubectl apply -f dev/manifests/cluster-config/
namespace/apps created
mutatingwebhookconfiguration.admissionregistration.k8s.io/tekton.webhook.config created
validatingwebhookconfiguration.admissionregistration.k8s.io/tekton.webhook.config created

๐Ÿš€ Deploying tekton-webhook...
kubectl apply -f dev/manifests/webhook/
deployment.apps/tekton-webhook created
service/tekton-webhook created
secret/tekton-webhook-tls created

Then, make sure the admission webhook pod is running (in the default namespace):

โฏ kubectl get pods
NAME                                        READY   STATUS    RESTARTS   AGE
tekton-webhook-77444566b7-wzwmx   1/1     Running   0          2m21s

You can stream logs from it:

โฏ make logs

๐Ÿ” Streaming tekton-webhook logs...
kubectl logs -l app=tekton-webhook -f
time="2021-09-03T04:59:10Z" level=info msg="Listening on port 443..."
time="2021-09-03T05:02:21Z" level=debug msg=healthy uri=/health

And hit it's health endpoint from your local machine:

โฏ curl -k https://localhost:8443/health
OK

Deploying tasks

Deploy a valid task that gets successfully created:

โฏ make valid-task

๐Ÿš€ Deploying valid pod...
kubectl apply -f dev/manifests/tasks/valid-task.yaml
tasks/valid-task created

You should see in the admission webhook logs that the task was validated and created.

Deploy an invalid task that gets rejected:

โฏ make invalid-task

๐Ÿš€ Deploying "invalid" task...
kubectl apply -f dev/manifests/tasks/invalid-task.yaml
Error from server: error when creating "dev/manifests/tasks/invalid-task.yaml": admission webhook "tekton.webhook.config" denied the request: pod name contains "offensive"

You should see in the admission webhook logs that the pod validation failed.

Admission Logic

A set of validations for pipelines and tasks are implemented in an extensible framework. Those happen on the fly when a pipeline/task is created and no further resources are tracked and updated (ie. no controller logic).

Validating Webhooks

Implemented

tekton-admission-wehook's People

Contributors

emmamunley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.