testing_helper

package
v0.0.0-...-bc30bd0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePodGroup

func CreatePodGroup(namespace, name string, minMember int32, priorityClassName string) *schedulingv1a1.PodGroup

func MakeNodesAndPods

func MakeNodesAndPods(existingPodsNum, allNodesNum int) (existingPods []*v1.Pod, allNodes []*v1.Node)

MakeNodesAndPods serves as a testing helper to generate regular Nodes and Pods that don't use any advanced scheduling features.

func MakeNodesAndPodsForEvenPodsSpread

func MakeNodesAndPodsForEvenPodsSpread(labels map[string]string, existingPodsNum, allNodesNum, filteredNodesNum int) (existingPods []*v1.Pod, allNodes []*v1.Node, filteredNodes []*v1.Node)

MakeNodesAndPodsForEvenPodsSpread serves as a testing helper for EvenPodsSpread feature. It builds a fake cluster containing running Pods and Nodes. The size of Pods and Nodes are determined by input arguments. The specs of Pods and Nodes are generated with the following rules:

  • Each generated node is applied with a unique label: "node: node<i>".
  • Each generated node is applied with a rotating label: "zone: zone[0-9]".
  • Depending on the input labels, each generated pod will be applied with label "key1", "key1,key2", ..., "key1,key2,...,keyN" in a rotating manner.

func MakeNodesAndPodsForPodAffinity

func MakeNodesAndPodsForPodAffinity(existingPodsNum, allNodesNum int) (existingPods []*v1.Pod, allNodes []*v1.Node)

MakeNodesAndPodsForPodAffinity serves as a testing helper for Pod(Anti)Affinity feature. It builds a fake cluster containing running Pods and Nodes. For simplicity, the Nodes will be labelled with "region", "zone" and "node". Nodes[i] will be applied with: - "region": "region" + i%3 - "zone": "zone" + i%10 - "node": "node" + i The Pods will be applied with various combinations of PodAffinity and PodAntiAffinity terms.

func NewFakeDeploymentLister

func NewFakeDeploymentLister(deploys []*appsv1.Deployment) appv1listers.DeploymentLister

func NewFakeDeploymentNamespaceLister

func NewFakeDeploymentNamespaceLister(deploys []*appsv1.Deployment) appv1listers.DeploymentNamespaceLister

func NewFakePodLister

func NewFakePodLister(pods []*v1.Pod) corelisters.PodLister

func NewFakePodNamespaceLister

func NewFakePodNamespaceLister(pods []*v1.Pod) corelisters.PodNamespaceLister

func NewFakePriorityClassLister

func NewFakePriorityClassLister(pcs []*schedulingv1.PriorityClass) fakePriorityClassLister

Types

type DeploymentWrapper

type DeploymentWrapper struct {
	appsv1.Deployment
}

NodeWrapper wraps a Node inside.

func MakeDeploy

func MakeDeploy() *DeploymentWrapper

MakeDp creates a deploy wrapper.

func (*DeploymentWrapper) Annotation

func (dp *DeploymentWrapper) Annotation(key, value string) *DeploymentWrapper

func (*DeploymentWrapper) Name

set 'a' as .Name of the inner Deployment obj.

func (*DeploymentWrapper) Namespace

func (dp *DeploymentWrapper) Namespace(n string) *DeploymentWrapper

func (*DeploymentWrapper) Obj

func (dp *DeploymentWrapper) Obj() *appsv1.Deployment

Obj returns the inner deploy.

func (*DeploymentWrapper) Replicas

func (dp *DeploymentWrapper) Replicas(n uint) *DeploymentWrapper

set n as .Spec.Replicas of the inner deploy obj.

type LabelSelectorWrapper

type LabelSelectorWrapper struct{ metav1.LabelSelector }

LabelSelectorWrapper wraps a LabelSelector inside.

func MakeLabelSelector

func MakeLabelSelector() *LabelSelectorWrapper

