server

package
v0.0.0-...-2d9dd87 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package server implements a server that can be used to fake the APIServer and etcd running in the workload clusters; the implementation is designed specifically to make Cluster API and the Kubeadm Control Plane provider happy during a stress test (it is not complete or production ready, and it will never be).

There are many factors shaping the implementation.

  • The server has to be able to serve requests for many workload clusters.
  • The server has to serve all kind of requests CAPI core controllers and the kubeadm control plane controller are sending to workload clusters
  • Among those request there are also two port-forward requests, one targeting the kube-apiserver pods, the other the etcd pods generated by kubeadm. The server has to be able to act as a target for those requests too (it will port forward to itself).
  • The server needs to comply to the CAPI contract, e.g. the control plane endpoint is in the form of host:port, the port is allocated first but the server starts answering later when the first CP instance comes up etc.

The implementation is inspired from https://fideloper.com/golang-proxy-multiple-listeners (kudos to the author!), and it consists of a server that has support for multiplexing requests for many workload clusters, each one with its own host:port listener, to a single handler/backend implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WorkloadClusterListener

type WorkloadClusterListener struct {
	// contains filtered or unexported fields
}

WorkloadClusterListener represents a listener for a workload cluster.

func (*WorkloadClusterListener) Address

func (s *WorkloadClusterListener) Address() string

Address returns the address of a WorkloadClusterListener.

func (*WorkloadClusterListener) GetClient

func (s *WorkloadClusterListener) GetClient() (client.Client, error)

GetClient returns a client for a WorkloadClusterListener.

func (*WorkloadClusterListener) Host

func (s *WorkloadClusterListener) Host() string

Host returns the host of a WorkloadClusterListener.

func (*WorkloadClusterListener) HostPort

func (s *WorkloadClusterListener) HostPort() string

HostPort returns the host port of a WorkloadClusterListener.

func (*WorkloadClusterListener) Port

func (s *WorkloadClusterListener) Port() int

Port returns the port of a WorkloadClusterListener.

func (*WorkloadClusterListener) RESTConfig

func (s *WorkloadClusterListener) RESTConfig() (*rest.Config, error)

RESTConfig returns the rest config for a WorkloadClusterListener.

type WorkloadClustersMux

type WorkloadClustersMux struct {
	// contains filtered or unexported fields
}

WorkloadClustersMux implements a server that handles requests for multiple workload clusters. Each workload clusters will get its own listener, serving on a dedicated port, eg. wkl-cluster-1 >> :20000, wkl-cluster-2 >> :20001 etc. Each workload cluster will act both as API server and as etcd for the cluster; the WorkloadClustersMux is also responsible for handling certificates for each of the above use cases.

func NewWorkloadClustersMux

func NewWorkloadClustersMux(manager cmanager.Manager, host string) *WorkloadClustersMux

NewWorkloadClustersMux returns a WorkloadClustersMux that handles requests for multiple workload clusters.

func (*WorkloadClustersMux) AddAPIServer

func (m *WorkloadClustersMux) AddAPIServer(wclName, podName string, caCert *x509.Certificate, caKey *rsa.PrivateKey) error

AddAPIServer mimics adding an API server instance behind the WorkloadClusterListener. When the first API server instance is added the serving certificates and the admin certificate for tests are generated, and the listener is started.

func (*WorkloadClustersMux) AddEtcdMember

func (m *WorkloadClustersMux) AddEtcdMember(wclName, podName string, caCert *x509.Certificate, caKey *rsa.PrivateKey) error

AddEtcdMember mimics adding an etcd Member behind the WorkloadClusterListener; every etcd member gets a dedicated serving certificate, so it will be possible to serve port forward requests to a specific etcd pod/member.

func (*WorkloadClustersMux) HasAPIServer

func (m *WorkloadClustersMux) HasAPIServer(wclName, podName string) bool

HasAPIServer returns true if the workload cluster already has an apiserver with podName.

func (*WorkloadClustersMux) HasEtcdMember

func (m *WorkloadClustersMux) HasEtcdMember(wclName, podName string) bool

HasEtcdMember returns true if the workload cluster already has an etcd member with podName.

func (*WorkloadClustersMux) HotRestart

func (m *WorkloadClustersMux) HotRestart(clusters *infrav1.GoofyClusterList) error

HotRestart tries to set up the mux according to an existing set of GoofyClusters. NOTE: This is done at best effort in order to make iterative development workflows easier.

func (*WorkloadClustersMux) InitWorkloadClusterListener

func (m *WorkloadClustersMux) InitWorkloadClusterListener(wclName string) (*WorkloadClusterListener, error)

InitWorkloadClusterListener initialize a WorkloadClusterListener by reserving a port for it. Note: The listener will be started when the first API server will be added.

func (*WorkloadClustersMux) ListListeners

func (m *WorkloadClustersMux) ListListeners() map[string]string

ListListeners implements api.DebugInfoProvider.

func (*WorkloadClustersMux) Shutdown

func (m *WorkloadClustersMux) Shutdown(ctx context.Context) error

Shutdown shuts down the workload cluster mux.

Directories

Path Synopsis
api
Package api defines a set of Handlers to be used for implementing a fake API server, designed specifically to make Cluster API and the Kubeadm Control Plane provider happy during a stress test (it is not complete or production ready, and it will never be).
Package api defines a set of Handlers to be used for implementing a fake API server, designed specifically to make Cluster API and the Kubeadm Control Plane provider happy during a stress test (it is not complete or production ready, and it will never be).
portforward
Package portforward implements support for implementing a fake port forward service in the api.
Package portforward implements support for implementing a fake port forward service in the api.
Package etcd implements a fake etcd server, designed specifically to make Cluster API and the Kubeadm Control Plane provider happy during a stress test (it is not complete or production ready, and it will never be).
Package etcd implements a fake etcd server, designed specifically to make Cluster API and the Kubeadm Control Plane provider happy during a stress test (it is not complete or production ready, and it will never be).
Package proxy implements kubeadm proxy functionality.
Package proxy implements kubeadm proxy functionality.

Jump to

Keyboard shortcuts

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