Documentation ¶
Overview ¶
Package k8s provides common functionalities for interacting with a Kubernetes cluster in the context of infrastructure testing.
Index ¶
- func AreAllNodesReady(t *testing.T) bool
- func AreAllNodesReadyE(t *testing.T) (bool, error)
- func CreateNamespace(t *testing.T, options *KubectlOptions, namespaceName string)
- func CreateNamespaceE(t *testing.T, options *KubectlOptions, namespaceName string) error
- func DeleteConfigContextE(t *testing.T, contextName string) error
- func DeleteConfigContextWithPathE(t *testing.T, kubeConfigPath string, contextName string) error
- func DeleteNamespace(t *testing.T, options *KubectlOptions, namespaceName string)
- func DeleteNamespaceE(t *testing.T, options *KubectlOptions, namespaceName string) error
- func GetKubeConfigPathE(t *testing.T) (string, error)
- func GetKubernetesClientE(t *testing.T) (*kubernetes.Clientset, error)
- func GetKubernetesClientFromOptionsE(t *testing.T, options *KubectlOptions) (*kubernetes.Clientset, error)
- func GetNamespace(t *testing.T, options *KubectlOptions, namespaceName string) corev1.Namespace
- func GetNamespaceE(t *testing.T, options *KubectlOptions, namespaceName string) (corev1.Namespace, error)
- func GetNodes(t *testing.T) []corev1.Node
- func GetNodesE(t *testing.T) ([]corev1.Node, error)
- func GetPod(t *testing.T, options *KubectlOptions, podName string) *corev1.Pod
- func GetPodE(t *testing.T, options *KubectlOptions, podName string) (*corev1.Pod, error)
- func GetReadyNodes(t *testing.T) []corev1.Node
- func GetReadyNodesE(t *testing.T) ([]corev1.Node, error)
- func GetService(t *testing.T, options *KubectlOptions, serviceName string) *corev1.Service
- func GetServiceE(t *testing.T, options *KubectlOptions, serviceName string) (*corev1.Service, error)
- func GetServiceEndpoint(t *testing.T, service *corev1.Service, servicePort int) string
- func GetServiceEndpointE(t *testing.T, service *corev1.Service, servicePort int) (string, error)
- func IsNodeReady(node corev1.Node) bool
- func IsPodAvailable(pod *corev1.Pod) bool
- func IsServiceAvailable(service *corev1.Service) bool
- func KubeConfigPathFromHomeDirE() (string, error)
- func KubectlApply(t *testing.T, options *KubectlOptions, configPath string)
- func KubectlApplyE(t *testing.T, options *KubectlOptions, configPath string) error
- func KubectlApplyFromString(t *testing.T, options *KubectlOptions, configData string)
- func KubectlApplyFromStringE(t *testing.T, options *KubectlOptions, configData string) error
- func KubectlDelete(t *testing.T, options *KubectlOptions, configPath string)
- func KubectlDeleteE(t *testing.T, options *KubectlOptions, configPath string) error
- func KubectlDeleteFromString(t *testing.T, options *KubectlOptions, configData string)
- func KubectlDeleteFromStringE(t *testing.T, options *KubectlOptions, configData string) error
- func LoadApiClientConfigE(configPath string, contextName string) (*restclient.Config, error)
- func LoadConfigFromPath(path string) clientcmd.ClientConfig
- func RemoveOrphanedClusterAndAuthInfoConfig(config *api.Config)
- func RunKubectl(t *testing.T, options *KubectlOptions, args ...string)
- func RunKubectlAndGetOutputE(t *testing.T, options *KubectlOptions, args ...string) (string, error)
- func RunKubectlE(t *testing.T, options *KubectlOptions, args ...string) error
- func StoreConfigToTempFile(t *testing.T, configData string) string
- func StoreConfigToTempFileE(t *testing.T, configData string) (string, error)
- func WaitUntilAllNodesReady(t *testing.T, retries int, sleepBetweenRetries time.Duration)
- func WaitUntilAllNodesReadyE(t *testing.T, retries int, sleepBetweenRetries time.Duration) error
- func WaitUntilPodAvailable(t *testing.T, options *KubectlOptions, podName string, retries int, ...)
- func WaitUntilPodAvailableE(t *testing.T, options *KubectlOptions, podName string, retries int, ...) error
- func WaitUntilServiceAvailable(t *testing.T, options *KubectlOptions, serviceName string, retries int, ...)
- type KubectlOptions
- type MalformedNodeID
- type NoNodesInKubernetes
- type NodeHasNoHostname
- type PodNotAvailable
- type ServiceNotAvailable
- type UnknownServicePort
- type UnknownServiceType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AreAllNodesReady ¶
AreAllNodesReady checks if all nodes are ready in the Kubernetes cluster targeted by the current config context
func AreAllNodesReadyE ¶
AreAllNodesReadyE checks if all nodes are ready in the Kubernetes cluster targeted by the current config context. If false, returns an error indicating the reason.
func CreateNamespace ¶
func CreateNamespace(t *testing.T, options *KubectlOptions, namespaceName string)
CreateNamespace will create a new Kubernetes namespace on the cluster targeted by the provided options. This will fail the test if there is an error in creating the namespace.
func CreateNamespaceE ¶
func CreateNamespaceE(t *testing.T, options *KubectlOptions, namespaceName string) error
CreateNamespaceE will create a new Kubernetes namespace on the cluster targeted by the provided options.
func DeleteConfigContextE ¶
DeleteConfigContextE will remove the context specified at the provided name, and remove any clusters and authinfos that are orphaned as a result of it. The config path is either specified in the environment variable KUBECONFIG or at the user's home directory under `.kube/config`.
func DeleteConfigContextWithPathE ¶
DeleteConfigContextWithPathE will remove the context specified at the provided name, and remove any clusters and authinfos that are orphaned as a result of it.
func DeleteNamespace ¶
func DeleteNamespace(t *testing.T, options *KubectlOptions, namespaceName string)
DeleteNamespace will delete the requested namespace from the Kubernetes cluster targeted by the provided options. This will fail the test if there is an error in creating the namespace.
func DeleteNamespaceE ¶
func DeleteNamespaceE(t *testing.T, options *KubectlOptions, namespaceName string) error
DeleteNamespaceE will delete the requested namespace from the Kubernetes cluster targeted by the provided options.
func GetKubeConfigPathE ¶
GetKubeConfigPathE determines which file path to use as the kubectl config path
func GetKubernetesClientE ¶
func GetKubernetesClientE(t *testing.T) (*kubernetes.Clientset, error)
GetKubernetesClientE returns a Kubernetes API client that can be used to make requests.
func GetKubernetesClientFromOptionsE ¶
func GetKubernetesClientFromOptionsE(t *testing.T, options *KubectlOptions) (*kubernetes.Clientset, error)
GetKubernetesClientFromOptionsE returns a Kubernetes API client given a configured KubectlOptions object.
func GetNamespace ¶
GetNamespace will query the Kubernetes cluster targeted by the provided options for the requested namespace. This will fail the test if there is an error in creating the namespace.
func GetNamespaceE ¶
func GetNamespaceE(t *testing.T, options *KubectlOptions, namespaceName string) (corev1.Namespace, error)
GetNamespaceE will query the Kubernetes cluster targeted by the provided options for the requested namespace.
func GetNodes ¶
GetNodes queries Kubernetes for information about the worker nodes registered to the cluster. If anything goes wrong, the function will automatically fail the test.
func GetNodesE ¶
GetNodesE queries Kubernetes for information about the worker nodes registered to the cluster.
func GetPod ¶
GetPod returns a Kubernetes pod resource in the provided namespace with the given name. This will fail the test if there is an error.
func GetPodE ¶
GetPodE returns a Kubernetes pod resource in the provided namespace with the given name.
func GetReadyNodes ¶
GetReadyNodes queries Kubernetes for information about the worker nodes registered to the cluster and only returns those that are in the ready state. If anything goes wrong, the function will automatically fail the test.
func GetReadyNodesE ¶
GetReadyNodesE queries Kubernetes for information about the worker nodes registered to the cluster and only returns those that are in the ready state.
func GetService ¶
GetService returns a Kubernetes service resource in the provided namespace with the given name. This will fail the test if there is an error.
func GetServiceE ¶
func GetServiceE(t *testing.T, options *KubectlOptions, serviceName string) (*corev1.Service, error)
GetServiceE returns a Kubernetes service resource in the provided namespace with the given name.
func GetServiceEndpoint ¶
GetServiceEndpoint will return the service access point. If the service endpoint is not ready, will fail the test immediately.
func GetServiceEndpointE ¶
GetServiceEndpointE will return the service access point using the following logic:
- For ClusterIP service type, return the URL that maps to ClusterIP and Service Port
- For NodePort service type, identify the public IP of the node (if it exists, otherwise return the bound hostname), and the assigned node port for the provided service port, and return the URL that maps to node ip and node port.
- For LoadBalancer service type, return the publicly accessible hostname of the load balancer.
- All other service types are not supported.
func IsNodeReady ¶
IsNodeReady takes a Kubernetes Node information object and checks if the Node is in the ready state.
func IsPodAvailable ¶
IsPodAvailable returns true if the pod is running.
func IsServiceAvailable ¶
IsServiceAvailable returns true if the service endpoint is ready to accept traffic.
func KubeConfigPathFromHomeDirE ¶
KubeConfigPathFromHomeDirE returns a string to the default Kubernetes config path in the home directory. This will error if the home directory can not be determined.
func KubectlApply ¶
func KubectlApply(t *testing.T, options *KubectlOptions, configPath string)
KubectlApply will take in a file path and apply it to the cluster targeted by KubectlOptions. If there are any errors, fail the test immediately.
func KubectlApplyE ¶
func KubectlApplyE(t *testing.T, options *KubectlOptions, configPath string) error
KubectlApplyE will take in a file path and apply it to the cluster targeted by KubectlOptions.
func KubectlApplyFromString ¶
func KubectlApplyFromString(t *testing.T, options *KubectlOptions, configData string)
KubectlApplyFromString will take in a kubernetes resource config as a string and apply it on the cluster specified by the provided kubectl options.
func KubectlApplyFromStringE ¶
func KubectlApplyFromStringE(t *testing.T, options *KubectlOptions, configData string) error
KubectlApplyFromStringE will take in a kubernetes resource config as a string and apply it on the cluster specified by the provided kubectl options. If it fails, this will return the error.
func KubectlDelete ¶
func KubectlDelete(t *testing.T, options *KubectlOptions, configPath string)
KubectlDelete will take in a file path and delete it from the cluster targeted by KubectlOptions. If there are any errors, fail the test immediately.
func KubectlDeleteE ¶
func KubectlDeleteE(t *testing.T, options *KubectlOptions, configPath string) error
KubectlDeleteE will take in a file path and delete it from the cluster targeted by KubectlOptions.
func KubectlDeleteFromString ¶
func KubectlDeleteFromString(t *testing.T, options *KubectlOptions, configData string)
KubectlDeleteFromString will take in a kubernetes resource config as a string and delete it on the cluster specified by the provided kubectl options.
func KubectlDeleteFromStringE ¶
func KubectlDeleteFromStringE(t *testing.T, options *KubectlOptions, configData string) error
KubectlDeleteFromStringE will take in a kubernetes resource config as a string and delete it on the cluster specified by the provided kubectl options. If it fails, this will return the error.
func LoadApiClientConfigE ¶
func LoadApiClientConfigE(configPath string, contextName string) (*restclient.Config, error)
LoadApiClientConfig will load a ClientConfig object from a file path that points to a location on disk containing a kubectl config, with the requested context loaded.
func LoadConfigFromPath ¶
func LoadConfigFromPath(path string) clientcmd.ClientConfig
LoadConfigFromPath will load a ClientConfig object from a file path that points to a location on disk containing a kubectl config.
func RemoveOrphanedClusterAndAuthInfoConfig ¶
RemoveOrphanedClusterAndAuthInfoConfig will remove all configurations related to clusters and users that have no contexts associated with it
func RunKubectl ¶
func RunKubectl(t *testing.T, options *KubectlOptions, args ...string)
RunKubectl will call kubectl using the provided options and args, failing the test on error.
func RunKubectlAndGetOutputE ¶
RunKubectlAndGetOutputE will call kubectl using the provided options and args, returning the output of stdout and stderr.
func RunKubectlE ¶
func RunKubectlE(t *testing.T, options *KubectlOptions, args ...string) error
RunKubectlE will call kubectl using the provided options and args.
func StoreConfigToTempFile ¶
StoreConfigToTempFile will store the provided config data to a temporary file created on the os and return the filename.
func StoreConfigToTempFileE ¶
StoreConfigToTempFileE will store the provided config data to a temporary file created on the os and return the filename, or error.
func WaitUntilAllNodesReady ¶
WaitUntilAllNodesReady continuously polls the Kubernetes cluster until all nodes in the cluster reach the ready state, or runs out of retries. Will fail the test immediately if it times out.
func WaitUntilAllNodesReadyE ¶
WaitUntilAllNodesReadyE continuously polls the Kubernetes cluster until all nodes in the cluster reach the ready state, or runs out of retries.
func WaitUntilPodAvailable ¶
func WaitUntilPodAvailable(t *testing.T, options *KubectlOptions, podName string, retries int, sleepBetweenRetries time.Duration)
WaitUntilPodAvailable waits until the pod is running, retrying the check for the specified amount of times, sleeping for the provided duration between each try. This will fail the test if there is an error or if the check times out.
func WaitUntilPodAvailableE ¶
func WaitUntilPodAvailableE(t *testing.T, options *KubectlOptions, podName string, retries int, sleepBetweenRetries time.Duration) error
WaitUntilPodAvailableE waits until the pod is running, retrying the check for the specified amount of times, sleeping for the provided duration between each try.
func WaitUntilServiceAvailable ¶
func WaitUntilServiceAvailable(t *testing.T, options *KubectlOptions, serviceName string, retries int, sleepBetweenRetries time.Duration)
WaitUntilServiceAvailable waits until the service endpoint is ready to accept traffic.
Types ¶
type KubectlOptions ¶
type KubectlOptions struct { ContextName string ConfigPath string Namespace string Env map[string]string }
Represents common options necessary to specify for all Kubectl calls
func NewKubectlOptions ¶
func NewKubectlOptions(contextName string, configPath string) *KubectlOptions
type MalformedNodeID ¶
type MalformedNodeID struct {
// contains filtered or unexported fields
}
MalformedNodeID is returned when a Kubernetes node has a malformed node id scheme
func NewMalformedNodeIDError ¶
func NewMalformedNodeIDError(node *corev1.Node) MalformedNodeID
func (MalformedNodeID) Error ¶
func (err MalformedNodeID) Error() string
type NoNodesInKubernetes ¶
type NoNodesInKubernetes struct{}
NoNodesInKubernetes is returned when the Kubernetes cluster has no nodes registered.
func NewNoNodesInKubernetesError ¶
func NewNoNodesInKubernetesError() NoNodesInKubernetes
func (NoNodesInKubernetes) Error ¶
func (err NoNodesInKubernetes) Error() string
type NodeHasNoHostname ¶
type NodeHasNoHostname struct {
// contains filtered or unexported fields
}
NodeHasNoHostname is returned when a Kubernetes node has no discernible hostname
func NewNodeHasNoHostnameError ¶
func NewNodeHasNoHostnameError(node *corev1.Node) NodeHasNoHostname
func (NodeHasNoHostname) Error ¶
func (err NodeHasNoHostname) Error() string
type PodNotAvailable ¶
type PodNotAvailable struct {
// contains filtered or unexported fields
}
PodNotAvailable is returned when a Kubernetes service is not yet available to accept traffic.
func NewPodNotAvailableError ¶
func NewPodNotAvailableError(pod *corev1.Pod) PodNotAvailable
func (PodNotAvailable) Error ¶
func (err PodNotAvailable) Error() string
type ServiceNotAvailable ¶
type ServiceNotAvailable struct {
// contains filtered or unexported fields
}
ServiceNotAvailable is returned when a Kubernetes service is not yet available to accept traffic.
func NewServiceNotAvailableError ¶
func NewServiceNotAvailableError(service *corev1.Service) ServiceNotAvailable
func (ServiceNotAvailable) Error ¶
func (err ServiceNotAvailable) Error() string
type UnknownServicePort ¶
type UnknownServicePort struct {
// contains filtered or unexported fields
}
UnknownServicePort is returned when the given service port is not an exported port of the service.
func NewUnknownServicePortError ¶
func NewUnknownServicePortError(service *corev1.Service, port int32) UnknownServicePort
func (UnknownServicePort) Error ¶
func (err UnknownServicePort) Error() string
type UnknownServiceType ¶
type UnknownServiceType struct {
// contains filtered or unexported fields
}
UnknownServiceType is returned when a Kubernetes service has a type that is not yet handled by the test functions.
func NewUnknownServiceTypeError ¶
func NewUnknownServiceTypeError(service *corev1.Service) UnknownServiceType
func (UnknownServiceType) Error ¶
func (err UnknownServiceType) Error() string