handler

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2019 License: MIT Imports: 31 Imported by: 0

README

k8s-webhook-handler

The k8s-webhook-handler listens for (GitHub) webhooks and acts on various events

Event Handlers

DeleteEvent

On branch deletion and deletes all resources in a kubernetes cluster that have a label matching the repo name and are in a namespace matching the branch name. If there are no other objects with the given label key in the namespace, it also deletes the namespace and all remaining objects.

PushEvent

On push events, k8s-webhook-handler will checkout .ci/workflow.yaml from the repo the push was and submit it to the k8s api with the following annotations added:

  • k8s-webhook-handler.io/ref: event.Ref
  • k8s-webhook-handler.io/before: event.Before
  • k8s-webhook-handler.io/revision: event.HeadCommit.ID
  • k8s-webhook-handler.io/repo_name: event.Repo.FullName
  • k8s-webhook-handler.io/repo_url: event.Repo.GitURL
  • k8s-webhook-handler.io/repo_ssh: event.Repo.SSHURL

Binaries

  • cmd/webhook is the actual webhook handling server
  • cmd/reconciler iterates over all k8s namespaces and deletes all objects that are labeled for which there is no remote branch anymore.

Usage

Currently only github delete webhooks in json format are supported. Beside the manifests and templates in deploy/, a secret 'webhook-handler' with the following fields is expected:

  • GITHUB_TOKEN Personal Access Token for API access
  • WEBHOOK_SECRET Secret for validating the webhook

The value should match the "Secret" field in the GitHub webhook settings and can be created like this:

kubectl create secret generic k8s-ci --from-literal=GITHUB_SECRET=github-secret ...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGitHubClient added in v0.1.0

func NewGitHubClient(token, baseURL, uploadURL string) (*github.Client, error)

func NewKubernetesConfig added in v0.1.0

func NewKubernetesConfig(kubeconfig string) (config *rest.Config, err error)

Types

type DeleteHandler added in v0.1.0

type DeleteHandler struct {
	DryRun bool
	discovery.DiscoveryInterface
	dynamic.Interface
	v1.NamespaceInterface
	*kubernetes.Clientset
	SelectorKey string
	GitAddress  string
	// contains filtered or unexported fields
}

func NewDeleteHandler added in v0.1.0

func NewDeleteHandler(logger log.Logger, kconfig *rest.Config, selectorKey string, dryRun bool) (*DeleteHandler, error)

func (*DeleteHandler) APIResources added in v0.1.0

func (p *DeleteHandler) APIResources() ([]*metav1.APIResourceList, error)

func (*DeleteHandler) FindResources added in v0.1.0

func (p *DeleteHandler) FindResources(namespace string) ([]runtime.Unstructured, error)

func (*DeleteHandler) FindResourcesAll added in v0.1.0

func (p *DeleteHandler) FindResourcesAll() ([]runtime.Unstructured, error)

func (*DeleteHandler) Handle added in v0.1.0

func (p *DeleteHandler) Handle(_ context.Context, ev *github.DeleteEvent) (*handlerResponse, error)

func (*DeleteHandler) HandleResources added in v0.1.0

func (p *DeleteHandler) HandleResources(namespace string, selector labels.Selector, handler resourceHandlerFn) ([]metav1.Object, error)

func (*DeleteHandler) NewSelector added in v0.1.0

func (p *DeleteHandler) NewSelector(val string) (labels.Selector, error)

func (*DeleteHandler) PurgeBranchless added in v0.1.0

func (p *DeleteHandler) PurgeBranchless() error

type Handler added in v0.1.0

type Handler struct {
	*DeleteHandler
	*PushHandler
	// contains filtered or unexported fields
}

func NewGithubHookHandler added in v0.1.0

func NewGithubHookHandler(secret []byte, statsdClient *statsd.Statsd) *Handler

func (*Handler) ServeHTTP added in v0.1.0

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PushHandler added in v0.1.0

type PushHandler struct {
	dynamic.Interface
	*kubernetes.Clientset

	ResourcePath string
	Namespace    string
	meta.RESTMapper
	// contains filtered or unexported fields
}

func NewPushHandler added in v0.1.0

func NewPushHandler(logger log.Logger, kconfig *rest.Config, ghClient *github.Client) (*PushHandler, error)

func (*PushHandler) Handle added in v0.1.0

func (h *PushHandler) Handle(ctx context.Context, event *github.PushEvent) (*handlerResponse, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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