utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package utils contains a collection of utilities for the controller test suites

Index

Constants

This section is empty.

Variables

View Source
var ExampleDaemonSet = &appsv1.DaemonSet{
	ObjectMeta: metav1.ObjectMeta{
		Name:      "example-daemonset",
		Namespace: "default",
		Labels:    exampleApp,
	},
	TypeMeta: metav1.TypeMeta{
		Kind:       "DaemonSet",
		APIVersion: "appsv1",
	},
	Spec: appsv1.DaemonSetSpec{
		Selector: &metav1.LabelSelector{
			MatchLabels: exampleApp,
		},
		Template: corev1.PodTemplateSpec{
			ObjectMeta: metav1.ObjectMeta{
				Labels: exampleApp,
			},
			Spec: corev1.PodSpec{
				Containers: []corev1.Container{
					{
						Name:  "pause",
						Image: "k8s.gcr.io/pause",
					},
				},
			},
		},
	},
}

ExampleDaemonSet is an example Daemonset for use in tests

View Source
var ExampleNodeMaster1 = &corev1.Node{
	ObjectMeta: metav1.ObjectMeta{
		Name: "example-master-1",
		Labels: map[string]string{
			"node-role.kubernetes.io/master": "true",
			"node-role.kubernetes.io/worker": "false",
		},
	},
}

ExampleNodeMaster1 is an example Node for use in tests

View Source
var ExampleNodeMaster2 = &corev1.Node{
	ObjectMeta: metav1.ObjectMeta{
		Name: "example-master-2",
		Labels: map[string]string{
			"node-role.kubernetes.io/master": "true",
			"node-role.kubernetes.io/worker": "false",
		},
	},
}

ExampleNodeMaster2 is an example Node for use in tests

View Source
var ExampleNodeOther = &corev1.Node{
	ObjectMeta: metav1.ObjectMeta{
		Name: "example-other",
		Labels: map[string]string{
			"node-role.kubernetes.io/other":  "true",
			"node-role.kubernetes.io/master": "false",
			"node-role.kubernetes.io/worker": "false",
		},
	},
}

ExampleNodeOther is an example Node for use in tests

View Source
var ExampleNodeReplacement = &navarchosv1alpha1.NodeReplacement{
	ObjectMeta: metav1.ObjectMeta{
		Name: "example",
	},
	Status: navarchosv1alpha1.NodeReplacementStatus{
		Phase: navarchosv1alpha1.ReplacementPhaseNew,
	},
	Spec: navarchosv1alpha1.NodeReplacementSpec{
		ReplacementSpec: navarchosv1alpha1.ReplacementSpec{
			Priority: intPtr(0),
		},
	},
}

ExampleNodeReplacement represents an example NodeReplacement for use in tests

View Source
var ExampleNodeRollout = &navarchosv1alpha1.NodeRollout{
	ObjectMeta: metav1.ObjectMeta{
		Name: "example",
	},
	Spec: navarchosv1alpha1.NodeRolloutSpec{
		NodeSelectors: []navarchosv1alpha1.NodeLabelSelector{
			{
				ReplacementSpec: navarchosv1alpha1.ReplacementSpec{
					Priority: intPtr(15),
				},
				LabelSelector: metav1.LabelSelector{
					MatchLabels: map[string]string{
						"node-role.kubernetes.io/master": "true",
					},
				},
			},
			{
				ReplacementSpec: navarchosv1alpha1.ReplacementSpec{
					Priority: intPtr(5),
				},
				LabelSelector: metav1.LabelSelector{
					MatchLabels: map[string]string{
						"node-role.kubernetes.io/worker": "true",
					},
				},
			},
		},
		NodeNames: []navarchosv1alpha1.NodeName{
			{
				Name: "example-master-1",
				ReplacementSpec: navarchosv1alpha1.ReplacementSpec{
					Priority: intPtr(20),
				},
			},
			{
				Name: "example-worker-1",
				ReplacementSpec: navarchosv1alpha1.ReplacementSpec{
					Priority: intPtr(10),
				},
			},
		},
	},
	Status: navarchosv1alpha1.NodeRolloutStatus{
		Phase: navarchosv1alpha1.RolloutPhaseNew,
	},
}

ExampleNodeRollout represents an example NodeRollout for use in tests

View Source
var ExampleNodeWorker1 = &corev1.Node{
	ObjectMeta: metav1.ObjectMeta{
		Name: "example-worker-1",
		Labels: map[string]string{
			"node-role.kubernetes.io/worker": "true",
			"node-role.kubernetes.io/master": "false",
		},
	},
}

ExampleNodeWorker1 is an example Node for use in tests

