helpers

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package helpers offers functions to simplify dealing with kubernetes resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Pod       string
	Container string
	Command   []string
	Stdin     []byte
}

Command records the execution of a command in a Pod

type FakeHTTPClient added in v0.1.2

type FakeHTTPClient struct {
	Request  *http.Request
	Response *http.Response
	Err      error
}

FakeHTTPClient implement a fake HTTPClient that returns a fixed response. When invoked, it records the request it received

func (*FakeHTTPClient) Do added in v0.1.2

func (f *FakeHTTPClient) Do(req *http.Request) (*http.Response, error)

Do implements HTTPClient's Do method

type FakePodCommandExecutor

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

FakePodCommandExecutor mocks the execution of a command in a pod recording the command history and returning a predefined stdout, stderr, and error

func NewFakePodCommandExecutor

func NewFakePodCommandExecutor() *FakePodCommandExecutor

NewFakePodCommandExecutor creates a new instance of FakePodCommandExecutor with default attributes

func (*FakePodCommandExecutor) Exec

func (f *FakePodCommandExecutor) Exec(
	pod string,
	container string,
	cmd []string,
	stdin []byte,
) ([]byte, []byte, error)

Exec records the execution of a command and returns the pre-defined

func (*FakePodCommandExecutor) GetHistory

func (f *FakePodCommandExecutor) GetHistory() []Command

GetHistory returns the history of commands executed by the FakePodCommandExecutor

func (*FakePodCommandExecutor) SetResult

func (f *FakePodCommandExecutor) SetResult(stdout []byte, stderr []byte, err error)

SetResult sets the results to be returned for each invocation to the FakePodCommandExecutor

type Helpers

type Helpers interface {
	NamespaceHelper
	ServiceHelper
	PodHelper
}

Helpers offers Helper functions grouped by the objects they handle

func NewFakeHelper

func NewFakeHelper(client kubernetes.Interface, namespace string, executor *FakePodCommandExecutor) Helpers

NewFakeHelper creates a set of helpers on the default namespace

func NewHelper

func NewHelper(client kubernetes.Interface, config *rest.Config, namespace string) Helpers

NewHelper creates a set of helpers on the default namespace

type NamespaceHelper

type NamespaceHelper interface {
	// CreateRandomNamespace creates a namespace with a random name starting with
	// the provided prefix and returns its name
	CreateRandomNamespace(ctx context.Context, prefix string) (string, error)
}

NamespaceHelper defines helper methods for handling namespaces

type PodHelper

type PodHelper interface {
	// WaitPodRunning waits for the Pod to be running for up to given timeout and returns a boolean indicating
	// if the status was reached. If the pod is Failed returns error.
	WaitPodRunning(ctx context.Context, name string, timeout time.Duration) (bool, error)
	// Exec executes a non-interactive command described in options and returns the stdout and stderr outputs
	Exec(pod string, container string, command []string, stdin []byte) ([]byte, []byte, error)
	// AttachEphemeralContainer adds an ephemeral container to a running pod, waiting for up to
	// a given timeout until the container is running
	AttachEphemeralContainer(
		ctx context.Context,
		podName string,
		container corev1.EphemeralContainer,
		timeout time.Duration,
	) error
}

PodHelper defines helper methods for handling Pods

type ServiceClient added in v0.1.2

type ServiceClient interface {
	// Do executes the request to the service and returns the response
	// From the request only the URL path method, headers and body are considered
	Do(request *http.Request) (*http.Response, error)
}

ServiceClient is the minimal interface for executing HTTP requests Offers an interface similar to http.Client but only the Do method is supported It is used primarily to allow mocking the client in unit tests

type ServiceHelper

type ServiceHelper interface {
	// WaitServiceReady waits for the given service to have at least one endpoint available
	WaitServiceReady(ctx context.Context, service string, timeout time.Duration) error
	// GetServiceProxy returns a client for making HTTP requests to the service using api server's proxy
	GetServiceProxy(service string, port int) (ServiceClient, error)
}

ServiceHelper implements functions for dealing with services

type ServiceProxy added in v0.1.2

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

ServiceProxy implements the HTTPClient interface for making HTTP request to a service

func (*ServiceProxy) Do added in v0.1.2

func (c *ServiceProxy) Do(request *http.Request) (*http.Response, error)

Do implements the Do method from the ServiceClient interface

Jump to

Keyboard shortcuts

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