kube

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNamespaceLabel = "kubernetes.io/metadata.name"
)

Variables

This section is empty.

Functions

func DeleteAllNetworkPoliciesInNamespaces added in v0.4.0

func DeleteAllNetworkPoliciesInNamespaces(kubernetes IKubernetes, namespaces []string) error

func GetNetworkPoliciesInNamespaces added in v0.4.0

func GetNetworkPoliciesInNamespaces(kubernetes IKubernetes, namespaces []string) ([]networkingv1.NetworkPolicy, error)

func GetPodsInNamespaces added in v0.4.0

func GetPodsInNamespaces(kubernetes IKubernetes, namespaces []string) ([]v1.Pod, error)

func GetServicesInNamespaces added in v0.4.0

func GetServicesInNamespaces(kubernetes IKubernetes, namespaces []string) ([]v1.Service, error)

func IsIPAddressMatchForIPBlock

func IsIPAddressMatchForIPBlock(ip string, ipBlock *networkingv1.IPBlock) (bool, error)

func IsIPInCIDR

func IsIPInCIDR(ip string, cidr string) (bool, error)

func IsIPV4Address added in v0.4.4

func IsIPV4Address(s string) bool

func IsLabelSelectorEmpty added in v0.0.8

func IsLabelSelectorEmpty(l metav1.LabelSelector) bool

func IsLabelsMatchLabelSelector

func IsLabelsMatchLabelSelector(labels map[string]string, labelSelector metav1.LabelSelector) bool

IsLabelsMatchLabelSelector matches labels to a kube LabelSelector. From the docs: > A label selector is a label query over a set of resources. The result of matchLabels and > matchExpressions are ANDed. An empty label selector matches all objects. A null > label selector matches no objects.

func IsMatchExpressionMatchForLabels

func IsMatchExpressionMatchForLabels(labels map[string]string, exp metav1.LabelSelectorRequirement) bool

func IsNameMatch

func IsNameMatch(objectName string, matcher string) bool

IsNameMatch follows the kube pattern of "empty string means matches All" It will return:

if matcher is empty: true
if objectName and matcher are the same: true
otherwise false

func LabelSelectorTableLines added in v0.2.0

func LabelSelectorTableLines(selector metav1.LabelSelector) string

func MakeCIDRFromOnes added in v0.4.4

func MakeCIDRFromOnes(ipString string, ones int) string

func MakeCIDRFromZeroes added in v0.4.4

func MakeCIDRFromZeroes(ipString string, zeroes int) string

func NetworkPoliciesToTable added in v0.4.0

func NetworkPoliciesToTable(policies []*NetworkPolicy) string

func ParseProtocol added in v0.1.0

func ParseProtocol(protocol string) (v1.Protocol, error)

func PrintIPBlock added in v0.4.0

func PrintIPBlock(i IPBlock) string

func PrintNSPodPeer added in v0.4.0

func PrintNSPodPeer(nsSelector *metav1.LabelSelector, podSelector *metav1.LabelSelector) string

func PrintPeers added in v0.4.0

func PrintPeers(npPeers []NetworkPolicyPeer) string

func PrintPorts added in v0.4.0

func PrintPorts(npPorts []NetworkPolicyPort) string

func QualifiedServiceAddress

func QualifiedServiceAddress(serviceName string, namespace string) string

QualifiedServiceAddress returns the address that can be used to hit a service from any namespace in the cluster

