k8s

package
v0.0.0-...-1eaa894 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JobSelectorKey = "job"
	// Poll is how often to Poll pods, nodes and claims.
	PollInterval         = 2 * time.Second
	PollTimeout          = 15 * time.Minute
	DefaultContainerName = "container-busybox"
)

Variables

This section is empty.

Functions

func AddAnnotationToPersistentVolume

func AddAnnotationToPersistentVolume(ctx context.Context, client TestClient, namespace string, persistentVolume, key string) (*corev1.PersistentVolume, error)

func AddAnnotationToPod

func AddAnnotationToPod(ctx context.Context, client TestClient, namespace, podName string, ann map[string]string) (*corev1.Pod, error)

func AddLabelToCRD

func AddLabelToCRD(ctx context.Context, crd, label string) error

func AddLabelToPod

func AddLabelToPod(ctx context.Context, podName, namespace, label string) error

func AddLabelToPv

func AddLabelToPv(ctx context.Context, pv, label string) error

func AddLabelToPvc

func AddLabelToPvc(ctx context.Context, pvc, namespace, label string) error

func CRDCountShouldBe

func CRDCountShouldBe(ctx context.Context, name string, count int) error

func CRDShouldExist

func CRDShouldExist(ctx context.Context, name string) error

func CRDShouldNotExist

func CRDShouldNotExist(ctx context.Context, name string) error

func CalFileHashInPod

func CalFileHashInPod(ctx context.Context, namespace, podName, containerName, filePath string) (string, error)

func CleanupClusterRole

func CleanupClusterRole(ctx context.Context, client TestClient, CaseBaseName string) error

func CleanupClusterRoleBinding

func CleanupClusterRoleBinding(ctx context.Context, client TestClient, CaseBaseName string) error

func CleanupNamespaces

func CleanupNamespaces(ctx context.Context, client TestClient, CaseBaseName string) error

func CleanupNamespacesFiterdByExcludes

func CleanupNamespacesFiterdByExcludes(ctx context.Context, client TestClient, excludeNS []string) error

func CleanupNamespacesWithPoll

func CleanupNamespacesWithPoll(ctx context.Context, client TestClient, CaseBaseName string) error

func ClearClaimRefForFailedPVs

func ClearClaimRefForFailedPVs(ctx context.Context, client TestClient) error

func CollectClusterEvents

func CollectClusterEvents(key string, pods []string)

func CreateConfigMap

func CreateConfigMap(c clientset.Interface, ns, name string, labels, data map[string]string) (*v1.ConfigMap, error)

func CreateConfigMapFromYAMLData

func CreateConfigMapFromYAMLData(c clientset.Interface, yamlData, cmName, namespace string) error

func CreateDeploy

func CreateDeploy(c clientset.Interface, ns string, deployment *apps.Deployment) error

func CreateDeployment

func CreateDeployment(c clientset.Interface, ns string, deployment *apps.Deployment) (*apps.Deployment, error)

func CreateFileToPod

func CreateFileToPod(ctx context.Context, namespace, podName, containerName, volume, filename, content string) error

func CreateNamespace

func CreateNamespace(ctx context.Context, client TestClient, namespace string) error

func CreateNamespaceWithAnnotation

func CreateNamespaceWithAnnotation(ctx context.Context, client TestClient, namespace string, annotation map[string]string) error

func CreateNamespaceWithLabel

func CreateNamespaceWithLabel(ctx context.Context, client TestClient, namespace string, label map[string]string) error

func CreatePVC

func CreatePVC(client TestClient, ns, name, sc string, ann map[string]string) (*corev1.PersistentVolumeClaim, error)

func CreatePersistentVolume

func CreatePersistentVolume(client TestClient, name string) (*corev1.PersistentVolume, error)

func CreatePod

func CreatePod(client TestClient, ns, name, sc, pvcName string, volumeNameList []string, pvcAnn, ann map[string]string) (*corev1.Pod, error)

func CreatePvc

func CreatePvc(client TestClient, pvcBulder *PVCBuilder) error

func CreateRBACWithBindingSA

func CreateRBACWithBindingSA(ctx context.Context, client TestClient, namespace string, serviceaccount string, clusterrole string, clusterrolebinding string) error

func CreateSecret

func CreateSecret(c clientset.Interface, ns, name string, labels map[string]string) (*v1.Secret, error)

func CreateSecretFromFiles

func CreateSecretFromFiles(ctx context.Context, client TestClient, namespace string, name string, files map[string]string) error

func CreateService

func CreateService(ctx context.Context, client TestClient, namespace string,
	service string, labels map[string]string, serviceSpec *corev1.ServiceSpec) error

func CreateServiceAccount

