kubernetes

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MiniKubeIPEnvVar is the environment variable name which will have Minikube node IP.
	MiniKubeIPEnvVar = "DAPR_TEST_MINIKUBE_IP"

	// ContainerLogPathEnvVar is the environment variable name which will have the container logs.
	ContainerLogPathEnvVar = "DAPR_CONTAINER_LOG_PATH"

	// ContainerLogDefaultPath.
	ContainerLogDefaultPath = "./container_logs"

	// PollInterval is how frequently e2e tests will poll for updates.
	PollInterval = 1 * time.Second
	// PollTimeout is how long e2e tests will wait for resource updates when polling.
	PollTimeout = 10 * time.Minute
)
View Source
const (
	// TestAppLabelKey is the label key for Kubernetes label selector.
	TestAppLabelKey = "testapp"
	// DaprSideCarName is the Pod name of Dapr side car.
	DaprSideCarName = "daprd"

	// DefaultContainerPort is the default container port exposed from test app.
	DefaultContainerPort = 3000
	// DefaultExternalPort is the default external port exposed by load balancer ingress.
	DefaultExternalPort = 3000

	// DaprComponentsKind is component kind.
	DaprComponentsKind = "components.dapr.io"

	// DaprTestNamespaceEnvVar is the environment variable for setting the Kubernetes namespace for e2e tests.
	DaprTestNamespaceEnvVar = "DAPR_TEST_NAMESPACE"

	// Environment variable for setting Kubernetes node affinity OS.
	TargetOsEnvVar = "TARGET_OS"

	// Environment variable for setting Kubernetes node affinity ARCH.
	TargetArchEnvVar = "TARGET_ARCH"
)

Variables

View Source
var (
	// DaprTestNamespace is the default Kubernetes namespace for e2e tests.
	DaprTestNamespace = "dapr-tests"

	// TargetOs is default os affinity for Kubernetes nodes.
	TargetOs = "linux"

	// TargetArch is the default architecture affinity for Kubernetes nodes.
	TargetArch = "amd64"
)

Functions

This section is empty.

Types

type AppDescription

type AppDescription struct {
	AppName           string
	AppPort           int
	AppProtocol       string
	AppEnv            map[string]string
	DaprEnabled       bool
	ImageName         string
	ImageSecret       string
	RegistryName      string
	Replicas          int32
	IngressEnabled    bool
	MetricsEnabled    bool // This controls the setting for the dapr.io/enable-metrics annotation
	MetricsPort       string
	Config            string
	AppCPULimit       string
	AppCPURequest     string
	AppMemoryLimit    string
	AppMemoryRequest  string
	DaprCPULimit      string
	DaprCPURequest    string
	DaprMemoryLimit   string
	DaprMemoryRequest string
	Namespace         *string
	IsJob             bool
}

AppDescription holds the deployment information of test app.

type AppManager

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

AppManager holds Kubernetes clients and namespace used for test apps and provides the helpers to manage the test apps.

func NewAppManager

func NewAppManager(kubeClients *KubeClient, namespace string, app AppDescription) *AppManager

NewAppManager creates AppManager instance.

func (*AppManager) AcquireExternalURL

func (m *AppManager) AcquireExternalURL() string

AcquireExternalURL gets external ingress endpoint from service when it is ready.

func (*AppManager) AcquireExternalURLFromService

func (m *AppManager) AcquireExternalURLFromService(svc *apiv1.Service) string

AcquireExternalURLFromService gets external url from Service Object.

func (*AppManager) App added in v0.3.0

func (m *AppManager) App() AppDescription

App returns app description.

func (*AppManager) CreateIngressService

func (m *AppManager) CreateIngressService() (*apiv1.Service, error)

CreateIngressService creates Ingress endpoint for test app.

func (*AppManager) DeleteDeployment

func (m *AppManager) DeleteDeployment(ignoreNotFound bool) error

DeleteDeployment deletes deployment for the test app.

func (*AppManager) DeleteJob added in v1.1.0

func (m *AppManager) DeleteJob(ignoreNotFound bool) error

DeleteJob deletes job for the test app.

func (*AppManager) DeleteService