MakeLabelSelector creates a LabelSelector wrapper.

func (*LabelSelectorWrapper) Exists

Exists injects a matchExpression (with an operator Exists) to the inner labelSelector.

func (*LabelSelectorWrapper) In

In injects a matchExpression (with an operator In) to the inner labelSelector.

func (*LabelSelectorWrapper) Label

Label applies a {k,v} pair to the inner LabelSelector.

func (*LabelSelectorWrapper) NotExist

NotExist injects a matchExpression (with an operator NotExist) to the inner labelSelector.

func (*LabelSelectorWrapper) NotIn

func (s *LabelSelectorWrapper) NotIn(key string, vals []string) *LabelSelectorWrapper

NotIn injects a matchExpression (with an operator NotIn) to the inner labelSelector.

func (*LabelSelectorWrapper) Obj

Obj returns the inner LabelSelector.

type NodeAffinityKind

type NodeAffinityKind int
const (
	NodeAffinityWithRequiredReq NodeAffinityKind = iota
	NodeAffinityWithPreferredReq
)

type NodeSelectorWrapper

type NodeSelectorWrapper struct{ v1.NodeSelector }

NodeSelectorWrapper wraps a NodeSelector inside.

func MakeNodeSelector

func MakeNodeSelector() *NodeSelectorWrapper

MakeNodeSelector creates a NodeSelector wrapper.

func (*NodeSelectorWrapper) In

In injects a matchExpression (with an operator IN) as a selectorTerm to the inner nodeSelector. NOTE: appended selecterTerms are ORed.

func (*NodeSelectorWrapper) NotIn

func (s *NodeSelectorWrapper) NotIn(key string, vals []string) *NodeSelectorWrapper

NotIn injects a matchExpression (with an operator NotIn) as a selectorTerm to the inner nodeSelector.

func (*NodeSelectorWrapper) Obj

Obj returns the inner NodeSelector.

type NodeWrapper

type NodeWrapper struct {
	v1.Node                             `json:"node"`
	katalystv1alpha1.CustomNodeResource `json:"cnr"`
}

NodeWrapper wraps a Node inside.

func MakeNode

func MakeNode() *NodeWrapper

MakeNode creates a Node wrapper.

func (*NodeWrapper) CNRCapacity

func (n *NodeWrapper) CNRCapacity(resources map[v1.ResourceName]string) *NodeWrapper

func (*NodeWrapper) CNRObj

func (*NodeWrapper) Capacity

func (n *NodeWrapper) Capacity(resources map[v1.ResourceName]string) *NodeWrapper

Capacity sets the capacity and the allocatable resources of the inner node. Each entry in `resources` corresponds to a resource name and its quantity. By default, the capacity and allocatable number of pods are set to 32.

func (*NodeWrapper) Images

func (n *NodeWrapper) Images(images map[string]int64) *NodeWrapper

Images sets the images of the inner node. Each entry in `images` corresponds to an image name and its size in bytes.

func (*NodeWrapper) Label

func (n *NodeWrapper) Label(k, v string) *NodeWrapper

Label applies a {k,v} label pair to the inner node.

func (*NodeWrapper) Name

func (n *NodeWrapper) Name(s string) *NodeWrapper

Name sets `s` as the name of the inner pod.

func (*NodeWrapper) NodeUID

func (n *NodeWrapper) NodeUID(s string) *NodeWrapper

NodeUID sets `s` as the UID of the inner pod.

func (*NodeWrapper) Obj

func (n *NodeWrapper) Obj() *v1.Node

Obj returns the inner Node.

type PDBWrapper

type PDBWrapper struct{ policy.PodDisruptionBudget }

PDBWrapper wrappers a pdb inside.

func MakePdb

func MakePdb() *PDBWrapper

MakePdb creates a pdb wrapper.

func (*PDBWrapper) DisruptionsAllowed

func (p *PDBWrapper) DisruptionsAllowed(n int32) *PDBWrapper