func QualifiedServiceAddress(serviceName string, namespace string, dnsDomain string) string {
	return fmt.Sprintf("%s.%s.svc.%s", serviceName, namespace, dnsDomain)

func ReadNetworkPoliciesFromKube added in v0.5.3

func ReadNetworkPoliciesFromKube(kubeClient *Kubernetes, namespaces []string) ([]*networkingv1.NetworkPolicy, error)

func ReadNetworkPoliciesFromPath added in v0.5.3

func ReadNetworkPoliciesFromPath(policyPath string) ([]*networkingv1.NetworkPolicy, error)

func RunIPAddressTests added in v0.0.8

func RunIPAddressTests()

func RunLabelSelectorTests added in v0.2.4

func RunLabelSelectorTests()

func RunReadNetworkPolicyTests added in v0.5.3

func RunReadNetworkPolicyTests()

func SerializeLabelSelector added in v0.0.8

func SerializeLabelSelector(ls metav1.LabelSelector) string

SerializeLabelSelector deterministically converts a metav1.LabelSelector into a string

Types

type IKubernetes added in v0.3.0

type IKubernetes interface {
	CreateNamespace(kubeNamespace *v1.Namespace) (*v1.Namespace, error)
	GetNamespace(namespace string) (*v1.Namespace, error)
	SetNamespaceLabels(namespace string, labels map[string]string) (*v1.Namespace, error)
	DeleteNamespace(namespace string) error
	GetAllNamespaces() (*v1.NamespaceList, error)

	CreateNetworkPolicy(kubePolicy *networkingv1.NetworkPolicy) (*networkingv1.NetworkPolicy, error)
	GetNetworkPoliciesInNamespace(namespace string) ([]networkingv1.NetworkPolicy, error)
	UpdateNetworkPolicy(kubePolicy *networkingv1.NetworkPolicy) (*networkingv1.NetworkPolicy, error)
	DeleteNetworkPolicy(namespace string, name string) error
	DeleteAllNetworkPoliciesInNamespace(namespace string) error

	CreateService(kubeService *v1.Service) (*v1.Service, error)
	GetService(namespace string, name string) (*v1.Service, error)
	DeleteService(namespace string, name string) error
	GetServicesInNamespace(namespace string) ([]v1.Service, error)

	CreatePod(kubePod *v1.Pod) (*v1.Pod, error)
	GetPod(namespace string, pod string) (*v1.Pod, error)
	DeletePod(namespace string, pod string) error
	SetPodLabels(namespace string, pod string, labels map[string]string) (*v1.Pod, error)
	GetPodsInNamespace(namespace string) ([]v1.Pod, error)

	ExecuteRemoteCommand(namespace string, pod string, container string, command []string) (string, string, error, error)
}

type Kubernetes

type Kubernetes struct {
	ClientSet  *kubernetes.Clientset
	RestConfig *rest.Config
}

func NewKubernetesForContext added in v0.0.3

func NewKubernetesForContext(context string) (*Kubernetes, error)

func (*Kubernetes) CreateNamespace added in v0.3.0

func (k *Kubernetes) CreateNamespace(ns *v1.Namespace) (*v1.Namespace, error)

func (*Kubernetes) CreateNetworkPolicy

func (k *Kubernetes) CreateNetworkPolicy(policy *networkingv1.NetworkPolicy) (*networkingv1.NetworkPolicy, error)

func (*Kubernetes) CreatePod

func (k *Kubernetes) CreatePod(pod *v1.Pod) (*v1.Pod, error)

func (*Kubernetes) CreateService

func (k *Kubernetes) CreateService(svc *v1.Service) (*v1.Service, error)

func (*Kubernetes) DeleteAllNetworkPoliciesInNamespace

func (k *Kubernetes) DeleteAllNetworkPoliciesInNamespace(ns string) error

func (*Kubernetes) DeleteNamespace added in v0.1.1

func (k *Kubernetes) DeleteNamespace(ns string) error

func (*Kubernetes) DeleteNetworkPolicy added in v0.1.0

func (k *Kubernetes) DeleteNetworkPolicy(ns string, name string) error

func (*Kubernetes) DeletePod added in v0.2.4

func (k *Kubernetes) DeletePod(namespace string, podName string) error

func (*Kubernetes) DeleteService added in v0.2.4

func (k *Kubernetes) DeleteService(namespace string, name string) error

func (*Kubernetes) ExecuteRemoteCommand

func (k *Kubernetes) ExecuteRemoteCommand(namespace string, pod string, container string, command []string) (string, string, error, error)

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

func (*Kubernetes) GetAllNamespaces added in v0.3.1

func (k *Kubernetes) GetAllNamespaces() (*v1.NamespaceList, error)

func (*Kubernetes) GetNamespace added in v0.1.0

func (k *Kubernetes) GetNamespace(namespace string) (*v1.Namespace, error)

func (*Kubernetes) GetNetworkPoliciesInNamespace added in v0.4.0

func (k *Kubernetes) GetNetworkPoliciesInNamespace(namespace string) ([]networkingv1.NetworkPolicy, error)

func (*Kubernetes) GetPod

func (k *Kubernetes) GetPod(namespace string, podName string) (*v1.Pod, error)

func (*Kubernetes) GetPodsInNamespace added in v0.4.0

func (k *Kubernetes) GetPodsInNamespace(namespace string) ([]v1.Pod, error)

func (*Kubernetes) GetService added in v0.1.0

func (k *Kubernetes) GetService(namespace string, name string) (*v1.Service, error)

func (*Kubernetes) GetServicesInNamespace added in v0.4.0

func (k *Kubernetes) GetServicesInNamespace(namespace string) ([]v1.Service, error)

func (*Kubernetes) SetNamespaceLabels added in v0.1.0

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

func (*Kubernetes) SetPodLabels added in v0.1.0

func (k *Kubernetes) SetPodLabels(namespace string, podName string, labels map[string]string) (*v1.Pod, error)

func (*Kubernetes) UpdateNetworkPolicy added in v0.1.0

func (k *Kubernetes) UpdateNetworkPolicy(policy *networkingv1.NetworkPolicy) (*networkingv1.NetworkPolicy, error)

type MockKubernetes added in v0.3.0

type MockKubernetes struct {
	Namespaces map[string]*MockNamespace
	// contains filtered or unexported fields
}

func NewMockKubernetes added in v0.3.0

func NewMockKubernetes(passRate float64) *MockKubernetes

func (*MockKubernetes) CreateNamespace added in v0.3.0

func (m *MockKubernetes) CreateNamespace(ns *v1.Namespace) (*v1.Namespace, error)

func (*MockKubernetes) CreateNetworkPolicy added in v0.3.0

func (m *MockKubernetes) CreateNetworkPolicy(policy *networkingv1.NetworkPolicy) (*networkingv1.NetworkPolicy, error)

func (*MockKubernetes) CreatePod added in v0.3.0

func (m *MockKubernetes) CreatePod(pod *v1.Pod) (*v1.Pod, error)

func (*MockKubernetes) CreateService added in v0.3.0

func (m *MockKubernetes) CreateService(svc *v1.Service) (*v1.Service, error)

func (*MockKubernetes) DeleteAllNetworkPoliciesInNamespace added in v0.3.0

func (m *MockKubernetes) DeleteAllNetworkPoliciesInNamespace(ns string) error

func (*MockKubernetes) DeleteNamespace added in v0.3.0

func (m *MockKubernetes) DeleteNamespace(ns string) error

func (*MockKubernetes) DeleteNetworkPolicy added in v0.3.0

func (m *MockKubernetes) DeleteNetworkPolicy(ns string, name string) error

func (*MockKubernetes) DeletePod added in v0.3.0

func (m *MockKubernetes) DeletePod(namespace string, podName string) error

func (*MockKubernetes) DeleteService added in v0.3.0

func (m *MockKubernetes) DeleteService(namespace string, name string) error

func (*MockKubernetes) ExecuteRemoteCommand added in v0.3.0

func (m *MockKubernetes) ExecuteRemoteCommand(namespace string, pod string, container string, command []string) (string, string, error, error)

func (*MockKubernetes) GetAllNamespaces added in v0.4.7

func (m *MockKubernetes) GetAllNamespaces() (*v1.NamespaceList, error)

func (*MockKubernetes) GetNamespace added in v0.3.0

func (m *MockKubernetes) GetNamespace(namespace string) (*v1.Namespace, error)

func (*MockKubernetes) GetNetworkPoliciesInNamespace added in v0.4.0

func (m *MockKubernetes) GetNetworkPoliciesInNamespace(namespace string) ([]networkingv1.NetworkPolicy, error)

func (*MockKubernetes) GetPod added in v0.3.0

func (m *MockKubernetes) GetPod(namespace string, podName string) (*v1.Pod, error)

func (*MockKubernetes) GetPodsInNamespace added in v0.4.0

func (m *MockKubernetes) GetPodsInNamespace(namespace string) ([]v1.Pod, error)

func (*MockKubernetes) GetService added in v0.3.0

func (m *MockKubernetes) GetService(namespace string, name string) (*v1.Service, error)

func (*MockKubernetes) GetServicesInNamespace added in v0.4.0

func (m *MockKubernetes) GetServicesInNamespace(namespace string) ([]v1.Service, error)

func (*MockKubernetes) SetNamespaceLabels added in v0.3.0

func (m *MockKubernetes) SetNamespaceLabels(namespace string, labels map[string]string) (*v1.Namespace, error)

func (*MockKubernetes) SetPodLabels added in v0.3.0

func (m *MockKubernetes) SetPodLabels(namespace string, podName string, labels map[string]string) (*v1.Pod, error)

func (*MockKubernetes) UpdateNetworkPolicy added in v0.3.0

func (m *MockKubernetes) UpdateNetworkPolicy(policy *networkingv1.NetworkPolicy) (*networkingv1.NetworkPolicy, error)

type MockNamespace added in v0.3.0

type MockNamespace struct {
	NamespaceObject *v1.Namespace
	Netpols         map[string]*networkingv1.NetworkPolicy
	Pods            map[string]*v1.Pod
	Services        map[string]*v1.Service
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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