kubernetes

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 39 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 = 8 * 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"

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

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

	// Environmental variable to disable API logging
	DisableAPILoggingEnvVar = "NO_API_LOGGING"

	// Environmental variable to enable debug logging
	DebugLoggingEnvVar = "DEBUG_LOGGING"
)

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"

	// Controls whether API logging is enabled
	EnableAPILogging = true

	// Controls whether debug logging is enabled
	EnableDebugLogging = false
)

Functions

func StreamContainerLogsToDisk added in v1.10.0

func StreamContainerLogsToDisk(ctx context.Context, appName string, podClient v1.PodInterface) error

StreamContainerLogsToDisk streams all containers logs for the given selector to a given disk directory.

Types

type AppDescription

type AppDescription struct {
	AppName                   string                          `json:",omitempty"`
	AppPort                   int                             `json:",omitempty"`
	AppProtocol               string                          `json:",omitempty"`
	AppEnv                    map[string]string               `json:",omitempty"`
	AppVolumeMounts           []apiv1.VolumeMount             `json:",omitempty"`
	DaprEnabled               bool                            `json:",omitempty"`
	DebugLoggingEnabled       bool                            `json:",omitempty"`
	ImageName                 string                          `json:",omitempty"`
	ImageSecret               string                          `json:",omitempty"`
	SidecarImage              string                          `json:",omitempty"`
	RegistryName              string                          `json:",omitempty"`
	Replicas                  int32                           `json:",omitempty"`
	IngressEnabled            bool                            `json:",omitempty"`
	IngressPort               int                             `json:",omitempty"` // Defaults to AppPort if empty
	MetricsEnabled            bool                            `json:",omitempty"` // This controls the setting for the dapr.io/enable-metrics annotation
	MetricsPort               string                          `json:",omitempty"`
	Config                    string                          `json:",omitempty"`
	AppCPULimit               string                          `json:",omitempty"`
	AppCPURequest             string                          `json:",omitempty"`
	AppMemoryLimit            string                          `json:",omitempty"`
	AppMemoryRequest          string                          `json:",omitempty"`
	DaprCPULimit              string                          `json:",omitempty"`
	DaprCPURequest            string                          `json:",omitempty"`
	DaprMemoryLimit           string                          `json:",omitempty"`
	DaprMemoryRequest         string                          `json:",omitempty"`
	DaprEnv                   string                          `json:",omitempty"`
	UnixDomainSocketPath      string                          `json:",omitempty"`
	Namespace                 *string                         `json:",omitempty"`
	IsJob                     bool                            `json:",omitempty"`
	SecretStoreDisable        bool                            `json:",omitempty"`
	DaprVolumeMounts          string                          `json:",omitempty"`
	Labels                    map[string]string               `json:",omitempty"` // Adds custom labels to pods
	PodAffinityLabels         map[string]string               `json:",omitempty"` // If set, adds a podAffinity rule matching those labels
	Tolerations               []apiv1.Toleration              `json:",omitempty"` // If set, adds tolerations to the pod
	NodeSelectors             []apiv1.NodeSelectorRequirement `json:",omitempty"` // If set, adds additional node selector requirements to the pod (note that os/arch are set automatically)
	Volumes                   []apiv1.Volume                  `json:",omitempty"`
	InitContainers            []apiv1.Container               `json:",omitempty"`
	PluggableComponents       []apiv1.Container               `json:",omitempty"`
	InjectPluggableComponents bool                            `json:",omitempty"`
	PlacementAddresses        []string                        `json:",omitempty"`
	EnableAppHealthCheck      bool                            `json:",omitempty"`
	AppHealthCheckPath        string                          `json:",omitempty"`
	AppHealthProbeInterval    int                             `json:",omitempty"` // In seconds
	AppHealthProbeTimeout     int                             `json:",omitempty"` // In milliseconds
	AppHealthThreshold        int                             `json:",omitempty"`
	AppChannelAddress         string                          `json:",omitempty"`
	MaxRequestSizeMB          int                             `json:",omitempty"`
}

AppDescription holds the deployment information of test app.

func (AppDescription) MarshalJSON added in v1.7.0

func (a AppDescription) MarshalJSON() ([]byte, error)

func (AppDescription) ShouldBeExposed added in v1.9.0

func (a AppDescription) ShouldBeExposed() bool

ShouldBeExposed returns if the app should be exposed as a loadbalancer/nodeport service.

func (AppDescription) String added in v1.7.0

func (a AppDescription) String() string

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(client *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 service 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) 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(runCtx context.Context) 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

StreamContainerLogs 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(svcName string, 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]MetadataValue
	// Scopes is the list of target apps that should use this component
	Scopes []string
	// ContainerAsJSON is used for pluggable components
	ContainerAsJSON 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(ctx context.Context) 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 MetadataValue added in v1.10.0

type MetadataValue struct {
	Raw           string
	FromSecretRef *SecretRef
}

MetadataValue is either a raw string value or a secret ref

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.

type Secret added in v1.12.0

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

Secret holds kubernetes client and component information.

func NewSecret added in v1.12.0

func NewSecret(client *KubeClient, ns, name string, data map[string][]byte) *Secret

NewSecret creates Secret instance.

func (*Secret) Dispose added in v1.12.0

func (s *Secret) Dispose(wait bool) error

func (*Secret) Init added in v1.12.0

func (s *Secret) Init(ctx context.Context) error

func (*Secret) Name added in v1.12.0

func (s *Secret) Name() string

type SecretDescription added in v1.12.0

type SecretDescription struct {
	Name      string
	Namespace string
	Data      map[string][]byte
}

type SecretRef added in v1.10.0

type SecretRef struct {
	Name string
	Key  string
}

SecretRef is a reference to a secret

Jump to

Keyboard shortcuts

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