func (m *AppManager) DeleteService(ignoreNotFound bool) error

DeleteService deletes deployment for the test app.

func (*AppManager) Deploy

func (m *AppManager) Deploy() (*appsv1.Deployment, error)

Deploy deploys app based on app description.

func (*AppManager) Dispose

func (m *AppManager) Dispose(wait bool) error

Dispose deletes deployment and service.

func (*AppManager) DoPortForwarding added in v0.4.0

func (m *AppManager) DoPortForwarding(podName string, targetPorts ...int) ([]int, error)

DoPortForwarding performs port forwarding for given podname to access test apps in the cluster.

func (*AppManager) GetCPUAndMemory added in v1.0.0

func (m *AppManager) GetCPUAndMemory(sidecar bool) (int64, float64, error)

GetCPUAndMemory returns the Cpu and Memory usage for the dapr app or sidecar.

func (*AppManager) GetHostDetails added in v0.8.0

func (m *AppManager) GetHostDetails() ([]PodInfo, error)

GetHostDetails returns the name and IP address of the pods running the app.

func (*AppManager) GetOrCreateNamespace

func (m *AppManager) GetOrCreateNamespace() (*apiv1.Namespace, error)

GetOrCreateNamespace gets or creates namespace unless namespace exists.

func (*AppManager) GetTotalRestarts added in v1.0.0

func (m *AppManager) GetTotalRestarts() (int, error)

GetTotalRestarts returns the total number of restarts for the app or sidecar.

func (*AppManager) Init

func (m *AppManager) Init() error

Init installs app by AppDescription.

func (*AppManager) IsDeploymentDeleted

func (m *AppManager) IsDeploymentDeleted(deployment *appsv1.Deployment, err error) bool

IsDeploymentDeleted returns true if deployment does not exist or current pod replica is zero.

func (*AppManager) IsDeploymentDone

func (m *AppManager) IsDeploymentDone(deployment *appsv1.Deployment, err error) bool

IsDeploymentDone returns true if deployment object completes pod deployments.

func (*AppManager) IsJobCompleted added in v1.1.0

func (m *AppManager) IsJobCompleted(job *batchv1.Job, err error) bool

IsJobCompleted returns true if job object is complete.

func (*AppManager) IsJobDeleted added in v1.1.0

func (m *AppManager) IsJobDeleted(job *batchv1.Job, err error) bool

IsJobDeleted returns true if job does not exist.

func (*AppManager) IsServiceDeleted

func (m *AppManager) IsServiceDeleted(svc *apiv1.Service, err error) bool

IsServiceDeleted returns true if service does not exist.

func (*AppManager) IsServiceIngressReady

func (m *AppManager) IsServiceIngressReady(svc *apiv1.Service, err error) bool

IsServiceIngressReady returns true if external ip is available.

func (*AppManager) Name

func (m *AppManager) Name() string

Name returns app name.

func (*AppManager) ScaleDeploymentReplica added in v0.3.0

func (m *AppManager) ScaleDeploymentReplica(replicas int32) error

ScaleDeploymentReplica scales the deployment.

func (*AppManager) ScheduleJob added in v1.1.0

func (m *AppManager) ScheduleJob() (*batchv1.Job, error)

ScheduleJob deploys job based on app description.

func (*AppManager) SetAppEnv added in v1.3.0

func (m *AppManager) SetAppEnv(key, value string) error

SetAppEnv sets an environment variable.

func (*AppManager) StreamContainerLogs added in v1.2.0

func (m *AppManager) StreamContainerLogs() error

SaveContainerLogs get container logs for all containers in the pod and saves them to disk.

func (*AppManager) ValidateSidecar added in v1.1.0

func (m *AppManager) ValidateSidecar() error

ValidateSidecar validates that dapr side car is running in dapr enabled pods.

func (*AppManager) WaitUntilDeploymentState

func (m *AppManager) WaitUntilDeploymentState(isState func(*appsv1.Deployment, error) bool) (*appsv1.Deployment, error)

WaitUntilDeploymentState waits until isState returns true.

func (*AppManager) WaitUntilJobState added in v1.1.0

