kubernetes_ctx

package module
v0.0.0-...-9fab673 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RxDNSChar          = `[a-z0-9\-.]`
	RxGroupVersionKind = `[\w/]+`
	RxNamespacedName   = RxDNSChar + `+(?:/` + RxDNSChar + `+)?`
	RxFieldPath        = `[^=:]+?`
)

Variables

This section is empty.

Functions

func AnnotateResource

func AnnotateResource(ctx *FeatureContext, s ScenarioContext)

AnnotateResource implements the GoDoc step - `Kubernetes annotates <ApiGroupVersionKind> '<NamespacedName>' with '<AnnotationName>=<AnnotationValue>'` It adds or modifies a specific resource annotation with the given value.

func CountNamespacedResources

func CountNamespacedResources(ctx *FeatureContext, s ScenarioContext)

CountNamespacedResources implements the GoDoc step - `Kubernetes has <NumberResources> <ApiGroupVersionKind> in namespace '<Namespace>'` It compare the current number of a specific resource with the given number.

func CountResources

func CountResources(ctx *FeatureContext, s ScenarioContext)

CountResources implements the GoDoc step - `Kubernetes has <NumberResources> <ApiGroupVersionKind>` It compare the current number of a specific resource with the given number.

func CreateMultiResources

func CreateMultiResources(ctx *FeatureContext, s ScenarioContext)

CreateMultiResources implements the GoDoc step - `Kubernetes must have the following resources <RESOURCES_TABLE>` - `Kubernetes creates the following resources <RESOURCES_TABLE>` It creates several resources in a row, without any specific fields (useful for Namespaces).

func CreateSingleResource

func CreateSingleResource(ctx *FeatureContext, s ScenarioContext)

CreateSingleResource implements the GoDoc step - `Kubernetes must have <ApiGroupVersionKind> '<NamespacedName>'` - `Kubernetes creates a new <ApiGroupVersionKind> '<NamespacedName>'` It creates a new resource, without any specific fields.

func CreateSingleResourceFrom

func CreateSingleResourceFrom(ctx *FeatureContext, s ScenarioContext)

CreateSingleResourceFrom implements the GoDoc step - `Kubernetes must have <ApiGroupVersionKind> '<NamespacedName>' from <filename>` - `Kubernetes creates a new <ApiGroupVersionKind> '<NamespacedName>' from <filename>` It creates a new resource, with then definition available in the given filename.

func CreateSingleResourceWith

func CreateSingleResourceWith(ctx *FeatureContext, s ScenarioContext)

CreateSingleResourceWith implements the GoDoc step - `Kubernetes must have <ApiGroupVersionKind> '<NamespacedName>' with <YAML>` - `Kubernetes creates a new <ApiGroupVersionKind> '<NamespacedName>' with <YAML>` It creates a new resource, with the given definition.

func LabelizeResource

func LabelizeResource(ctx *FeatureContext, s ScenarioContext)

LabelizeResource implements the GoDoc step - `Kubernetes labelizes <ApiGroupVersionKind> '<NamespacedName>' with '<LabelName>=<LabelValue>'` It adds or modifies a specific resource label with the given value.

func NaiveGC

func NaiveGC(ctx *FeatureContext, owner *unstructured.Unstructured) error

NaiveGC performs a manual and naive garbage collector using the given object as owner.

func PatchResourceWith

func PatchResourceWith(ctx *FeatureContext, s ScenarioContext)

PatchResourceWith implements the GoDoc step - `Kubernetes patches <ApiGroupVersionKind> '<NamespacedName>' with <YAML>` It patches a specific resource with the given patch (it use StrategicMergePatchType... see https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md for more information).

func RemoveMultiResource

func RemoveMultiResource(ctx *FeatureContext, s ScenarioContext)

RemoveMultiResource implements the GoDoc step - `Kubernetes removes the following resources <RESOURCES_TABLE>` It creates several resources in a row.

func RemoveResource

func RemoveResource(ctx *FeatureContext, s ScenarioContext)

RemoveResource implements the GoDoc step - `Kubernetes removes <ApiGroupVersionKind> '<NamespacedName>'` It removes the specified resource.

func RemoveResourceAnnotation

func RemoveResourceAnnotation(ctx *FeatureContext, s ScenarioContext)

