kube

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

README

Kube

The kube package provides steps implementations related to Kubernetes.

Templated Kubernetes manifests

All the steps implementations of this package use the "text/template" library to support templated yaml files. Simply assign the data structure that contains your template's arguments to TemplateArguments within the KubeContext object of your Test instance:

// Data structure with your template's arguments
type templateArgs struct {
	namespace string
}

func NewTemplateArgs() templateArgs {
	return templateArgs{
		namespace: os.Getenv("NAMESPACE"),
	}
}
var t kubedog.Test

func InitializeTestSuite(ctx *godog.TestSuiteContext) {
	t.SetTestSuite(ctx)
}

func InitializeScenario(ctx *godog.ScenarioContext) {
	t.SetScenario(ctx)
    // Assign your data structure
	t.KubeContext.TemplateArguments = NewTemplateArgs()
	t.Run()
}

Documentation

Overview

Package kube provides steps implementations related to Kubernetes.

Index

Constants

View Source
const (
	OperationCreate = "create"
	OperationSubmit = "submit"
	OperationUpdate = "update"
	OperationDelete = "delete"

	StateCreated  = "created"
	StateDeleted  = "deleted"
	StateUpgraded = "upgraded"

	NodeStateReady = "ready"
	NodeStateFound = "found"

	DefaultWaiterInterval = time.Second * 30
	DefaultWaiterTries    = 40

	DefaultFilePath = "templates"
	SomePodsKeyword = "some"
	AllPodsKeyword  = "all"
)
View Source
const (
	// InstanceGroupNamespace is the default namespace to use of instance-group submission
	InstanceGroupNamespace = "instance-manager"
	// CustomResourceGroup is the group of the instance-manager API/custom resource definition
	CustomResourceGroup = "instancemgr"
	// CustomResourceAPIVersion is the version of the instance-manager API/custom resource definition
	CustomResourceAPIVersion = "v1alpha1"
	// CustomeResourceDomain is the domain of the instance-manager API/custom resource definition
	CustomeResourceDomain = "keikoproj.io"
	// CustomResourceKind is the resource kind (plural) of the instance-manager API/custom resource definition
	CustomResourceKind = "instancegroups"
)

Variables

View Source
var (
	// CustomResourceName is the name of the API/custom resource definition
	CustomResourceName    = fmt.Sprintf("%v.%v", CustomResourceGroup, CustomeResourceDomain)
	InstanceGroupResource = schema.GroupVersionResource{Group: CustomResourceName, Version: CustomResourceAPIVersion, Resource: CustomResourceKind}
)

Functions

This section is empty.

Types

type Client

type Client struct {
	KubeInterface      kubernetes.Interface
	DynamicInterface   dynamic.Interface
	DiscoveryInterface discovery.DiscoveryInterface
	FilesPath          string
	TemplateArguments  interface{}
	WaiterInterval     time.Duration
	WaiterTries        int
	Timestamps         map[string]time.Time
}

func (*Client) ClusterRbacIsFound added in v0.4.0

func (kc *Client) ClusterRbacIsFound(resource, name string) error

Cluster scoped role and bindings are found.

func (*Client) DeleteAllTestResources

func (kc *Client) DeleteAllTestResources() error

DeleteAllTestResources deletes all the resources defined by yaml files in the path given by FilesPath: if FilesPath is empty, it will look for the files in ./templates. Meant to be use in the before/after suite/scenario/step hooks

func (*Client) DeleteResourcesAtPath added in v0.8.0

func (kc *Client) DeleteResourcesAtPath(resourcesPath string) error

DeleteResourcesAtPath deletes all the resources defined by yaml files in the path provided

func (*Client) GetDaemonset added in v0.8.0

func (kc *Client) GetDaemonset(name, namespace string) (*appsv1.DaemonSet, error)

GetDaemonset gets a daemonset

func (*Client) GetDeployment added in v0.8.0

func (kc *Client) GetDeployment(name, namespace string) (*appsv1.Deployment, error)

GetDeployment gets a deployment

func (*Client) GetIngress added in v0.8.0

func (kc *Client) GetIngress(name, namespace string) (*networkingv1.Ingress, error)

func (*Client) GetIngressEndpoint added in v0.8.0

