internal

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: LGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIServerDefaultArgs = []string{
	"--advertise-address=0.0.0.0",
	"--bind-address=0.0.0.0",
	"--etcd-servers={{ if .EtcdURL }}{{ .EtcdURL.String }}{{ end }}",
	"--cert-dir={{ .CertDir }}",
	"--insecure-port={{ if .URL }}{{ .URL.Port }}{{ end }}",
	"--insecure-bind-address={{ if .URL }}{{ .URL.Hostname }}{{ end }}",
	"--secure-port={{ if .SecurePort }}{{ .SecurePort }}{{ end }}",
	"--disable-admission-plugins=ServiceAccount",
	"--service-cluster-ip-range=10.10.0.0/24",
	"--allow-privileged=true",
}

APIServerDefaultArgs allow tests to run offline, by preventing API server from attempting to use default route to determine its --advertise-address.

View Source
var EtcdDefaultArgs = []string{
	"--listen-peer-urls=http://localhost:0",
	"--advertise-client-urls={{ if .URL }}{{ .URL.String }}{{ end }}",
	"--listen-client-urls={{ if .URL }}{{ .URL.String }}{{ end }}",
	"--data-dir={{ .DataDir }}",
}

EtcdDefaultArgs allow tests to run offline, by preventing API server from attempting to use default route to determine its urls.

Functions

func DoAPIServerArgDefaulting

func DoAPIServerArgDefaulting(args []string) []string

DoAPIServerArgDefaulting will set default values to allow tests to run offline when the args are not informed. Otherwise, it will return the same []string arg passed as param.

func DoEtcdArgDefaulting

func DoEtcdArgDefaulting(args []string) []string

DoEtcdArgDefaulting will set default values to allow tests to run offline when the args are not informed. Otherwise, it will return the same []string arg passed as param.

func GetEtcdStartMessage

func GetEtcdStartMessage(listenURL url.URL) string

GetEtcdStartMessage returns an start message to inform if the client is or not insecure. It will return true when the URL informed has the scheme == "https" || scheme == "unixs"

func RenderTemplates

func RenderTemplates(argTemplates []string, data interface{}) (args []string, err error)

RenderTemplates returns an []string to render the templates

Types

type APIServer

type APIServer struct {
	// URL is the address the ApiServer should listen on for client connections.
	//
	// If this is not specified, we default to a random free port on localhost.
	URL *url.URL

	// SecurePort is the additional secure port that the APIServer should listen on.
	SecurePort int

	// Path is the path to the apiserver binary.
	//
	// If this is left as the empty string, we will attempt to locate a binary,
	// by checking for the TEST_ASSET_KUBE_APISERVER environment variable, and
	// the default test assets directory. See the "Binaries" section above (in
	// doc.go) for details.
	Path string

	// Args is a list of arguments which will passed to the APIServer binary.
	// Before they are passed on, they will be evaluated as go-template strings.
	// This means you can use fields which are defined and exported on this
	// APIServer struct (e.g. "--cert-dir={{ .Dir }}").
	// Those templates will be evaluated after the defaulting of the APIServer's
	// fields has already happened and just before the binary actually gets
	// started. Thus you have access to calculated fields like `URL` and others.
	//
	// If not specified, the minimal set of arguments to run the APIServer will
	// be used.
	Args []string

	// CertDir is a path to a directory containing whatever certificates the
	// APIServer will need.
	//
	// If left unspecified, then the Start() method will create a fresh temporary
	// directory, and the Stop() method will clean it up.
	CertDir string

	// EtcdURL is the URL of the Etcd the APIServer should use.
	//
	// If this is not specified, the Start() method will return an error.
	EtcdURL *url.URL

	// StartTimeout, StopTimeout specify the time the APIServer is allowed to
	// take when starting and stoppping before an error is emitted.
	//
	// If not specified, these default to 20 seconds.
	StartTimeout time.Duration
	StopTimeout  time.Duration

	// Out, Err specify where APIServer should write its StdOut, StdErr to.
	//
	// If not specified, the output will be discarded.
	Out io.Writer
	Err io.Writer
	// contains filtered or unexported fields
}

APIServer knows how to run a kubernetes apiserver.

func (*APIServer) Start

func (s *APIServer) Start() error

Start starts the apiserver, waits for it to come up, and returns an error, if occurred.

func (*APIServer) Stop

func (s *APIServer) Stop() error

Stop stops this process gracefully, waits for its termination, and cleans up the CertDir if necessary.

type CertPair

type CertPair struct {
	Key  crypto.Signer
	Cert *x509.Certificate
}

CertPair is a private key and certificate for use for client auth, as a CA, or serving.

func (CertPair) AsBytes

func (k CertPair) AsBytes() (cert []byte, key []byte, err error)

AsBytes encodes keypair in the appropriate formats for on-disk storage (PEM and PKCS8, respectively).

func (CertPair) CertBytes

func (k CertPair) CertBytes() []byte

CertBytes returns the PEM-encoded version of the certificate for this pair.

type ControlPlane

type ControlPlane struct {
	APIServer *APIServer
	Etcd      *Etcd
}

ControlPlane is a struct that knows how to start your test control plane.

Right now, that means Etcd and your APIServer. This is likely to increase in future.

