util

package
v0.0.0-...-b8ed03b Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnnotateEnrolledPod

func AnnotateEnrolledPod(client kubernetes.Interface, pod *metav1.ObjectMeta) error

func AnnotatePartiallyEnrolledPod

func AnnotatePartiallyEnrolledPod(client kubernetes.Interface, pod *metav1.ObjectMeta) error

func AnnotateUnenrollPod

func AnnotateUnenrollPod(client kubernetes.Interface, pod *metav1.ObjectMeta) error

func CheckBooleanAnnotation

func CheckBooleanAnnotation(pod *corev1.Pod, annotationName string) (bool, bool)

CheckBooleanAnnotation checks for the named boolean-style (as per strcov.ParseBool) annotation on the pod. Returns the bool value, and a bool indicating annotation presence on the pod.

If the bool value is false, not present, or unparsable, returns a false value. If the annotation is not present or unparsable, returns false for presence.

func GetPlugin

func GetPlugin(rawPlugin any) (plugin map[string]any, err error)

Given the raw plugin interface, return the plugin asserted as a map[string]interface{}

func GetPlugins

func GetPlugins(cniConfigMap map[string]any) (plugins []any, err error)

Given an unmarshalled CNI config JSON map, return the plugin list asserted as a []interface{}

func GetPodIPsIfPresent

func GetPodIPsIfPresent(pod *corev1.Pod) []netip.Addr

Get any IPs currently assigned to the Pod.

If 'PodIPs' exists, it is preferred (and should be guaranteed to contain the address in 'PodIP'), otherwise fallback to 'PodIP'.

Note that very early in the pod's lifecycle (before all the node CNI plugin invocations finish) K8S may not have received the pod IPs yet, and may not report the pod as having any.

func IsZtunnelPod

func IsZtunnelPod(systemNs string, pod *corev1.Pod) bool

func MarshalCNIConfig

func MarshalCNIConfig(cniConfigMap map[string]any) ([]byte, error)

Marshal the CNI config map and append a new line

func PodFullyEnrolled

func PodFullyEnrolled(pod *corev1.Pod) bool

PodFullyEnrolled reports on whether the pod _has_ actually been fully configured for traffic redirection.

That is, have we annotated it after successfully setting up iptables rules AND sending it to a node proxy instance.

If you just want to know if the pod _should be_ configured for traffic redirection, see PodRedirectionEnabled

func PodPartiallyEnrolled

func PodPartiallyEnrolled(pod *corev1.Pod) bool

PodPartiallyEnrolled reports on whether the pod _has_ already been partially configured (e.g. for traffic redirection) but not fully configured.

That is, have we annotated it after setting iptables rules, but have not yet been able to send it to a node proxy instance.

Pods like this still need to undergo the removal process (to potentially undo the redirection).

If you just want to know if the pod _should be_ configured for traffic redirection, see PodRedirectionEnabled

func PodRedirectionEnabled

func PodRedirectionEnabled(namespace *corev1.Namespace, pod *corev1.Pod) bool

PodRedirectionEnabled determines if a pod should or should not be configured to have traffic redirected thru the node proxy.

func ReadCNIConfigMap

func ReadCNIConfigMap(path string) (map[string]any, error)

Read CNI config from file and return the unmarshalled JSON as a map

Types

type Watcher

type Watcher struct {
	Events chan struct{}
	Errors chan error
	// contains filtered or unexported fields
}

func CreateFileWatcher

func CreateFileWatcher(paths ...string) (*Watcher, error)

Creates a file watcher that watches for any changes to the directory

func (*Watcher) Close

func (w *Watcher) Close()

func (*Watcher) Wait

func (w *Watcher) Wait(ctx context.Context) error

Waits until a file is modified (returns nil), the context is cancelled (returns context error), or returns error

Jump to

Keyboard shortcuts

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