func (kc *Client) GetIngressEndpoint(name, namespace string, port int, path string) (string, error)

func (*Client) GetNodes added in v0.8.0

func (kc *Client) GetNodes() error

func (*Client) GetPersistentVolume added in v0.8.0

func (kc *Client) GetPersistentVolume(name string) (*corev1.PersistentVolume, error)

GetPersistentVolume gets a pv

func (*Client) GetPods added in v0.8.0

func (kc *Client) GetPods(namespace string) error

func (*Client) GetPodsWithSelector added in v0.8.0

func (kc *Client) GetPodsWithSelector(namespace, selector string) error

func (*Client) IngressAvailable added in v0.8.0

func (kc *Client) IngressAvailable(name, namespace string, port int, path string) error

func (*Client) KubernetesCluster added in v0.8.0

func (kc *Client) KubernetesCluster() error

AKubernetesCluster sets the Kubernetes clients given a valid kube config file in ~/.kube or the path set in the environment variable KUBECONFIG.

func (*Client) KubernetesClusterShouldBe added in v0.8.0

func (kc *Client) KubernetesClusterShouldBe(state string) error

func (*Client) ListInstanceGroups added in v0.8.0

func (kc *Client) ListInstanceGroups() (*unstructured.UnstructuredList, error)

func (*Client) ListNodes added in v0.8.0

func (kc *Client) ListNodes() (*corev1.NodeList, error)

ListNodes lists nodes

func (*Client) ListPersistentVolumes added in v0.8.0

func (kc *Client) ListPersistentVolumes() (*corev1.PersistentVolumeList, error)

ListPersistentVolume lists pvs

func (*Client) ListPodsWithLabelSelector added in v0.8.0

func (kc *Client) ListPodsWithLabelSelector(namespace, selector string) (*corev1.PodList, error)

ListPodsWithLabelSelector lists pods with a label selector

func (*Client) ListStatefulSets added in v0.8.0

func (kc *Client) ListStatefulSets(namespace string) (*appsv1.StatefulSetList, error)

ListStatefulSets lists statefulsets

func (*Client) MultiResourceOperation added in v0.2.0

func (kc *Client) MultiResourceOperation(operation, resourceFileName string) error

MultiResourceOperation performs the given operation on the resources defined in resourceFileName. The operation could be “create”, “submit” or “delete”. Files created using this function cannot individually be addressed by filename.

func (*Client) MultiResourceOperationInNamespace added in v0.7.0

func (kc *Client) MultiResourceOperationInNamespace(operation, resourceFileName, ns string) error

func (*Client) NodesWithSelectorShouldBe

func (kc *Client) NodesWithSelectorShouldBe(n int, selector, state string) error

NodesWithSelectorShouldBe checks that n amount of nodes with the given selector are in the desired state. It retries every 30 seconds for a total of 40 times. Selector in the form <key>=<value>, the state can be "ready" or "found".

func (*Client) PersistentVolExists added in v0.8.0

func (kc *Client) PersistentVolExists(volName, expectedPhase string) error

func (*Client) PodsWithSelectorHaveRestartCountLessThan added in v0.8.0

func (kc *Client) PodsWithSelectorHaveRestartCountLessThan(namespace string, selector string, expectedRestartCountLessThan int) error

func (*Client) ResourceConditionShouldBe

func (kc *Client) ResourceConditionShouldBe(resourceFileName, cType, status string) error

ResourceConditionShouldBe checks that the resource defined in resourceFileName has the condition of type cType in the desired status. It retries every 30 seconds for a total of 40 times.

func (*Client) ResourceInNamespace added in v0.3.0

func (kc *Client) ResourceInNamespace(resource, name, ns string) error

ResourceInNamespace check if (deployment|service) in the related namespace

func (*Client) ResourceIsRunning added in v0.8.0

func (kc *Client) ResourceIsRunning(kind, name, namespace string) error

func (*Client) ResourceOperation

func (kc *Client) ResourceOperation(operation, resourceFileName string) error

ResourceOperation performs the given operation on the resource defined in resourceFileName. The operation could be “create”, “submit”, “delete”, or "update".

func (*Client) ResourceOperationInNamespace added in v0.7.0

func (kc *Client) ResourceOperationInNamespace(operation, resourceFileName, ns string) error