RemoveResourceAnnotation implements the GoDoc step - `Kubernetes removes annotation <AnnotationName> on <ApiGroupVersionKind> '<NamespacedName>'` It removes the given annotation on the specified resource.

func RemoveResourceLabel

func RemoveResourceLabel(ctx *FeatureContext, s ScenarioContext)

RemoveResourceLabel implements the GoDoc step - `Kubernetes removes label <LabelName> on <ApiGroupVersionKind> '<NamespacedName>'` It removes the given label on the specified resource.

func ResourceDoesntHaveAnnotation

func ResourceDoesntHaveAnnotation(ctx *FeatureContext, s ScenarioContext)

ResourceDoesntHaveAnnotation implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' doesn't have annotation '<AnnotationName>'` It validates the fact that the specific resource doesn't have the given annotation.

func ResourceDoesntHaveField

func ResourceDoesntHaveField(ctx *FeatureContext, s ScenarioContext)

ResourceDoesntHaveField implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' doesn't have '<FieldPath>'` It validates the fact that the specific resource doesn't have the field.

func ResourceDoesntHaveLabel

func ResourceDoesntHaveLabel(ctx *FeatureContext, s ScenarioContext)

ResourceDoesntHaveLabel implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' doesn't have label '<LabelName>'` It validates the fact that the specific resource doesn't have the given label.

func ResourceExists

func ResourceExists(ctx *FeatureContext, s ScenarioContext)

ResourceExists implements the GoDoc step - `Kubernetes has <ApiGroupVersionKind> '<NamespacedName>'` It validates the fact that Kubernetes has the specified resource.

func ResourceHasAnnotation

func ResourceHasAnnotation(ctx *FeatureContext, s ScenarioContext)

ResourceHasAnnotation implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has annotation '<AnnotationName>'` It validates the fact that the specific resource has the given annotation.

func ResourceHasAnnotationEqual

func ResourceHasAnnotationEqual(ctx *FeatureContext, s ScenarioContext)

ResourceHasAnnotationEqual implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has annotation '<AnnotationName>=<AnnotationValue>'` It validates the fact that the specific resource annotation has the given value.

func ResourceHasAnnotationNotEqual

func ResourceHasAnnotationNotEqual(ctx *FeatureContext, s ScenarioContext)

ResourceHasAnnotationNotEqual implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has annotation '<AnnotationName>!=<AnnotationValue>'` It validates the fact that the specific resource annotation doesn't have the given value.

func ResourceHasField

func ResourceHasField(ctx *FeatureContext, s ScenarioContext)

ResourceHasField implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has '<FieldPath>'` It validates the fact that the specific resource has the field.

func ResourceHasFieldEqual

func ResourceHasFieldEqual(ctx *FeatureContext, s ScenarioContext)

ResourceHasFieldEqual implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has '<FieldPath>=<FieldValue>'` It validates the fact that the specific resource field has the given value.

func ResourceHasFieldNotEqual

func ResourceHasFieldNotEqual(ctx *FeatureContext, s ScenarioContext)

ResourceHasFieldNotEqual implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has '<FieldPath>!=<FieldValue>'` It validates the fact that the specific resource field is different than the given value.

func ResourceHasLabel

func ResourceHasLabel(ctx *FeatureContext, s ScenarioContext)

ResourceHasLabel implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has label '<LabelName>'` It validates the fact that the specific resource has the given label.

func ResourceHasLabelEqual

func ResourceHasLabelEqual(ctx *FeatureContext, s ScenarioContext)

ResourceHasLabelEqual implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has label '<LabelName>=<LabelValue>'` It validates the fact that the specific resource label has the given value.

func ResourceHasLabelNotEqual

func ResourceHasLabelNotEqual(ctx *FeatureContext, s ScenarioContext)

ResourceHasLabelNotEqual implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' has label '<LabelName>!=<LabelValue>'` It validates the fact that the specific resource label doesn't have the given value.

func ResourceIsEqualTo

func ResourceIsEqualTo(ctx *FeatureContext, s ScenarioContext)

ResourceIsEqualTo implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' is equal to '<NamespacedName>'` It compares two resources in order to determine if they are equal.

