builders

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package builders offers functions for building test objects

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientBuilder added in v0.3.6

type ClientBuilder interface {
	// returns an instance of a fake.Clientset.
	Build() (*fake.Clientset, error)
	// WithObjects initializes the client with the given runtime.Objects
	WithObjects(objs ...runtime.Object) ClientBuilder
	// WithNamespace initializes the client with the given namespace
	WithNamespace(namespace string) ClientBuilder
	// WithPods initializes the client with the given Pods
	WithPods(pods ...corev1.Pod) ClientBuilder
	// WithServices initializes the client with the given Services
	WithServices(pods ...corev1.Service) ClientBuilder
	// WithPodObserver adds a PodObserver that receives notifications of specific events
	WithPodObserver(namespace string, event ObjectEvent, observer PodObserver) ClientBuilder
	// WithContext sets a context allows cancelling object observers
	WithContext(ctx context.Context) ClientBuilder
	// WithErrorChannel sets a channel for reporting errors from observers
	WithErrorChannel(chan error) ClientBuilder
}

ClientBuilder defines a fluent API for configuring a fake client for testing

func NewClientBuilder added in v0.3.6

func NewClientBuilder() ClientBuilder

NewClientBuilder returns a ClientBuilder

type ContainerBuilder added in v0.3.2

type ContainerBuilder interface {
	// WithPort adds a port to the container
	WithPort(name string, port int32) ContainerBuilder
	// WithImage sets the container's image
	WithImage(image string) ContainerBuilder
	// WithPullPolicy sets the container's image pull policy (default is IfNotPresent)
	WithPullPolicy(policy corev1.PullPolicy) ContainerBuilder
	// WithCommand sets the container's command
	WithCommand(cmd ...string) ContainerBuilder
	// WithCapabilites adds capabilities to the container's security context
	WithCapabilities(capabilities ...corev1.Capability) ContainerBuilder
	// Build returns a Pod with the attributes defined in the PodBuilder
	Build() corev1.Container
	// WithEnvVarFromField adds an environment variable to the container
	WithEnvVar(name string, value string) ContainerBuilder
	// WithEnvVarFromField adds an environment variable to the container referencing a field
	// Example: "PodName", "metadata.name"
	WithEnvVarFromField(name string, path string) ContainerBuilder
}

ContainerBuilder defines the methods for building a Container

func NewContainerBuilder added in v0.3.2

func NewContainerBuilder(name string) ContainerBuilder

NewContainerBuilder returns a new ContainerBuilder

type EndpointsBuilder added in v0.2.1

type EndpointsBuilder interface {
	// WithNamespace sets namespace for the pod to be built
	WithNamespace(namespace string) EndpointsBuilder
	// WithSubset adds a subset to the Endpoints
	WithSubset(name string, port int32, pods []string) EndpointsBuilder
	// WithNotReadyAddresses adds a subset with not ready addresses
	WithNotReadyAddresses(name string, port int32, pods []string) EndpointsBuilder
	// Build builds the Endpoints
	Build() corev1.Endpoints
	// BuildAsPtr builds the Endpoints and returns as a pointer
	BuildAsPtr() *corev1.Endpoints
}

EndpointsBuilder defines the methods for building a service EndPoints

func NewEndPointsBuilder added in v0.2.1

func NewEndPointsBuilder(service string) EndpointsBuilder

NewEndPointsBuilder creates a new EndpointsBuilder for a given service

type IngressBuilder added in v0.3.2

type IngressBuilder interface {
	// WithNamespace sets the namespace for the ingres
	WithNamespace(namespace string) IngressBuilder
	// WithClass sets the ingress class
	WithClass(class string) IngressBuilder
	// WithHost sets the host for the ingress rule
	WithHost(host string) IngressBuilder
	// WithPath sets the path for the ingress
	WithPath(path string) IngressBuilder
	// WithAnnotations add annotations to the Ingress
	WithAnnotation(key, value string) IngressBuilder
	// WithAddress sets the ingress loadbalancer address
	WithAddress(addr string) IngressBuilder
	// Build returns the Ingress
	Build() networking.Ingress
	// BuildAsPtr returns a reference to the Ingress
	BuildAsPtr() *networking.Ingress
}