set 'a' as .Status.DisruptionsAllowed of the inner pdb obj.

func (*PDBWrapper) Label

func (p *PDBWrapper) Label(k, v string) *PDBWrapper

add 'k,v' to the selector of the inner pdb.

func (*PDBWrapper) Name

func (p *PDBWrapper) Name(name string) *PDBWrapper

func (*PDBWrapper) Namespace

func (p *PDBWrapper) Namespace(namespace string) *PDBWrapper

func (*PDBWrapper) Obj

Obj returns the inner pdb.

func (*PDBWrapper) Selector

func (p *PDBWrapper) Selector(selector *metav1.LabelSelector) *PDBWrapper

set 'selector' as .Spec.Selector of the inner pdb.

type PersistentVolumeClaimLister

type PersistentVolumeClaimLister []v1.PersistentVolumeClaim

PersistentVolumeClaimLister declares a []v1.PersistentVolumeClaim type for testing.

func (PersistentVolumeClaimLister) List

func (pvcs PersistentVolumeClaimLister) List(selector labels.Selector) (ret []*v1.PersistentVolumeClaim, err error)

List gets PVC matching the namespace and PVC ID.

func (PersistentVolumeClaimLister) PersistentVolumeClaims

PersistentVolumeClaims returns a fake PersistentVolumeClaimLister object.

type PodAffinityKind

type PodAffinityKind int

PodAffinityKind represents different kinds of PodAffinity.

const (
	// NilPodAffinity is a no-op which doesn't apply any PodAffinity.
	NilPodAffinity PodAffinityKind = iota
	// PodAffinityWithRequiredReq applies a HARD requirement to pod.spec.affinity.PodAffinity.
	PodAffinityWithRequiredReq
	// PodAffinityWithPreferredReq applies a SOFT requirement to pod.spec.affinity.PodAffinity.
	PodAffinityWithPreferredReq
	// PodAffinityWithRequiredPreferredReq applies HARD and SOFT requirements to pod.spec.affinity.PodAffinity.
	PodAffinityWithRequiredPreferredReq
	// PodAntiAffinityWithRequiredReq applies a HARD requirement to pod.spec.affinity.PodAntiAffinity.
	PodAntiAffinityWithRequiredReq
	// PodAntiAffinityWithPreferredReq applies a SOFT requirement to pod.spec.affinity.PodAntiAffinity.
	PodAntiAffinityWithPreferredReq
	// PodAntiAffinityWithRequiredPreferredReq applies HARD and SOFT requirements to pod.spec.affinity.PodAntiAffinity.
	PodAntiAffinityWithRequiredPreferredReq
)

type PodGroupWrapper

type PodGroupWrapper struct {
	schedulingv1a1.PodGroup
}

PodGroupWrapper wraps a PodGroup inside.

func MakePodGroup

func MakePodGroup() *PodGroupWrapper

MakeDp creates a deploy wrapper.

func (*PodGroupWrapper) MinMember

func (pg *PodGroupWrapper) MinMember(n uint) *PodGroupWrapper

set n as .Spec.MinMember of the inner PodGroup obj.

func (*PodGroupWrapper) Name

func (pg *PodGroupWrapper) Name(n string) *PodGroupWrapper

set 'a' as .Name of the inner PodGroup obj.

func (*PodGroupWrapper) Namespace

func (pg *PodGroupWrapper) Namespace(n string) *PodGroupWrapper

func (*PodGroupWrapper) Obj

Obj returns the inner pod group.

func (*PodGroupWrapper) Phase

func (*PodGroupWrapper) ProrityClassName

func (pg *PodGroupWrapper) ProrityClassName(n string) *PodGroupWrapper

set n as .Spec.PriorityClassName of the inner PodGroup obj.

type PodWrapper

type PodWrapper struct{ v1.Pod }

PodWrapper wraps a Pod inside.

func MakePod

func MakePod() *PodWrapper

