kube

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: Apache-2.0 Imports: 18 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"

	ResourceStateCreated = "created"
	ResourceStateDeleted = "deleted"

	NodeStateReady = "ready"
	NodeStateFound = "found"

	DefaultWaiterInterval = time.Second * 30
	DefaultWaiterTries    = 40

	DefaultFilePath = "templates"
)

Variables

This section is empty.

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
}

func (*Client) AKubernetesCluster

func (kc *Client) AKubernetesCluster() 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) ClusterRbacIsFound added in v0.4.0

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

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) 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) 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) 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) 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” or “delete”.

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) 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.

Jump to

Keyboard shortcuts

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