func (*ControlPlane) APIURL

func (f *ControlPlane) APIURL() *url.URL

APIURL returns the URL you should connect to to talk to your API.

func (*ControlPlane) RESTClientConfig

func (f *ControlPlane) RESTClientConfig() (*rest.Config, error)

RESTClientConfig returns a pre-configured restconfig, ready to connect to this ControlPlane.

func (*ControlPlane) Start

func (f *ControlPlane) Start() error

Start will start your control plane processes. To stop them, call Stop().

func (*ControlPlane) Stop

func (f *ControlPlane) Stop() error

Stop will stop your control plane processes, and clean up their data.

type DefaultedProcessInput

type DefaultedProcessInput struct {
	URL              url.URL
	Dir              string
	DirNeedsCleaning bool
	Path             string
	StopTimeout      time.Duration
	StartTimeout     time.Duration
}

DefaultedProcessInput defines the default process input required to perform the test.

func DoDefaulting

func DoDefaulting(
	name string,
	listenURL *url.URL,
	dir string,
	path string,
	startTimeout time.Duration,
	stopTimeout time.Duration,
) (DefaultedProcessInput, error)

DoDefaulting sets the default configuration according to the data informed and return an DefaultedProcessInput and an error if some requirement was not informed.

type Etcd

type Etcd struct {
	// URL is the address the Etcd should listen on for client connections.
	//
	// If this is not specified, we default to a random free port on localhost.
	URL *url.URL

	// Path is the path to the etcd binary.
	//
	// If this is left as the empty string, we will attempt to locate a binary,
	// by checking for the TEST_ASSET_ETCD environment variable, and the default
	// test assets directory. See the "Binaries" section above (in doc.go) for
	// details.
	Path string

	// Args is a list of arguments which will passed to the Etcd binary. Before
	// they are passed on, the`y will be evaluated as go-template strings. This
	// means you can use fields which are defined and exported on this Etcd
	// struct (e.g. "--data-dir={{ .Dir }}").
	// Those templates will be evaluated after the defaulting of the Etcd's
	// fields has already happened and just before the binary actually gets
	// started. Thus you have access to calculated fields like `URL` and others.
	//
	// If not specified, the minimal set of arguments to run the Etcd will be
	// used.
	Args []string

	// DataDir is a path to a directory in which etcd can store its state.
	//
	// If left unspecified, then the Start() method will create a fresh temporary
	// directory, and the Stop() method will clean it up.
	DataDir string

	// StartTimeout, StopTimeout specify the time the Etcd is allowed to
	// take when starting and stopping before an error is emitted.
	//
	// If not specified, these default to 20 seconds.
	StartTimeout time.Duration
	StopTimeout  time.Duration

	// Out, Err specify where Etcd should write its StdOut, StdErr to.
	//
	// If not specified, the output will be discarded.
	Out io.Writer
	Err io.Writer
	// contains filtered or unexported fields
}

Etcd knows how to run an etcd server.

func (*Etcd) Start

func (e *Etcd) Start() error

Start starts the etcd, waits for it to come up, and returns an error, if one occoured.

func (*Etcd) Stop

func (e *Etcd) Stop() error

Stop stops this process gracefully, waits for its termination, and cleans up the DataDir if necessary.

type ProcessState

type ProcessState struct {
	DefaultedProcessInput
	Session *gexec.Session
	// Healthcheck Endpoint. If we get http.StatusOK from this endpoint, we
	// assume the process is ready to operate. E.g. "/healthz". If this is set,
	// we ignore StartMessage.
	HealthCheckEndpoint string
	// HealthCheckPollInterval is the interval which will be used for polling the
	// HealthCheckEndpoint.
	// If left empty it will default to 100 Milliseconds.
	HealthCheckPollInterval time.Duration
	// StartMessage is the message to wait for on stderr. If we receive this
	// message, we assume the process is ready to operate. Ignored if
	// HealthCheckEndpoint is specified.
	//
	// The usage of StartMessage is discouraged, favour HealthCheckEndpoint
	// instead!
	//
	// Deprecated: Use HealthCheckEndpoint in favour of StartMessage
	StartMessage string
	Args         []string
	// contains filtered or unexported fields
}

ProcessState define the state of the process.

func (*ProcessState) Start

func (ps *ProcessState) Start(stdout, stderr io.Writer) (err error)

Start starts the apiserver, waits for it to come up, and returns an error, if occurred.

func (*ProcessState) Stop

func (ps *ProcessState) Stop() error

Stop stops this process gracefully, waits for its termination, and cleans up the CertDir if necessary.

type TinyCA

type TinyCA struct {
	CA CertPair
	// contains filtered or unexported fields
}

TinyCA supports signing serving certs and client-certs, and can be used as an auth mechanism with envtest.

func NewTinyCA

func NewTinyCA() (*TinyCA, error)

NewTinyCA creates a new a tiny CA utility for provisioning serving certs and client certs FOR TESTING ONLY. Don't use this for anything else!

func (*TinyCA) NewServingCert

func (c *TinyCA) NewServingCert() (CertPair, error)

NewServingCert returns a new CertPair for a serving HTTPS on localhost.

Jump to

Keyboard shortcuts

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