View Source
var ExampleNodeWorker2 = &corev1.Node{
	ObjectMeta: metav1.ObjectMeta{
		Name: "example-worker-2",
		Labels: map[string]string{
			"node-role.kubernetes.io/worker": "true",
			"node-role.kubernetes.io/master": "false",
		},
	},
}

ExampleNodeWorker2 is an example Node for use in tests

View Source
var ExamplePod = &corev1.Pod{
	ObjectMeta: metav1.ObjectMeta{
		Name:      "example-pod",
		Namespace: "default",
	},
	Spec: corev1.PodSpec{
		Containers: []corev1.Container{
			{
				Name:  "pause",
				Image: "k8s.gcr.io/pause",
			},
		},
	},
}

ExamplePod is an example of a Pod for use in test

View Source
var ExamplePodDisruptionBudget = policyv1beta1.PodDisruptionBudget{
	ObjectMeta: metav1.ObjectMeta{
		Name:      "example-pdb",
		Namespace: "default",
	},
	Spec: policyv1beta1.PodDisruptionBudgetSpec{
		MaxUnavailable: &intStr1,
		Selector: &metav1.LabelSelector{
			MatchLabels: map[string]string{
				"block-eviction": "true",
			},
		},
	},
}

ExamplePodDisruptionBudget is an example PodDisruptionBudget for use in tests

Functions

func DeleteAll

func DeleteAll(cfg *rest.Config, timeout time.Duration, objLists ...runtime.Object)

DeleteAll lists and deletes all resources

func GetOwnerReferenceForDaemonSet

func GetOwnerReferenceForDaemonSet(ds *appsv1.DaemonSet) metav1.OwnerReference

GetOwnerReferenceForDaemonSet constructs an owner reference for the DaemonSet given

func GetOwnerReferenceForNode

func GetOwnerReferenceForNode(node *corev1.Node) metav1.OwnerReference

GetOwnerReferenceForNode constructs an owner reference for the Node given

func GetOwnerReferenceForNodeRollout

func GetOwnerReferenceForNodeRollout(nr *navarchosv1alpha1.NodeRollout) metav1.OwnerReference

GetOwnerReferenceForNodeRollout constructs an owner reference for the NodeRollout given

func WithField

func WithField(field string, matcher gtypes.GomegaMatcher) gtypes.GomegaMatcher

WithField gets the value of the named field from the object

func WithListItems

func WithListItems(matcher gtypes.GomegaMatcher) gtypes.GomegaMatcher

WithListItems returns the items of the list

Types

type Matcher

type Matcher struct {
	Client client.Client
}

Matcher has Gomega Matchers that use the controller-runtime client

func (*Matcher) Consistently

func (m *Matcher) Consistently(obj runtime.Object, intervals ...interface{}) gomega.GomegaAsyncAssertion

Consistently continually gets the object from the API for comparison

func (*Matcher) Create

func (m *Matcher) Create(obj Object, extras ...interface{}) gomega.GomegaAssertion

Create creates the object on the API server

func (*Matcher) Delete

func (m *Matcher) Delete(obj Object, extras ...interface{}) gomega.GomegaAssertion

Delete deletes the object from the API server

func (*Matcher) Eventually

func (m *Matcher) Eventually(obj runtime.Object, intervals ...interface{}) gomega.GomegaAsyncAssertion

Eventually continually gets the object from the API for comparison

func (*Matcher) Get

func (m *Matcher) Get(obj Object, intervals ...interface{}) gomega.GomegaAsyncAssertion

Get gets the object from the API server

func (*Matcher) List

func (m *Matcher) List(obj runtime.Object, intervals ...interface{}) gomega.GomegaAsyncAssertion

List gets the list object from the API server

func (*Matcher) Update

func (m *Matcher) Update(obj Object, fn UpdateFunc, intervals ...interface{}) gomega.GomegaAsyncAssertion

Update udpates the object on the API server by fetching the object and applying a mutating UpdateFunc before sending the update

func (*Matcher) UpdateStatus

func (m *Matcher) UpdateStatus(obj Object, fn UpdateFunc, intervals ...interface{}) gomega.GomegaAsyncAssertion

UpdateStatus udpates the object's status subresource on the API server by fetching the object and applying a mutating UpdateFunc before sending the update

type Object

type Object interface {
	runtime.Object
	metav1.Object
}

Object is the combination of two interfaces as a helper for passing Kubernetes objects between methods

type UpdateFunc

type UpdateFunc func(Object) Object

UpdateFunc modifies the object fetched from the API server before sending the update

Jump to

Keyboard shortcuts

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