clientsholder

package
v0.0.0-...-9c8cfac Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func ClearTestClientsHolder

func ClearTestClientsHolder()

func GetClientConfigFromRestConfig

func GetClientConfigFromRestConfig(restConfig *rest.Config) *clientcmdapi.Config

Creates a clientcmdapi.Config object from a rest.Config. Based on https://github.com/kubernetes/client-go/issues/711#issuecomment-1666075787

func SetTestK8sClientsHolder

func SetTestK8sClientsHolder(k8sClient kubernetes.Interface)

func SetupFakeOlmClient

func SetupFakeOlmClient(olmMockObjects []runtime.Object)

SetupFakeOlmClient Overrides the OLM client with the fake interface object for unit testing. Loads the mocking objects so olmv interface methods can find them.

Types

type ClientsHolder

type ClientsHolder struct {
	RestConfig            *rest.Config
	DynamicClient         dynamic.Interface
	ScalingClient         scale.ScalesGetter
	APIExtClient          apiextv1.Interface
	OlmClient             olmClient.Interface
	OlmPkgClient          olmpkgclient.OperatorsV1Interface
	OcpClient             clientconfigv1.ConfigV1Interface
	K8sClient             kubernetes.Interface
	K8sNetworkingClient   networkingv1.NetworkingV1Interface
	CNCFNetworkingClient  cncfNetworkAttachmentv1.Interface
	SriovNetworkingClient sriovNetworkOp.SriovnetworkV1Interface
	DiscoveryClient       discovery.DiscoveryInterface
	MachineCfg            ocpMachine.Interface
	KubeConfig            []byte

	GroupResources  []*metav1.APIResourceList
	ApiserverClient apiserverscheme.Interface
	// contains filtered or unexported fields
}

func GetClientsHolder

func GetClientsHolder(filenames ...string) *ClientsHolder

GetClientsHolder returns the singleton ClientsHolder object.

func GetNewClientsHolder

func GetNewClientsHolder(kubeconfigFile string) *ClientsHolder

func GetTestClientsHolder

func GetTestClientsHolder(k8sMockObjects []runtime.Object) *ClientsHolder

GetTestClientHolder Overwrites the existing clientholders with a mocked version for unit testing. Only pure k8s interfaces will be available. The runtime objects must be pure k8s ones. For other (OLM, ) runtime mocking objects loading, use the proper clientset mocking function.

func (*ClientsHolder) ExecCommandContainer

func (clientsholder *ClientsHolder) ExecCommandContainer(
	ctx Context, command string) (stdout, stderr string, err error)

ExecCommand runs command in the pod and returns buffer output.

type Command

type Command interface {
	ExecCommandContainer(Context, string) (string, string, error)
}

type CommandMock

type CommandMock struct {
	// ExecCommandContainerFunc mocks the ExecCommandContainer method.
	ExecCommandContainerFunc func(context Context, s string) (string, string, error)
	// contains filtered or unexported fields
}

CommandMock is a mock implementation of Command.

func TestSomethingThatUsesCommand(t *testing.T) {

	// make and configure a mocked Command
	mockedCommand := &CommandMock{
		ExecCommandContainerFunc: func(context Context, s string) (string, string, error) {
			panic("mock out the ExecCommandContainer method")
		},
	}

	// use mockedCommand in code that requires Command
	// and then make assertions.

}

func (*CommandMock) ExecCommandContainer

func (mock *CommandMock) ExecCommandContainer(context Context, s string) (string, string, error)

ExecCommandContainer calls ExecCommandContainerFunc.

func (*CommandMock) ExecCommandContainerCalls

func (mock *CommandMock) ExecCommandContainerCalls() []struct {
	Context Context
	S       string
}

ExecCommandContainerCalls gets all the calls that were made to ExecCommandContainer. Check the length with:

len(mockedCommand.ExecCommandContainerCalls())

type Context

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

func NewContext

func NewContext(namespace, podName, containerName string) Context

func (*Context) GetContainerName

func (c *Context) GetContainerName() string

func (*Context) GetNamespace

func (c *Context) GetNamespace() string

func (*Context) GetPodName

func (c *Context) GetPodName() string

Jump to

Keyboard shortcuts

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