utils

package
v1.16.0-pre.3 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 19 Imported by: 22

Documentation

Index

Constants

View Source
const (

	// EndpointSliceMeshControllerName is a unique value used with LabelManagedBy to indicate
	// the component managing an EndpointSlice.
	EndpointSliceMeshControllerName = "endpointslice-mesh-controller.cilium.io"
)

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

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

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 GetEndpointSliceListOptionsModifier

func GetEndpointSliceListOptionsModifier() (func(options *v1meta.ListOptions), error)

GetEndpointSliceListOptionsModifier returns the options modifier for endpointSlice object list. This methods returns a ListOptions modifier which adds a label selector to select all endpointSlice objects they are not from remote clusters in Cilium cluster mesh. This is mostly the same behavior as kube-proxy except the cluster mesh behavior which is tied to how Cilium internally works with clustermesh endpoints and that this function also doesn't ignore headless Services. Given label mirroring from the service objects to endpoint slice objects were introduced in Kubernetes PR 94443, and released as part of Kubernetes v1.20; we can start using GetServiceAndEndpointListOptionsModifier for endpoint slices when dropping support for Kubernetes v1.19 and older. We can do that since the serviceProxyNameLabel label will then be mirrored to endpoint slices for services with that label. We also ignore Kubernetes endpoints coming from other clusters in the Cilium clustermesh here as Cilium does not rely on mirrored Kubernetes EndpointSlice for any of its functionalities.

func GetLatestPodReadiness

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 GetServiceAndEndpointListOptionsModifier

func GetServiceAndEndpointListOptionsModifier(k8sServiceProxy string) (func(options *v1meta.ListOptions), error)

GetServiceAndEndpointListOptionsModifier returns the options modifier for service and endpoint object lists. This methods returns a ListOptions modifier which adds a label selector to only select services that are in context of Cilium. Unlike kube-proxy Cilium does not select services/endpoints 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

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

GetWorkloadMetaFromPod heuristically derives workload metadata from the pod spec.

func IsPodRunning

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

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

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

func ListerWatcherWithModifier

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

func ListerWatcherWithModifiers

func ListerWatcherWithModifiers(lw cache.ListerWatcher, opts ...func(*metav1.ListOptions)) cache.ListerWatcher

func SanitizePodLabels added in v1.12.14

func SanitizePodLabels(podLabels map[string]string, namespace nameLabelsGetter, serviceAccount, clusterName string) map[string]string

SanitizePodLabels makes sure that no important pod labels were overridden manually on k8s pod object creation.

func StripPodSpecialLabels added in v1.12.14

func StripPodSpecialLabels(labels map[string]string) map[string]string

StripPodSpecialLabels strips labels that are not supposed to be coming from a k8s pod object update.

func ValidIPs

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 NamespaceNameGetter

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

Jump to

Keyboard shortcuts

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