IngressBuilder defines the interface for building Ingresses for a service backend

func NewIngressBuilder added in v0.3.2

func NewIngressBuilder(service string, port intstr.IntOrString) IngressBuilder

NewIngressBuilder creates a new IngressBuilder for a given serviceBackend

type ObjectEvent added in v0.3.6

type ObjectEvent string

ObjectEvent defines an event in an object

const (
	// ObjectEventAll subscribe to all object events
	ObjectEventAll ObjectEvent = "ALL"
	// ObjectEventAdded subscribe to object creation events
	ObjectEventAdded ObjectEvent = "ADDED"
	// ObjectEventDeleted subscribe to object delete events
	ObjectEventDeleted ObjectEvent = "DELETED"
	// ObjectEventModified subscribe to object update events
	ObjectEventModified ObjectEvent = "MODIFIED"
)

type PodBuilder

type PodBuilder interface {
	// Build returns a Pod with the attributes defined in the PodBuilder
	Build() corev1.Pod
	// WithNamespace sets namespace for the pod to be built
	WithNamespace(namespace string) PodBuilder
	// WithDefaultNamespace sets namespace for the pod as "default"
	// By default, the Pod has no namespace set to allow overriding it when creating the resource in k8s
	WithDefaultNamespace() PodBuilder
	// WithLabels sets the labels to the pod (overrides any previously set labels)
	WithLabels(labels map[string]string) PodBuilder
	// WithLabel adds a label to the Pod
	WithLabel(name string, value string) PodBuilder
	// WithAnnotation adds an annotation
	WithAnnotation(name string, value string) PodBuilder
	// WithPhase sets the PodPhase for the pod to be built
	WithPhase(status corev1.PodPhase) PodBuilder
	// WithIP sets the IP address for the pod to be built
	WithIP(ip string) PodBuilder
	// WithHostNetwork sets the hostNetwork property of the pod to be built
	WithHostNetwork(hostNetwork bool) PodBuilder
	// WithContainer add a container to the pod
	WithContainer(c corev1.Container) PodBuilder
}

PodBuilder defines the methods for building a Pod

func NewPodBuilder

func NewPodBuilder(name string) PodBuilder

NewPodBuilder creates a new instance of PodBuilder with the given pod name and default attributes such as containers and namespace

type PodObserver added in v0.3.6

type PodObserver func(ObjectEvent, *corev1.Pod) (*corev1.Pod, bool, error)

PodObserver is a function that receives notifications of events on an Pod and can update it by returning a non-nil value. In addition, the PodObserver returns a boolean value indicating if it wants to keep receiving events or not.

Note: PodObserver that subscribe to update events should implement a mechanism for avoiding an update loop. They can for instance check the object is in a particular state before updating. Additionally, they can unsubscribe from further updates.

type ServiceBuilder

type ServiceBuilder interface {
	// Build returns a Service with the attributes defined in the ServiceBuilder
	Build() corev1.Service
	// BuildAsPtr returns a Service with the attributes defined in the ServiceBuilder as a pointer
	BuildAsPtr() *corev1.Service
	// WithNamespace sets namespace for the pod to be built
	WithNamespace(namespace string) ServiceBuilder
	// WithPorts sets the ports exposed by the service
	WithPorts(ports []corev1.ServicePort) ServiceBuilder
	// WithPort adds a port to the service
	WithPort(name string, port int32, target intstr.IntOrString) ServiceBuilder
	// WithSelector sets the service's selector labels (overrides any previously set label)
	WithSelector(labels map[string]string) ServiceBuilder
	// WithSelectorLabel adds a label to the service selector
	WithSelectorLabel(label string, value string) ServiceBuilder
	// WithServiceType sets the type of the service (default is NodePort)
	WithServiceType(t corev1.ServiceType) ServiceBuilder
	// WithAnnotation adds an annotation to the service
	WithAnnotation(key string, value string) ServiceBuilder
}

ServiceBuilder defines the methods for building a service

func NewServiceBuilder

func NewServiceBuilder(name string) ServiceBuilder

NewServiceBuilder creates a new instance of ServiceBuilder with the given pod name and default attributes

Jump to

Keyboard shortcuts

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