ResourceOperationInNamespace performs the given operation on the resource defined in resourceFileName in a specified namespace. The operation could be “create”, “submit”, “delete”, or "update".

func (*Client) ResourceOperationWithResult added in v0.8.0

func (kc *Client) ResourceOperationWithResult(operation, resourceFileName, expectedResult string) error

func (*Client) ResourceOperationWithResultInNamespace added in v0.8.0

func (kc *Client) ResourceOperationWithResultInNamespace(operation, resourceFileName, namespace, expectedResult string) error

func (*Client) ResourceShouldBe

func (kc *Client) ResourceShouldBe(resourceFileName, state string) error

ResourceShouldBe checks if the resource defined in resourceFileName is in the desired state. It retries every 30 seconds for a total of 40 times. The state could be “created” or “deleted”.

func (*Client) ResourceShouldConvergeToSelector

func (kc *Client) ResourceShouldConvergeToSelector(resourceFileName, selector string) error

ResourceShouldConvergeToSelector checks if the resource defined in resourceFileName has the desired selector. It retries every 30 seconds for a total of 40 times. Selector in the form <keys>=<value>.

func (*Client) ScaleDeployment added in v0.0.2

func (kc *Client) ScaleDeployment(name, ns string, replica int32) error

ScaleDeployment scale up/down for the deployment

func (*Client) SecretDelete added in v0.8.0

func (kc *Client) SecretDelete(secretName, namespace string) error

func (*Client) SecretOperationFromEnvironmentVariable added in v0.8.0

func (kc *Client) SecretOperationFromEnvironmentVariable(operation, secretName, namespace, environmentVariable string) error

func (*Client) SendTrafficToIngress added in v0.8.0

func (kc *Client) SendTrafficToIngress(tps int, name, namespace string, port int, path string, duration int, durationUnits string, expectedErrors int) error

func (*Client) SetTimestamp added in v0.8.0

func (kc *Client) SetTimestamp(timestampName string) error

func (*Client) SomeOrAllPodsInNamespaceWithSelectorHaveStringInLogsSinceTime added in v0.8.1

func (kc *Client) SomeOrAllPodsInNamespaceWithSelectorHaveStringInLogsSinceTime(SomeOrAll, namespace, selector, searchkeyword, sinceTime string) error

func (*Client) SomePodsInNamespaceWithSelectorDontHaveStringInLogsSinceTime added in v0.8.1

func (kc *Client) SomePodsInNamespaceWithSelectorDontHaveStringInLogsSinceTime(namespace, selector, searchkeyword, sinceTime string) error

func (*Client) ThePodsInNamespaceShouldHaveLabels added in v0.8.0

func (kc *Client) ThePodsInNamespaceShouldHaveLabels(podName string,
	namespace string, labels string) error

func (*Client) ThePodsInNamespaceWithSelectorHaveNoErrorsInLogsSinceTime added in v0.8.0

func (kc *Client) ThePodsInNamespaceWithSelectorHaveNoErrorsInLogsSinceTime(namespace string, selector string, sinceTime string) error

func (*Client) ThePodsInNamespaceWithSelectorHaveSomeErrorsInLogsSinceTime added in v0.8.0

func (kc *Client) ThePodsInNamespaceWithSelectorHaveSomeErrorsInLogsSinceTime(namespace string, selector string, sinceTime string) error

func (*Client) ThePodsInNamespaceWithSelectorShouldHaveLabels added in v0.8.0

func (kc *Client) ThePodsInNamespaceWithSelectorShouldHaveLabels(namespace string,
	selector string, labels string) error

func (*Client) UpdateResourceWithField

func (kc *Client) UpdateResourceWithField(resourceFileName, key string, value string) error

UpdateResourceWithField it updates the field found in the key of the resource defined in resourceFileName with value.

func (*Client) Validate added in v0.8.0

func (kc *Client) Validate() error

func (*Client) ValidatePrometheusVolumeClaimTemplatesName added in v0.8.0

func (kc *Client) ValidatePrometheusVolumeClaimTemplatesName(statefulsetName string, namespace string, volumeClaimTemplatesName string) error

func (*Client) VerifyInstanceGroups added in v0.8.0

func (kc *Client) VerifyInstanceGroups() error

Jump to

Keyboard shortcuts

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