func (m *AppManager) WaitUntilJobState(isState func(*batchv1.Job, error) bool) (*batchv1.Job, error)

WaitUntilJobState waits until isState returns true.

func (*AppManager) WaitUntilServiceState

func (m *AppManager) WaitUntilServiceState(isState func(*apiv1.Service, error) bool) (*apiv1.Service, error)

WaitUntilServiceState waits until isState returns true.

func (*AppManager) WaitUntilSidecarPresent added in v1.1.0

func (m *AppManager) WaitUntilSidecarPresent() error

WaitUntilSidecarPresent waits until Dapr sidecar is present.

type ComponentDescription added in v0.3.0

type ComponentDescription struct {
	// Name is the name of dapr component
	Name string
	// Namespace to deploy the component to
	Namespace *string
	// Type contains component types (<type>.<component_name>)
	TypeName string
	// MetaData contains the metadata for dapr component
	MetaData map[string]string
}

ComponentDescription holds dapr component description.

type DaprComponent added in v0.3.0

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

DaprComponent holds kubernetes client and component information.

func NewDaprComponent added in v0.3.0

func NewDaprComponent(client *KubeClient, ns string, comp ComponentDescription) *DaprComponent

NewDaprComponent creates DaprComponent instance.

func (*DaprComponent) Dispose added in v0.3.0

func (do *DaprComponent) Dispose(wait bool) error

func (*DaprComponent) Init added in v0.3.0

func (do *DaprComponent) Init() error

func (*DaprComponent) Name added in v0.3.0

func (do *DaprComponent) Name() string

type KubeClient

type KubeClient struct {
	ClientSet     kubernetes.Interface
	MetricsClient metrics.Interface
	DaprClientSet daprclient.Interface
	// contains filtered or unexported fields
}

KubeClient holds instances of Kubernetes clientset TODO: Add cluster management methods to clean up the old test apps.

func NewKubeClient

func NewKubeClient(configPath string, clusterName string) (*KubeClient, error)

NewKubeClient creates KubeClient instance.

func (*KubeClient) DaprComponents added in v0.3.0

func (c *KubeClient) DaprComponents(namespace string) componentsv1alpha1.ComponentInterface

DaprComponents gets Dapr component client for namespace.

func (*KubeClient) Deployments

func (c *KubeClient) Deployments(namespace string) appv1.DeploymentInterface

Deployments gets Deployment client for namespace.

func (*KubeClient) GetClientConfig added in v0.4.0

func (c *KubeClient) GetClientConfig() *rest.Config

GetClientConfig returns client configuration.

func (*KubeClient) Jobs added in v1.1.0

func (c *KubeClient) Jobs(namespace string) batchv1.JobInterface

Jobs gets Jobs client for namespace.

func (*KubeClient) Namespaces

func (c *KubeClient) Namespaces() apiv1.NamespaceInterface

Namespaces gets Namespace client.

func (*KubeClient) Pods

func (c *KubeClient) Pods(namespace string) apiv1.PodInterface

Pods gets Pod client for namespace.

func (*KubeClient) Services

func (c *KubeClient) Services(namespace string) apiv1.ServiceInterface

Services gets Service client for namespace.

type PodInfo added in v1.0.0

type PodInfo struct {
	Name string
	IP   string
}

PodInfo holds information about a given pod.

type PodPortForwarder added in v0.8.0

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

PodPortFowarder implements the PortForwarder interface for Kubernetes.

func NewPodPortForwarder added in v0.8.0

func NewPodPortForwarder(c *KubeClient, namespace string) *PodPortForwarder

NewPodPortForwarder returns a new PodPortForwarder.

func (*PodPortForwarder) Close added in v0.8.0

func (p *PodPortForwarder) Close() error

func (*PodPortForwarder) Connect added in v0.8.0

func (p *PodPortForwarder) Connect(name string, targetPorts ...int) ([]int, error)

Connect establishes a new connection to a given app on the provided target ports.

type PortForwardRequest added in v0.4.0

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

PortForwardRequest encapsulates data required to establish a Kuberentes tunnel.

Jump to

Keyboard shortcuts

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