utils

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractNamespace

func ExtractNamespace(np NamespaceNameGetter) string

ExtractNamespace extracts the namespace of ObjectMeta. For cluster scoped objects the Namespace field is empty and this function assumes that the object is returned from kubernetes itself implying that the namespace is empty only and only when the Object is cluster scoped and thus returns empty namespace for such objects.

func ExtractNamespaceOrDefault added in v1.14.0

func ExtractNamespaceOrDefault(np NamespaceNameGetter) string

ExtractNamespaceOrDefault extracts the namespace of ObjectMeta, it returns default namespace if the namespace field in the ObjectMeta is empty.

func GetClusterIPByFamily added in v1.14.0

func GetClusterIPByFamily(ipFamily slim_corev1.IPFamily, service *slim_corev1.Service) string

GetClusterIPByFamily returns a service clusterip by family. From - https://github.com/kubernetes/kubernetes/blob/release-1.20/pkg/proxy/util/utils.go#L386-L411

func GetLatestPodReadiness added in v1.14.0

func GetLatestPodReadiness(podStatus slim_corev1.PodStatus) slim_corev1.ConditionStatus

GetLatestPodReadiness returns the lastest podReady condition on a given pod.

func GetObjNamespaceName

func GetObjNamespaceName(obj NamespaceNameGetter) string

GetObjNamespaceName returns the object's namespace and name. If the object is cluster scoped then the function returns only the object name without any namespace prefix.

func GetServiceListOptionsModifier added in v1.14.0

func GetServiceListOptionsModifier(cfg ServiceConfiguration) (func(options *v1meta.ListOptions), error)

GetServiceListOptionsModifier returns the options modifier for service object list. This methods returns a ListOptions modifier which adds a label selector to only select services that are in context of Cilium. Like kube-proxy Cilium does not select services containing k8s headless service label. We honor service.kubernetes.io/service-proxy-name label in the service object and only handle services that match our service proxy name. If the service proxy name for Cilium is an empty string, we assume that Cilium is the default service handler in which case we select all services that don't have the above mentioned label.

func GetWorkloadMetaFromPod added in v1.14.0

func GetWorkloadMetaFromPod(pod *slim_corev1.Pod) (slim_metav1.ObjectMeta, slim_metav1.TypeMeta, bool)

GetWorkloadMetaFromPod heuristically derives workload metadata from the pod spec.

func IsPodRunning added in v1.14.0

func IsPodRunning(status slim_corev1.PodStatus) bool

IsPodRunning returns true if the pod is considered to be in running state. We consider a Running pod a pod that does not report a Failed nor a Succeeded pod Phase.

func ListerWatcherFromTyped added in v1.14.0

func ListerWatcherFromTyped[T k8sRuntime.Object](lw typedListWatcher[T]) cache.ListerWatcher

ListerWatcherFromTyped adapts a typed k8s client to cache.ListerWatcher so it can be used with an informer. With this construction we can use fake clients for testing, which would not be possible if we used NewListWatchFromClient and RESTClient().

func ListerWatcherWithFields added in v1.14.0

func ListerWatcherWithFields(lw cache.ListerWatcher, fieldSelector fields.Selector) cache.ListerWatcher

func ListerWatcherWithModifier added in v1.14.0

func ListerWatcherWithModifier(lw cache.ListerWatcher, optsModifier func(*metav1.ListOptions)) cache.ListerWatcher

func ValidIPs added in v1.14.0

func ValidIPs(podStatus slim_corev1.PodStatus) []string

ValidIPs return a sorted slice of unique IP addresses retrieved from the given PodStatus. Returns an error when no IPs are found.

Types

type GatewayAPIConfiguration added in v1.14.0

type GatewayAPIConfiguration interface {
	// K8sGatewayAPIEnabled returns true if gateway API is enabled in Cilium
	K8sGatewayAPIEnabled() bool
}

GatewayAPIConfiguration is the required configuration for GetServiceListOptionsModifier

type IngressConfiguration added in v1.14.0

type IngressConfiguration interface {
	// K8sIngressControllerEnabled returns true if ingress controller feature is enabled in Cilium
	K8sIngressControllerEnabled() bool
}

IngressConfiguration is the required configuration for GetServiceListOptionsModifier

type NamespaceNameGetter added in v1.14.0

type NamespaceNameGetter interface {
	GetNamespace() string
	GetName() string
}

type PolicyConfiguration added in v1.14.0

type PolicyConfiguration interface {
	// K8sNetworkPolicyEnabled returns true if cilium agent needs to support K8s NetworkPolicy
	K8sNetworkPolicyEnabled() bool
}

PolicyConfiguration is the required configuration for K8s NetworkPolicy

type ServiceConfiguration added in v1.14.0

type ServiceConfiguration interface {
	// K8sServiceProxyNameValue must return the value of the proxy name
	// annotation. If set, only services with this label will be handled.
	K8sServiceProxyNameValue() string
}

ServiceConfiguration is the required configuration for GetServiceListOptionsModifier

Jump to

Keyboard shortcuts

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