NOTE: Two resources are equal if all fields except unique fields ('metadata.name',

'metadata.namespace', 'metadata.uid' and 'metadata.resourceVersion') are the same.

func ResourceIsNotEqualTo

func ResourceIsNotEqualTo(ctx *FeatureContext, s ScenarioContext)

ResourceIsNotEqualTo implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' is not equal to '<NamespacedName>'` It compares two resources in order to determine if they are not equal.

NOTE: Two resources are equal if all fields except unique fields ('metadata.name',

'metadata.namespace', 'metadata.uid' and 'metadata.resourceVersion') are the same.

func ResourceIsNotSimilarTo

func ResourceIsNotSimilarTo(ctx *FeatureContext, s ScenarioContext)

ResourceIsNotSimilarTo implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' is not similar to '<NamespacedName>'` It compares two resources in order to determine if they are not similar.

NOTE: Two resources are similar if all fields except 'medatata' are the same.

func ResourceIsSimilarTo

func ResourceIsSimilarTo(ctx *FeatureContext, s ScenarioContext)

ResourceIsSimilarTo implements the GoDoc step - `Kubernetes resource <ApiGroupVersionKind> '<NamespacedName>' is similar to '<NamespacedName>'` It compares two resources in order to determine if they are similar.

NOTE: Two resources are similar if all fields except 'medatata' are the same.

func ResourceNotExists

func ResourceNotExists(ctx *FeatureContext, s ScenarioContext)

ResourceNotExists implements the GoDoc step - `Kubernetes doesn't have <ApiGroupVersionKind> '<NamespacedName>'` It validates the fact that Kubernetes doesn't have the specified resource.

func UpdateResourceAnnotation

func UpdateResourceAnnotation(ctx *FeatureContext, s ScenarioContext)

UpdateResourceAnnotation implements the GoDoc step - `Kubernetes updates annotation <AnnotationName> on <ApiGroupVersionKind> '<NamespacedName>' with '<AnnotationValue>'` It updates the given annotation on the specified resource with the given value.

func UpdateResourceLabel

func UpdateResourceLabel(ctx *FeatureContext, s ScenarioContext)

UpdateResourceLabel implements the GoDoc step - `Kubernetes updates label <LabelName> on <ApiGroupVersionKind> '<NamespacedName>' with '<LabelValue>'` It updates the given label on the specified resource with the given value.

Types

type FeatureContext

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

FeatureContext extends GoDoc in order to implement step definitions for Kubernetes.

func NewEmptyFeatureContext

func NewEmptyFeatureContext(s ScenarioContext, opts ...FeatureContextOption) (*FeatureContext, error)

NewEmptyFeatureContext returns a new instance of the Kubernetes feature context, without any step injected.

func NewFeatureContext

func NewFeatureContext(s ScenarioContext, opts ...FeatureContextOption) (*FeatureContext, error)

NewFeatureContext returns a new instance of the Kubernetes feature context, with all step injected. If you want to choose which steps must be enabled, use NewEmptyFeatureContext instead.

func (FeatureContext) Client

func (ctx FeatureContext) Client() client.Client

Client returns the Kubernetes client used by the FeatureContext.

func (*FeatureContext) Create

func (ctx *FeatureContext) Create(
	groupVersionKind schema.GroupVersionKind,
	namespacedName types.NamespacedName,
	obj *unstructured.Unstructured,
	opts ...client.CreateOption,
) error

Create creates a Kubernetes resource based on the given APIVersion/Kind, the name and the object definition itself. It allows us to easily manage all resources through Unstructured object with the "official" Kubernetes client.Client interface.

func (*FeatureContext) Delete

func (ctx *FeatureContext) Delete(
	groupVersionKind schema.GroupVersionKind,
	namespacedName types.NamespacedName,
) (*unstructured.Unstructured, error)

Delete deletes a Kubernetes resource based on the given APIVersion/Kind and the name, and returns the removed object. If a garbage collector is set to the context, it will call it on the removed resource.

func (*FeatureContext) DeleteWithoutGC

func (ctx *FeatureContext) DeleteWithoutGC(
	groupVersionKind schema.GroupVersionKind,
	namespacedName types.NamespacedName,
) (*unstructured.Unstructured, error)

DeleteWithoutGC deletes a Kubernetes resource based on the given APIVersion/Kind and the name, and returns the removed object. Therefore, it never calls the garbage collector.

