Categorygithub.com/goeuro/kubernetes-ingressify
modulepackage
0.0.1-snapshot
Repository: https://github.com/goeuro/kubernetes-ingressify.git
Documentation: pkg.go.dev

# README

kubernetes-ingressify

Latest Release Build Status Release Status Go Report Card codecov

This is a simple binary that watches kubernetes ingress rules, renders your template and calls your script. You can use this to generate ingress-based configuration for any backend router.

Why?

There are multiple kubernetes ingress controller implementations. Unfortunately they control both router implementation (how router is compiled, built, etc), behavior and configuration. Its not easy to extend them and add custom logic, e.g. adding custom modules or plugins on the router, custom annotations and routing features, overriding templates, etc. Different organizations have different traffic handling needs, and having a third-party ingress controller own everything is not possible in many scenarios. But at the same time, the cost of writing your own ingress controller is also quite high. This is an attempt to decouple router implementation from configuration and allow anyone to easily create their own ingress controllers.

Roadmap

  • Bootstrap
  • Poll ingress rules, templating and implementation
  • Release v0.1
  • Watch endpoint events, templating and implementation
  • Release v0.2
  • Documentation and examples

Usage

We have a special release called v0.0.1-snapshot which always reflects master build. Please go ahead and grab it: https://github.com/goeuro/kubernetes-ingressify/releases/tag/v0.0.1-snapshot

Create a configuration file:

# ingress.cfg
kubeconfig: <path to kubeconfig, leave it empty for in-cluster authentication>
in_template: <path to template, context provided to template will be documented, defaults to ingress.cfg.tpl>
out_file: <path to output file, defaults to ingress.cfg>
interval: <time between executions>, for field format refer to https://golang.org/pkg/time/#ParseDuration 
hooks:
  post-render:
    - script 1
    - script 2
    - ...
    - script n 

Run it:

kubernetes-ingressify -config ingress.cfg

For more usage details, please refer to the examples

Development

Use docker/docker-compose to develop. You don't need to have golang installed.

  • docker-compose build Builds image for development
  • docker-compose run --rm default /bin/bash Gives you a terminal inside the container, from where you can run go commands like:
    • bin/test.sh Runs all tests
    • gofmt -s -w . Fix code formatting
    • go run main.go Compiles and runs main
  • Adding dependencies:
    • catch-22: godep has issues, dep is alpha (not all libs support it) and glide is deprecated in favor of dep
    • We use Godep as the least working option, but it means slightly additional effort when adding dependencies
    • SSH into your container (as above) and follow https://github.com/tools/godep#add-a-dependency

# Functions

AsMap returns a generic map.
Asset loads and returns the asset for the given name.
AssetDir returns the file names below a certain directory embedded in the file by go-bindata.
AssetInfo loads and returns the asset info for the given name.
AssetNames returns the names of the assets.
AsSlice returns a generic list.
BuildFuncMap merges template.FuncMap's.
ExecHook executes an array of commands.
GetKubeClient creates a k8s client.
GroupByHost returns a map of IngressifyRule grouped by ir.Host.
GroupByPath returns a map of IngressifyRule grouped by ir.Path.
GroupBySvcNs returns a map of IngressifyRule grouped by ir.ServiceName + ir.Namespace.
MustAsset is like Asset but panics when Asset would return an error.
OrderByPathLen order the rules by Path length in ascending or descending order.
PrepareTemplate creates a template from `tmplpath` initialized with `withfuncs`.
ReadConfig is a helper function to read the config.
RenderTemplate renders the template and writes the output to `outpath`.
RestoreAsset restores an asset under the given directory.
RestoreAssets restores an asset under the given directory recursively.
ScrapeIngresses connects to k8s and retrieves ingresses rules for all the namespaces.
ToIngressifyRule converts from *v1beta1.IngressList (normalized) to IngressifyRule (denormalized).

# Constants

PORT is the port.
REFRESHINTERVAL is the cache expiration time in seconds.

# Structs

Config represents the structure of the config file.
Hook is a struct that contains the pre-render and post-render scripts to be executed.
ICxt holds data used for rendering.
IngressifyRule is a denormalization of the Ingresses rules coming from k8s.
OpsStatus holds information to track failures/success of render and execHooks functions this information gets bubbled up to the health check.

# Type aliases

IngRules is just an alias to be able to implement custom sorting.