k8sfunctions

package
v0.0.0-...-23d10c9 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2020 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Namespace

func Namespace() string

Namespace This function returns the namespace of the running pod

func NewDeploymentHandlerForK8sconfig

func NewDeploymentHandlerForK8sconfig(c interface{}, ns string,
	proxies *ProxyMap, metric *PMetric) cache.ResourceEventHandlerFuncs

NewDeploymentHandlerForK8sconfig This function creates a new deployment handler. It will watch for deployments in k8s with the desired annotations and create (delete) the corresponding proxy. It is possible to have more than one Deployment in a namespace, but they should have different app annotations and different ports. This handler implements the actions of the DeploymentController.

func NewMetaDeploymentHandlerForK8sconfig

func NewMetaDeploymentHandlerForK8sconfig(c interface{}, ns string,
	proxies *ProxyMap, metric *PMetric) cache.ResourceEventHandlerFuncs

NewMetaDeploymentHandlerForK8sconfig This function creates a new handler for the meta data of Deployments. It will only watch for updates of the meta data. It does basically the same job as the handler for the Deployment, but enables the change of parameters while the application is running. This handler implements the actions of the DeploymentMetaController.

func NewPodHandlerForServerlist

func NewPodHandlerForServerlist(proxy *ProxyForDeployment, maxtickets int) cache.ResourceEventHandlerFuncs

NewPodHandlerForServerlist This function creates the PodHandler for a given Proxy. The handler will only handle the specific Serverlist of this Proxy. It will create the servers in the Serverlist based on the running Pods. It will also modify them or delete them if the Pod was modified. This handler implements the actions of the podController and triggers the UpdatePodMetric method.

func PodToConfig

func PodToConfig(pod *v1.Pod) (proxyfunctions.Config, error)

PodToConfig This function reads the k8sTicket annotations and creates a config for the reverse proxy.

Types

type Controller

type Controller struct {
	Clientset interface{} //*kubernetes.Clientset
	Factory   interface{} //informers.SharedInformerFactory
	//We need interfaces here because metadatainformer and infomers
	//are still in different libraries providing different methods.
	//Maybe the implementation will change in the future to a common lib
	Informer cache.SharedInformer
	Stopper  chan struct{}
}

Controller This struct includes all components of the Controller It has a clientset, a Informer.SharedInformerFactory, the Informer that was created by the Factory and a Channel stop the informer.

func NewDeploymentController

func NewDeploymentController(ns string) Controller

NewDeploymentController This function creates a new Deployment controller for a proxy with a hardcoded InClusterConfig and a given namespace to watch. It will inform k8sTicket about creation, deletion or updates of running Deployments. This controller is a major component because k8sTicket will retrieve its configuration from the Deployments.

func NewDeploymentMetaController

func NewDeploymentMetaController(ns string) Controller

NewDeploymentMetaController This function creates a new controller for the meta data of Deployments. In that way it is a kind of extension of the DeploymentController which only listens for Deployments themselves. This controlller handels the updates of Annotations and Labels.

func NewPodController

func NewPodController(clientset kubernetes.Interface, ns string, app string) *Controller

NewPodController This function creates a new Pod controller for a proxy with a kubernetes.Clientset and a given namespace to watch. It will inform k8sTicket about creation, deletion or updates of running Pods for the parameter app.

type PMetric

type PMetric struct {
	CurrentUsers       *prometheus.GaugeVec
	CurrentFreeTickets *prometheus.GaugeVec
	CurrentScaledPods  *prometheus.GaugeVec
	TotalUsers         *prometheus.CounterVec
}

PMetric This struct defines our exported metrics. We export the current users, the available Tickets, the scaled Pods and a counter for all served users.

func NewPMetric

func NewPMetric() PMetric

NewPMetric This function defines the metrics from the PMetric struct. We will label each value with the Prefix (application name).

type ProxyForDeployment

type ProxyForDeployment struct {
	Clientset  *kubernetes.Clientset
	Serverlist *proxyfunctions.Serverlist

	Stopper chan struct{}
	// contains filtered or unexported fields
}

ProxyForDeployment This struct includes everything needed for running the ticket proxy for one deployment. It is the essiential structure of k8sTicket.

func NewProxyForDeployment

func NewProxyForDeployment(clienset *kubernetes.Clientset, prefix string, ns string,
	port string, maxTickets int, spareTickets int, maxPods int, cooldown int,
	podspec v1.PodTemplateSpec, metric *PMetric, dns bool) *ProxyForDeployment

NewProxyForDeployment The main idea of the k8sTicket structure is that every Deployment is one application that should be delivered with the proxy. For this reason all components are tied together in this structure.

func (*ProxyForDeployment) Start

func (proxy *ProxyForDeployment) Start()

Start This method starts a proxy. That includes the http handler as well as the necessary methods and functions to manage tickets. Furthermore, k8s informers are started to watch the events in the cluster.

func (*ProxyForDeployment) Stop

func (proxy *ProxyForDeployment) Stop()

Stop This method stops a proxy including the http server and all running routines and infomers.

func (*ProxyForDeployment) UpdateAccessMetric

func (proxy *ProxyForDeployment) UpdateAccessMetric(informer chan string)

UpdateAccessMetric This method uses the Serverlists ability to export informer channels to inform external functions. The metrics are updated whenever a new server or a new Ticket are registered or when a Ticket/server is removed.

func (*ProxyForDeployment) UpdatePodMetric

func (proxy *ProxyForDeployment) UpdatePodMetric()

UpdatePodMetric This method is called in the PodHandler to update the metric about new or deleted autoscaled Pods by k8sTicket

type ProxyMap

type ProxyMap struct {
	Deployments map[string]*ProxyForDeployment
	Mux         sync.Mutex
}

ProxyMap This is a map with a mux that stores the ProxyForDeployments. The mux is used by the Informers when adding or deleting (updating) a ProxyForDeployment instance.

func NewProxyMap

func NewProxyMap() *ProxyMap

NewProxyMap Creates a new ProxyMap with initialized ProxyForDeployment map.

Jump to

Keyboard shortcuts

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