func CreateServiceAccount(ctx context.Context, client TestClient, namespace string, serviceaccount string) error

func CreateVolumes

func CreateVolumes(pvcName string, volumeNameList []string) (vols []*corev1.Volume)

func DeleteCRD

func DeleteCRD(ctx context.Context, yaml string) error

func DeleteCRDByName

func DeleteCRDByName(ctx context.Context, name string) error

func DeleteConfigMap

func DeleteConfigMap(c clientset.Interface, ns, name string) error

func DeleteNamespace

func DeleteNamespace(ctx context.Context, client TestClient, namespace string, wait bool) error

func DeleteStorageClass

func DeleteStorageClass(ctx context.Context, client TestClient, name string) error

func DeleteVeleroDs

func DeleteVeleroDs(ctx context.Context) error

func EnsureClusterExists

func EnsureClusterExists(ctx context.Context) error

ensureClusterExists returns whether or not a Kubernetes cluster exists for tests to be run on.

func FileExistInPV

func FileExistInPV(ctx context.Context, namespace, podName, containerName, volume, filename string) (bool, error)

func GetAPIVersions

func GetAPIVersions(client *TestClient, name string) ([]string, error)

func GetAllPVNames

func GetAllPVNames(ctx context.Context, client TestClient) ([]string, error)

func GetAllService

func GetAllService(ctx context.Context) (string, error)

func GetBackupNamespaces

func GetBackupNamespaces(ctx context.Context, client TestClient, excludeNS []string) ([]string, error)

func GetCRD

func GetCRD(ctx context.Context, name string) ([]string, error)

func GetClusterRole

func GetClusterRole(ctx context.Context, client TestClient, role string) (*v1.ClusterRole, error)

func GetClusterRoleBinding

func GetClusterRoleBinding(ctx context.Context, client TestClient, rolebinding string) (*v1.ClusterRoleBinding, error)

func GetConfigMap

func GetConfigMap(c clientset.Interface, ns, secretName string) (*v1.ConfigMap, error)

func GetDeployment

func GetDeployment(c clientset.Interface, ns, name string) (*apps.Deployment, error)

func GetMappingNamespaces

func GetMappingNamespaces(ctx context.Context, client TestClient, excludeNS []string) (string, error)

func GetNamespace

func GetNamespace(ctx context.Context, client TestClient, namespace string) (*corev1api.Namespace, error)

func GetPVByPVCName

func GetPVByPVCName(client TestClient, namespace, pvcName string) (string, error)

func GetPVC

func GetPVC(ctx context.Context, client TestClient, namespace string, pvcName string) (*corev1.PersistentVolumeClaim, error)

func GetPersistentVolume

func GetPersistentVolume(ctx context.Context, client TestClient, namespace string, persistentVolume string) (*corev1.PersistentVolume, error)

func GetPod

func GetPod(ctx context.Context, client TestClient, namespace string, pod string) (*corev1.Pod, error)

func GetPvByPvc

func GetPvByPvc(ctx context.Context, namespace, pvc string) ([]string, error)

func GetPvcByPVCName

func GetPvcByPVCName(ctx context.Context, namespace, pvcName string) ([]string, error)

func GetSecret

func GetSecret(c clientset.Interface, ns, secretName string) (*v1.Secret, error)

func GetService

func GetService(ctx context.Context, client TestClient, namespace string, service string) (*corev1.Service, error)

func GetServiceAccount

func GetServiceAccount(ctx context.Context, client TestClient, namespace string, serviceAccount string) (*corev1.ServiceAccount, error)

func GetWorkerNodes

func GetWorkerNodes(ctx context.Context) ([]string, error)

func InstallCR

func InstallCR(ctx context.Context, crFile, ns string) error

func InstallCRD

func InstallCRD(ctx context.Context, yaml string) error

func InstallStorageClass

func InstallStorageClass(ctx context.Context, yaml string) error

func KubectlApplyByFile

func KubectlApplyByFile(ctx context.Context, file string) error

func KubectlConfigUseContext

func KubectlConfigUseContext(ctx context.Context, kubectlContext string) error

func KubectlCreateClusterRoleBinding

func KubectlCreateClusterRoleBinding(ctx context.Context, name, clusterrole, namespace, serviceaccount string) error

func KubectlCreateNamespace

func KubectlCreateNamespace(ctx context.Context, name string) error

func KubectlDeleteByFile

func KubectlDeleteByFile(ctx context.Context, file string) error

func KubectlDeleteClusterRoleBinding

func KubectlDeleteClusterRoleBinding(ctx context.Context, name string) error

func KubectlDeleteNamespace

func KubectlDeleteNamespace(ctx context.Context, namespace string) error

func KubectlGetDsJson

func KubectlGetDsJson(veleroNamespace string) (string, error)

