server

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 30 Imported by: 3

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

View Source
const (
	// DefaultDebugPort default debug port of the workload clusters mux.
	DefaultDebugPort = 19000

	// DefaultMinPort default min port of the workload clusters mux.
	DefaultMinPort = 20000
	// DefaultMaxPort default max port of the workload clusters mux.
	DefaultMaxPort = 24000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomPorts

type CustomPorts struct {
	MinPort   int
	MaxPort   int
	DebugPort int
}

CustomPorts allows to customize the ports used by the workload clusters mux.

func (CustomPorts) Apply

func (c CustomPorts) Apply(options *WorkloadClustersMuxOptions)

Apply applies this configuration to the given WorkloadClustersMuxOptions.

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.WithWatch, 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.

func (*WorkloadClusterListener) ResourceGroup

func (s *WorkloadClusterListener) ResourceGroup() string

ResourceGroup returns the resource group that hosts in memory resources 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 inmemoryruntime.Manager, host string, opts ...WorkloadClustersMuxOption) (*WorkloadClustersMux, error)

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) DeleteAPIServer

func (m *WorkloadClustersMux) DeleteAPIServer(wclName, podName string) error

DeleteAPIServer removes an API server instance from the WorkloadClusterListener.

func (*WorkloadClustersMux) DeleteEtcdMember

func (m *WorkloadClustersMux) DeleteEtcdMember(wclName, podName string) error

DeleteEtcdMember removes an etcd Member from the WorkloadClusterListener.

func (*WorkloadClustersMux) DeleteWorkloadClusterListener

func (m *WorkloadClustersMux) DeleteWorkloadClusterListener(wclName string) error

DeleteWorkloadClusterListener deletes a WorkloadClusterListener.

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.InMemoryClusterList) error

HotRestart tries to set up the mux according to an existing set of InMemoryClusters. 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) RegisterResourceGroup

func (m *WorkloadClustersMux) RegisterResourceGroup(wclName, resourceGroup string) error

RegisterResourceGroup registers the resource group that host in memory resources for a WorkloadClusterListener.

func (*WorkloadClustersMux) ResourceGroupByWorkloadCluster

func (m *WorkloadClustersMux) ResourceGroupByWorkloadCluster(wclName string) (string, error)

ResourceGroupByWorkloadCluster returns the resource group that host in memory resources for a WorkloadClusterListener.

func (*WorkloadClustersMux) Shutdown

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

Shutdown shuts down the workload cluster mux.

func (*WorkloadClustersMux) WorkloadClusterByResourceGroup

func (m *WorkloadClustersMux) WorkloadClusterByResourceGroup(resouceGroup string) (string, error)

WorkloadClusterByResourceGroup returns the WorkloadClusterListener that serves resources from a given resource.

type WorkloadClustersMuxOption

type WorkloadClustersMuxOption interface {
	Apply(*WorkloadClustersMuxOptions)
}

WorkloadClustersMuxOption define an option for the WorkloadClustersMux creation.

type WorkloadClustersMuxOptions

type WorkloadClustersMuxOptions struct {
	MinPort   int
	MaxPort   int
	DebugPort int
}

WorkloadClustersMuxOptions are options for the workload clusters mux.

func (*WorkloadClustersMuxOptions) ApplyOptions

ApplyOptions applies WorkloadClustersMuxOption to the current WorkloadClustersMuxOptions.

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