conversion

package
v3.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NamespaceLabelPrefix            = "pcns."
	NamespaceProfileNamePrefix      = "kns."
	K8sNetworkPolicyNamePrefix      = "knp.default."
	ServiceAccountLabelPrefix       = "pcsa."
	ServiceAccountProfileNamePrefix = "ksa."

	// AnnotationPodIP is an annotation we apply to pods when assigning them an IP.  It
	// duplicates the value of the Pod.Status.PodIP field, which is set by kubelet but,
	// since we write it ourselves, we can make sure that it is written synchronously
	// and quickly.
	AnnotationPodIP = "cni.projectcalico.org/podIP"
)
View Source
const (
	SelectorNamespace selectorType = iota
	SelectorPod
)

Variables

This section is empty.

Functions

func VethNameForWorkload

func VethNameForWorkload(namespace, podname string) string

VethNameForWorkload returns a deterministic veth name for the given Kubernetes workload (WEP) name and namespace.

Types

type Converter

type Converter struct{}

TODO: make this private and expose a public conversion interface instead

func (Converter) GetPodIPs

func (c Converter) GetPodIPs(pod *kapiv1.Pod) ([]string, error)

GetPodIPs extracts the IP addresses from a Kubernetes Pod. At present, only a single IP is expected/supported. GetPodIPs loads the IP either from the PodIP field, if present, or the calico podIP annotation.

func (Converter) HasIPAddress

func (c Converter) HasIPAddress(pod *kapiv1.Pod) bool

func (Converter) IsFinished

func (c Converter) IsFinished(pod *kapiv1.Pod) bool

func (Converter) IsHostNetworked

func (c Converter) IsHostNetworked(pod *kapiv1.Pod) bool

func (Converter) IsReadyCalicoPod

func (c Converter) IsReadyCalicoPod(pod *kapiv1.Pod) bool

IsReadyCalicoPod returns true if the pod is a valid Calico WorkloadEndpoint and has an IP address assigned (i.e. it's ready for Calico networking).

func (Converter) IsScheduled

func (c Converter) IsScheduled(pod *kapiv1.Pod) bool

func (Converter) IsValidCalicoWorkloadEndpoint

func (c Converter) IsValidCalicoWorkloadEndpoint(pod *kapiv1.Pod) bool

IsValidCalicoWorkloadEndpoint returns true if the pod should be shown as a workloadEndpoint in the Calico API and false otherwise. Note: since we completely ignore notifications for invalid Pods, it is important that pods can only transition from not-valid to valid and not the other way. If they transition from valid to invalid, we'll fail to emit a deletion event in the watcher.

func (Converter) JoinNetworkPolicyRevisions

func (c Converter) JoinNetworkPolicyRevisions(crdNPRev, k8sNPRev string) string

JoinNetworkPolicyRevisions constructs the revision from the individual CRD and K8s NetworkPolicy revisions.

func (Converter) JoinProfileRevisions

func (c Converter) JoinProfileRevisions(nsRev, saRev string) string

JoinProfileRevisions constructs the revision from the individual namespace and serviceaccount revisions. This is conditional on the feature flag for serviceaccount set or not.

func (Converter) K8sNetworkPolicyToCalico

func (c Converter) K8sNetworkPolicyToCalico(np *networkingv1.NetworkPolicy) (*model.KVPair, error)

K8sNetworkPolicyToCalico converts a k8s NetworkPolicy to a model.KVPair.

func (Converter) NamespaceToProfile

func (c Converter) NamespaceToProfile(ns *kapiv1.Namespace) (*model.KVPair, error)

NamespaceToProfile converts a Namespace to a Calico Profile. The Profile stores labels from the Namespace which are inherited by the WorkloadEndpoints within the Profile. This Profile also has the default ingress and egress rules, which are both 'allow'.

func (Converter) ParseWorkloadEndpointName

func (c Converter) ParseWorkloadEndpointName(workloadName string) (names.WorkloadEndpointIdentifiers, error)

ParseWorkloadName extracts the Node name, Orchestrator, Pod name and endpoint from the given WorkloadEndpoint name. The expected format for k8s is <node>-k8s-<pod>-<endpoint>

func (Converter) PodToWorkloadEndpoint

func (c Converter) PodToWorkloadEndpoint(pod *kapiv1.Pod) (*model.KVPair, error)

PodToWorkloadEndpoint converts a Pod to a WorkloadEndpoint. It assumes the calling code has verified that the provided Pod is valid to convert to a WorkloadEndpoint. PodToWorkloadEndpoint requires a Pods Name and Node Name to be populated. It will fail to convert from a Pod to WorkloadEndpoint otherwise.

func (Converter) ProfileNameToNamespace

func (c Converter) ProfileNameToNamespace(profileName string) (string, error)

ProfileNameToNamespace extracts the Namespace name from the given Profile name.

func (Converter) ProfileNameToServiceAccount

func (c Converter) ProfileNameToServiceAccount(profileName string) (ns, sa string, err error)

ProfileNameToServiceAccount extracts the ServiceAccount name from the given Profile name.

func (Converter) ServiceAccountToProfile

func (c Converter) ServiceAccountToProfile(sa *kapiv1.ServiceAccount) (*model.KVPair, error)

ServiceAccountToProfile converts a ServiceAccount to a Calico Profile. The Profile stores labels from the ServiceAccount which are inherited by the WorkloadEndpoints within the Profile.

func (Converter) SplitNetworkPolicyRevision

func (c Converter) SplitNetworkPolicyRevision(rev string) (crdNPRev string, k8sNPRev string, err error)

SplitNetworkPolicyRevision extracts the CRD and K8s NetworkPolicy revisions from the combined revision returned on the KDD NetworkPolicy client.

func (Converter) SplitProfileRevision

func (c Converter) SplitProfileRevision(rev string) (nsRev string, saRev string, err error)

SplitProfileRevision extracts the namespace and serviceaccount revisions from the combined revision returned on the KDD service account based profile. This is conditional on the feature flag for serviceaccount set or not.

Jump to

Keyboard shortcuts

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