MakePod creates a Pod wrapper.

func (*PodWrapper) Annotation

func (p *PodWrapper) Annotation(k, v string) *PodWrapper

Annotation sets a {k,v} pair to the inner pod.

func (*PodWrapper) Container

func (p *PodWrapper) Container(s string) *PodWrapper

Container appends a container into PodSpec of the inner pod.

func (*PodWrapper) ControllerRef

func (p *PodWrapper) ControllerRef(ref metav1.OwnerReference) *PodWrapper

func (*PodWrapper) Label

func (p *PodWrapper) Label(k, v string) *PodWrapper

Label sets a {k,v} pair to the inner pod.

func (*PodWrapper) Name

func (p *PodWrapper) Name(s string) *PodWrapper

Name sets `s` as the name of the inner pod.

func (*PodWrapper) Namespace

func (p *PodWrapper) Namespace(s string) *PodWrapper

Namespace sets `s` as the namespace of the inner pod.

func (*PodWrapper) Node

func (p *PodWrapper) Node(s string) *PodWrapper

Node sets `s` as the nodeName of the inner pod.

func (*PodWrapper) NodeAffinityIn

func (p *PodWrapper) NodeAffinityIn(key string, vals []string, kind NodeAffinityKind) *PodWrapper

NodeAffinityIn creates a HARD node affinity (with the operator In) and injects into the inner pod.

func (*PodWrapper) NodeAffinityNotIn

func (p *PodWrapper) NodeAffinityNotIn(key string, vals []string, kind NodeAffinityKind) *PodWrapper

NodeAffinityNotIn creates a HARD node affinity (with the operator NotIn) and injects into the inner pod.

func (*PodWrapper) NodeSelector

func (p *PodWrapper) NodeSelector(m map[string]string) *PodWrapper

NodeSelector sets `m` as the nodeSelector of the inner pod.

func (*PodWrapper) NominatedNodeName

func (p *PodWrapper) NominatedNodeName(n string) *PodWrapper

NominatedNodeName sets `n` as the .Status.NominatedNodeName of the inner pod.

func (*PodWrapper) Obj

func (p *PodWrapper) Obj() *v1.Pod

Obj returns the inner Pod.

func (*PodWrapper) PodAffinityExists

func (p *PodWrapper) PodAffinityExists(labelKey, topologyKey string, kind PodAffinityKind) *PodWrapper

PodAffinityExists creates an PodAffinity with the operator "Exists" and injects into the inner pod.

func (*PodWrapper) PodAntiAffinityExists

func (p *PodWrapper) PodAntiAffinityExists(labelKey, topologyKey string, kind PodAffinityKind) *PodWrapper

PodAntiAffinityExists creates an PodAntiAffinity with the operator "Exists" and injects into the inner pod.

func (*PodWrapper) PreemptionPolicy

func (p *PodWrapper) PreemptionPolicy(policy v1.PreemptionPolicy) *PodWrapper

PreemptionPolicy sets the give preemption policy to the inner pod.

func (*PodWrapper) Priority

func (p *PodWrapper) Priority(val int32) *PodWrapper

Priority sets a priority value into PodSpec of the inner pod.

func (*PodWrapper) PriorityClassName

func (p *PodWrapper) PriorityClassName(n string) *PodWrapper

PriorityClassName sets 'n' as .Spec.PriorityClassName to the inner pod.

func (*PodWrapper) Req

func (p *PodWrapper) Req(resMap map[v1.ResourceName]string) *PodWrapper

Req adds a new container to the inner pod with given resource map.

func (*PodWrapper) ResourceVersion

func (p *PodWrapper) ResourceVersion(v string) *PodWrapper

func (*PodWrapper) SchedulerName

func (p *PodWrapper) SchedulerName(s string) *PodWrapper

SchedulerName sets `s` as the scheduler name of the inner pod.

func (*PodWrapper) SetCreationTimestampAt