func KubectlGetNS

func KubectlGetNS(ctx context.Context, name string) ([]string, error)

func ListPods

func ListPods(ctx context.Context, client TestClient, namespace string) (*corev1.PodList, error)

func NamespaceShouldNotExist

func NamespaceShouldNotExist(ctx context.Context, client TestClient, namespace string) error

func PatchServiceAccountWithImagePullSecret

func PatchServiceAccountWithImagePullSecret(ctx context.Context, client TestClient, namespace, serviceAccount, dockerCredentialFile string) error

func PrepareVolumeList

func PrepareVolumeList(volumeNameList []string) (vols []*corev1.Volume)

func ReadFileFromPodVolume

func ReadFileFromPodVolume(ctx context.Context, namespace, podName, containerName, volume, filename string) (string, string, error)

func RunCommand

func RunCommand(cmdName string, arg []string) string

func ScaleStatefulSet

func ScaleStatefulSet(ctx context.Context, namespace, name string, replicas int) error

func WaitAllSelectedNSDeleted

func WaitAllSelectedNSDeleted(ctx context.Context, client TestClient, label string) error

func WaitForCRDEstablished

func WaitForCRDEstablished(crdName string) error

func WaitForConfigMapComplete

func WaitForConfigMapComplete(c clientset.Interface, ns, cmName string) error

WaitForConfigMapComplete uses c to wait for completions to complete for the Job jobName in namespace ns.

func WaitForConfigmapDelete

func WaitForConfigmapDelete(c clientset.Interface, ns, name string) error

func WaitForPods

func WaitForPods(ctx context.Context, client TestClient, namespace string, pods []string) error

WaitForPods waits until all of the pods have gone to PodRunning state

func WaitForReadyDeployment

func WaitForReadyDeployment(c clientset.Interface, ns, name string) error

WaitForReadyDeployment waits for number of ready replicas to equal number of replicas.

func WaitForSecretDelete

func WaitForSecretDelete(c clientset.Interface, ns, name string) error

func WaitForSecretsComplete

func WaitForSecretsComplete(c clientset.Interface, ns, secretName string) error

WaitForSecretsComplete uses c to wait for completions to complete for the Job jobName in namespace ns.

func WaitForServiceDelete

func WaitForServiceDelete(client TestClient, ns, name string, deleteFirst bool) error

func WaitUntilServiceAccountCreated

func WaitUntilServiceAccountCreated(ctx context.Context, client TestClient, namespace, serviceAccount string, timeout time.Duration) error

func WriteRandomDataToFileInPod

func WriteRandomDataToFileInPod(ctx context.Context, namespace, podName, containerName, volume, filename string, fileSize int64) error

Types

type DeploymentBuilder

type DeploymentBuilder struct {
	*apps.Deployment
}

DeploymentBuilder builds Deployment objects.

func NewDeployment

func NewDeployment(name, ns string, replicas int32, labels map[string]string, containers []v1.Container) *DeploymentBuilder

newDeployment returns a RollingUpdate Deployment with a fake container image

func (*DeploymentBuilder) Result

func (d *DeploymentBuilder) Result() *apps.Deployment

func (*DeploymentBuilder) WithVolume

func (d *DeploymentBuilder) WithVolume(volumes []*v1.Volume) *DeploymentBuilder

type PVCBuilder

type PVCBuilder struct {
	*corev1.PersistentVolumeClaim
}

PVCBuilder builds PVC objects.

func NewPVC

func NewPVC(ns, name string) *PVCBuilder

func (*PVCBuilder) Result

func (*PVCBuilder) WithAnnotation

func (p *PVCBuilder) WithAnnotation(ann map[string]string) *PVCBuilder

func (*PVCBuilder) WithResourceStorage

func (p *PVCBuilder) WithResourceStorage(q resource.Quantity) *PVCBuilder

func (*PVCBuilder) WithStorageClass

func (p *PVCBuilder) WithStorageClass(sc string) *PVCBuilder

type TestClient

type TestClient struct {
	Kubebuilder kbclient.Client

	// clientGo returns a client-go API client.
	//
	// Deprecated, TODO(2.0): presuming all controllers and resources are converted to the
	// controller runtime framework by v2.0, it is the intent to remove all
	// client-go API clients. Please use the controller runtime to make API calls for tests.
	ClientGo kubernetes.Interface

	MetricsClient *metricsclientset.Clientset
	// contains filtered or unexported fields
}

func InitTestClient

func InitTestClient(kubecontext string) (TestClient, error)

func NewTestClient

func NewTestClient(kubecontext string) (TestClient, error)

NewTestClient returns a set of ready-to-use API clients.

Jump to

Keyboard shortcuts

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