utils

package
v0.0.0-...-0e91a63 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client() (*kubernetes.Clientset, error)

Types

type Connectivity

type Connectivity struct {
	From        Pod
	To          Pod
	IsConnected bool
}

type Kubernetes

type Kubernetes struct {
	ClientSet *kubernetes.Clientset
	// contains filtered or unexported fields
}

func NewKubernetes

func NewKubernetes() (*Kubernetes, error)

func (*Kubernetes) CleanNetworkPolicies

func (k *Kubernetes) CleanNetworkPolicies(namespaces []string) error

CleanNetworkPolicies is a convenience function for deleting network policies before startup of any new test.

func (*Kubernetes) CreateOrUpdateDeployment

func (k *Kubernetes) CreateOrUpdateDeployment(ns, deploymentName string, replicas int32, labels map[string]string) (*appsv1.Deployment, error)

CreateOrUpdateDeployment is a convenience function for idempotent setup of deployments

func (*Kubernetes) CreateOrUpdateNamespace

func (k *Kubernetes) CreateOrUpdateNamespace(n string, labels map[string]string) (*v1.Namespace, error)

CreateOrUpdateNamespace is a convenience function for idempotent setup of namespaces

func (*Kubernetes) CreateOrUpdateNetworkPolicy

func (k *Kubernetes) CreateOrUpdateNetworkPolicy(ns string, netpol *v1net.NetworkPolicy) (*v1net.NetworkPolicy, error)

CreateOrUpdateNetworkPolicy is a convenience function for updating/creating netpols. Updating is important since some tests update a network policy to confirm that mutation works with a CNI.

func (*Kubernetes) ExecuteRemoteCommand

func (k *Kubernetes) ExecuteRemoteCommand(pod v1.Pod, cname string, command []string) (string, string, error)

ExecuteRemoteCommand executes a remote shell command on the given pod returns the output from stdout and stderr

func (*Kubernetes) GetPod

func (k *Kubernetes) GetPod(ns string, name string) (*v1.Pod, error)

GetPod returns a pod with the matching namespace and name

func (*Kubernetes) GetPods

func (k *Kubernetes) GetPods(ns string, key string, val string) ([]v1.Pod, error)

GetPods returns an array of all pods in the given namespace having a k/v label pair.

func (*Kubernetes) Probe

func (k *Kubernetes) Probe(ns1, pod1, ns2, pod2 string, port int) (bool, error)

Probe execs into a pod and checks its connectivity to another pod. Of course it assumes that the target pod is serving on the input port, and also that wget is installed. For perf it uses spider rather then actually getting the full contents.

type NetworkPolicySpecBuilder

type NetworkPolicySpecBuilder struct {
	Spec      networkingv1.NetworkPolicySpec
	Name      string
	Namespace string
}

func (*NetworkPolicySpecBuilder) AddEgress

func (n *NetworkPolicySpecBuilder) AddEgress(protoc v1.Protocol, port *int, portName *string, cidr *string, exceptCIDRs []string, podSelector map[string]string, nsSelector map[string]string, podSelectorMatchExp *[]metav1.LabelSelectorRequirement, nsSelectorMatchExp *[]metav1.LabelSelectorRequirement) *NetworkPolicySpecBuilder

func (*NetworkPolicySpecBuilder) AddIngress

func (n *NetworkPolicySpecBuilder) AddIngress(protoc v1.Protocol, port *int, portName *string, cidr *string, exceptCIDRs []string, podSelector map[string]string, nsSelector map[string]string, podSelectorMatchExp *[]metav1.LabelSelectorRequirement, nsSelectorMatchExp *[]metav1.LabelSelectorRequirement) *NetworkPolicySpecBuilder

TODO: Add tests to match expressions

func (*NetworkPolicySpecBuilder) Get

func (*NetworkPolicySpecBuilder) SetName

func (n *NetworkPolicySpecBuilder) SetName(namespace string, name string) *NetworkPolicySpecBuilder

func (*NetworkPolicySpecBuilder) SetPodSelector

func (n *NetworkPolicySpecBuilder) SetPodSelector(labels map[string]string) *NetworkPolicySpecBuilder

func (*NetworkPolicySpecBuilder) SetTypeBoth

func (*NetworkPolicySpecBuilder) SetTypeEgress

func (*NetworkPolicySpecBuilder) SetTypeIngress

func (*NetworkPolicySpecBuilder) WithEgressDNS

AddEgressDNS mutates the nth policy rule to allow DNS, convenience method

type Pod

type Pod string

func NewPod

func NewPod(namespace string, podName string) Pod

func (Pod) Namespace

func (pod Pod) Namespace() string

func (Pod) PodName

func (pod Pod) PodName() string

func (Pod) String

func (pod Pod) String() string

type Reachability

type Reachability struct {
	Expected *TruthTable
	Observed *TruthTable
	Pods     []Pod
}

func NewReachability

func NewReachability(pods []Pod, defaultExpectation bool) *Reachability

func (*Reachability) Expect

func (r *Reachability) Expect(pod1 Pod, pod2 Pod, isConnected bool)

func (*Reachability) ExpectAllEgress

func (r *Reachability) ExpectAllEgress(pod Pod, connected bool)

ExpectAllEgress defines that any traffic going out of the pod will be allowed/denied (true/false)

func (*Reachability) ExpectAllIngress

func (r *Reachability) ExpectAllIngress(pod Pod, connected bool)

ExpectAllIngress defines that any traffic going into the pod will be allowed/denied (true/false)

func (*Reachability) ExpectConn

func (r *Reachability) ExpectConn(spec *Connectivity)

ExpectConn is an experimental way to describe connectivity with named fields

func (*Reachability) Observe

func (r *Reachability) Observe(pod1 Pod, pod2 Pod, isConnected bool)

func (*Reachability) PrintSummary

func (r *Reachability) PrintSummary(printExpected bool, printObserved bool, printComparison bool)

func (*Reachability) Summary

func (r *Reachability) Summary() (trueObs int, falseObs int, comparison *TruthTable)

type TruthTable

type TruthTable struct {
	Items []string

	Values map[string]map[string]bool
	// contains filtered or unexported fields
}

func NewTruthTable

func NewTruthTable(items []string, defaultValue *bool) *TruthTable

func (*TruthTable) Compare

func (tt *TruthTable) Compare(other *TruthTable) *TruthTable

func (*TruthTable) Get

func (tt *TruthTable) Get(from string, to string) bool

func (*TruthTable) IsComplete

func (tt *TruthTable) IsComplete() bool

IsComplete returns true if there's a value set for every single pair of items, otherwise it returns false.

func (*TruthTable) PrettyPrint

func (tt *TruthTable) PrettyPrint(indent string) string

func (*TruthTable) Set

func (tt *TruthTable) Set(from string, to string, value bool)

func (*TruthTable) SetAllFrom

func (tt *TruthTable) SetAllFrom(from string, value bool)

func (*TruthTable) SetAllTo

func (tt *TruthTable) SetAllTo(to string, value bool)

Jump to

Keyboard shortcuts

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