func (p *PodWrapper) SetCreationTimestampAt(creation time.Time) *PodWrapper

func (*PodWrapper) SpreadConstraint

func (p *PodWrapper) SpreadConstraint(maxSkew int, tpKey string, mode v1.UnsatisfiableConstraintAction, selector *metav1.LabelSelector) *PodWrapper

SpreadConstraint constructs a TopologySpreadConstraint object and injects into the inner pod.

func (*PodWrapper) StartTime

func (p *PodWrapper) StartTime(t metav1.Time) *PodWrapper

StartTime sets `t` as .status.startTime for the inner pod.

func (*PodWrapper) Terminating

func (p *PodWrapper) Terminating() *PodWrapper

Terminating sets the inner pod's deletionTimestamp to current timestamp.

func (*PodWrapper) UID

func (p *PodWrapper) UID(s string) *PodWrapper

UID sets `s` as the UID of the inner pod.

func (*PodWrapper) ZeroTerminationGracePeriod

func (p *PodWrapper) ZeroTerminationGracePeriod() *PodWrapper

ZeroTerminationGracePeriod sets the TerminationGracePeriodSeconds of the inner pod to zero.

type PriorityClassWrapper

type PriorityClassWrapper struct{ scheduling.PriorityClass }

PriorityClassWrapper wrappers a PriorityClass inside.

func MakePriorityClass

func MakePriorityClass() *PriorityClassWrapper

MakePriorityClass creates a PriorityClass wrapper.

func (*PriorityClassWrapper) Annotation

func (p *PriorityClassWrapper) Annotation(k, v string) *PriorityClassWrapper

func (*PriorityClassWrapper) Name

set 'a' as .Name of the inner PriorityClass obj.

func (*PriorityClassWrapper) Obj

Obj returns the inner pdb.

func (*PriorityClassWrapper) SetPreemptionPolicy

func (p *PriorityClassWrapper) SetPreemptionPolicy(policy v1.PreemptionPolicy) *PriorityClassWrapper

func (*PriorityClassWrapper) Value

set 'n' as .PriorityClass.Value of the inner PriorityClass obj.

type ReplicaSetWrapper

type ReplicaSetWrapper struct {
	appsv1.ReplicaSet
}

ReplicaSetWrapper wraps a ReplicaSet inside.

func MakeReplicaSet

func MakeReplicaSet() *ReplicaSetWrapper

MakeReplicaSet creates a replicaset wrapper.

func (*ReplicaSetWrapper) Label

func (rs *ReplicaSetWrapper) Label(k, v string) *ReplicaSetWrapper

Label applies a {k,v} label pair to the inner replicaset.

func (*ReplicaSetWrapper) Name

set 'a' as .Name of the inner ReplicaSet obj.

func (*ReplicaSetWrapper) Namespace

func (rs *ReplicaSetWrapper) Namespace(n string) *ReplicaSetWrapper

func (*ReplicaSetWrapper) Obj

func (rs *ReplicaSetWrapper) Obj() *appsv1.ReplicaSet

Obj returns the inner replicaset.

type ReservationWrapper

type ReservationWrapper struct {
	schedulingv1a1.Reservation
}

func MakeReservation

func MakeReservation() *ReservationWrapper

func (*ReservationWrapper) CreateTime

func (prr *ReservationWrapper) CreateTime(createTime metav1.Time) *ReservationWrapper

func (*ReservationWrapper) Obj

func (*ReservationWrapper) SetStatus

type StorageClassLister

type StorageClassLister []storagev1.StorageClass

StorageClassLister declares a []storagev1.StorageClass type for testing.

func (StorageClassLister) Get

func (classes StorageClassLister) Get(name string) (*storagev1.StorageClass, error)

Get returns a fake storage class object in the fake storage classes by name.

func (StorageClassLister) List

func (classes StorageClassLister) List(selector labels.Selector) ([]*storagev1.StorageClass, error)

List lists all StorageClass in the indexer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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