func (FeatureContext) GarbageCollector

func (ctx FeatureContext) GarbageCollector() func(*FeatureContext, *unstructured.Unstructured) error

GarbageCollector returns the garbage collector implementation used by the FeatureContext.

func (*FeatureContext) Get

func (ctx *FeatureContext) Get(
	groupVersionKind schema.GroupVersionKind,
	namespacedName types.NamespacedName,
) (*unstructured.Unstructured, error)

Get fetches the Kubernetes resource using the given APIVersion/Kind and the name. It wraps the Get method of the "official" Kubernetes client.Client interface, but returns an Unstructured object, more easier to use.

func (FeatureContext) GoContext

func (ctx FeatureContext) GoContext() context.Context

GoContext returns the golang context used by the FeatureContext.

func (*FeatureContext) List

func (ctx *FeatureContext) List(
	groupVersionKind schema.GroupVersionKind,
	opts ...client.ListOption,
) ([]*unstructured.Unstructured, error)

List returns all Kubernetes resources based on the given APIVersion/Kind. It returns a List of Unstructured object, more easier to use.

func (*FeatureContext) Patch

func (ctx *FeatureContext) Patch(
	groupVersionKind schema.GroupVersionKind,
	namespacedName types.NamespacedName,
	pt types.PatchType,
	data []byte,
) error

Patch patches a Kubernetes resource based on the given APIVersion/Kind and the name with the given Patch value.

func (FeatureContext) Scheme

func (ctx FeatureContext) Scheme() Scheme

Scheme returns the Kubernetes scheme used by the FeatureContext.

func (*FeatureContext) Update

func (ctx *FeatureContext) Update(
	groupVersionKind schema.GroupVersionKind,
	namespacedName types.NamespacedName,
	obj *unstructured.Unstructured,
	opts ...client.UpdateOption,
) error

Update updates a Kubernetes resource based on the given APIVersion/Kind and the name with the given Unstructured object.

type FeatureContextOption

type FeatureContextOption interface {
	ApplyToFeatureContext(*FeatureContext)
}

FeatureContextOption is some configuration that modifies options for the Kubernetes feature context.

type FeatureContextOptionFnc

type FeatureContextOptionFnc func(*FeatureContext)

FeatureContextOptionFnc wraps a function to implement the FeatureContextOption interface.

func WithClient

func WithClient(scheme Scheme, client client.Client) FeatureContextOptionFnc

WithClient inject the given client inside the Kubernetes feature context.

func WithContext

func WithContext(goctx context.Context) FeatureContextOptionFnc

WithContext inject a context to the Kubernetes feature context, used during the client's call.

func WithCustomGarbageCollector

func WithCustomGarbageCollector(gc func(*FeatureContext, *unstructured.Unstructured) error) FeatureContextOptionFnc

WithCustomGarbageCollector inject the given GarbageCollector to the feature context. This garbage collector is used to Delete children objects when a parent is removed. It is required because the fake client doesn't implement it.

func WithFakeClient

func WithFakeClient(scheme *runtime.Scheme) FeatureContextOptionFnc

WithFakeClient instantiate a new Kubernetes client with the given scheme. It automatically inject the NaiveGC as garbage collector if any is provided.

func WithFakeRuntimeClient

func WithFakeRuntimeClient() FeatureContextOptionFnc

WithFakeRuntimeClient instantiate a new Kubernetes client with the default scheme. It automatically inject the NaiveGC as garbage collector if any is provided.

func (FeatureContextOptionFnc) ApplyToFeatureContext

func (fnc FeatureContextOptionFnc) ApplyToFeatureContext(ctx *FeatureContext)

type ScenarioContext

type ScenarioContext interface {
	BeforeScenario(fn func(sc *godog.Scenario))
	AfterScenario(fn func(sc *godog.Scenario, err error))
	BeforeStep(fn func(st *godog.Step))
	AfterStep(fn func(st *godog.Step, err error))
	Step(expr, stepFunc interface{})
}

ScenarioContext wraps godog.ScenarioContext in order to easily mock it for internal tests.

type Scheme

type Scheme interface {
	runtime.ObjectCreater
	runtime.ObjectTyper
}

Scheme abstracts the implementation of common operations on objects.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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