workload

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Overview

Package workload implements the reflection logic for pods.

Index

Constants

View Source
const (
	// PodReflectorName -> The name associated with the Pod reflector.
	PodReflectorName = "Pod"
)

Variables

This section is empty.

Functions

func RemoteShadowNamespacedKeyer added in v0.9.0

func RemoteShadowNamespacedKeyer(namespace, nodename string) func(metadata metav1.Object) []types.NamespacedName

RemoteShadowNamespacedKeyer returns a shadowpod keyer associated with the given namespace, retrieving the object name from its metadata.

Types

type FallbackPodReflector

type FallbackPodReflector struct {
	// contains filtered or unexported fields
}

FallbackPodReflector handles the "orphan" pods outside the managed namespaces.

func (*FallbackPodReflector) Handle

Handle operates as fallback to reconcile pod objects not managed by namespaced handlers.

func (*FallbackPodReflector) Keys

func (fpr *FallbackPodReflector) Keys(local, _ string) []types.NamespacedName

Keys returns a set of keys to be enqueued for fallback processing for the given namespace pair.

func (*FallbackPodReflector) List added in v0.9.0

func (fpr *FallbackPodReflector) List() ([]interface{}, error)

List returns the list of pods managed by the FallbackReflector.

func (*FallbackPodReflector) Ready

func (fpr *FallbackPodReflector) Ready() bool

Ready returns whether the FallbackReflector is completely initialized.

type MetricsFactory

type MetricsFactory func(namespace string) metricsv1beta1.PodMetricsInterface

MetricsFactory represents a function to generate the interface to retrieve the pod metrics for a given namespace.

type NamespacedPodHandler

type NamespacedPodHandler interface {
	// Exec executes a command in a container of a reflected pod.
	Exec(ctx context.Context, pod, container string, cmd []string, attach api.AttachIO) error
	// Attach attaches to a process that is already running inside an existing container of a reflected pod.
	Attach(ctx context.Context, pod, container string, attach api.AttachIO) error
	// PortForward forwards a connection from local to the ports of a reflected pod.
	PortForward(ctx context.Context, name string, port int32, stream io.ReadWriteCloser) error
	// Logs retrieves the logs of a container of a reflected pod.
	Logs(ctx context.Context, pod, container string, opts api.ContainerLogOpts) (io.ReadCloser, error)
	// Stats retrieves the stats of the reflected pods.
	Stats(ctx context.Context) ([]statsv1alpha1.PodStats, error)
}

NamespacedPodHandler exposes an interface to interact with pods offloaded to the remote cluster in a given namespace.

type NamespacedPodReflector

type NamespacedPodReflector struct {
	generic.NamespacedReflector
	// contains filtered or unexported fields
}

NamespacedPodReflector manages the Pod reflection for a given pair of local and remote namespaces.

func (*NamespacedPodReflector) Attach added in v0.7.0

func (npr *NamespacedPodReflector) Attach(ctx context.Context, po, container string, attach api.AttachIO) error

Attach attaches to a process that is already running inside an existing container of a reflected pod.

func (*NamespacedPodReflector) Exec

func (npr *NamespacedPodReflector) Exec(ctx context.Context, po, container string, cmd []string, attach api.AttachIO) error

Exec executes a command in a container of a reflected pod.

func (*NamespacedPodReflector) ForgeShadowPod added in v0.5.0

func (npr *NamespacedPodReflector) ForgeShadowPod(ctx context.Context, local *corev1.Pod,
	shadow *vkv1alpha1.ShadowPod, info *PodInfo, forgingOpts *forge.ForgingOpts) (*vkv1alpha1.ShadowPod, error)

ForgeShadowPod forges the ShadowPod object to be enforced by the reflection process.

func (*NamespacedPodReflector) ForgetPodInfo

func (npr *NamespacedPodReflector) ForgetPodInfo(po string)

ForgetPodInfo forgets about a pod and deletes the cached information.

func (*NamespacedPodReflector) Handle

func (npr *NamespacedPodReflector) Handle(ctx context.Context, name string) error

Handle reconciles pod objects.

func (*NamespacedPodReflector) HandleLabels added in v0.4.0

func (npr *NamespacedPodReflector) HandleLabels(ctx context.Context, local *corev1.Pod) error

HandleLabels mutates the local object labels, to mark the pod as offloaded and allow filtering at the informer level.

func (*NamespacedPodReflector) HandleStatus

func (npr *NamespacedPodReflector) HandleStatus(ctx context.Context, local, remote *corev1.Pod, info *PodInfo) error

HandleStatus reflects the status from the remote Pod to the local one.

func (*NamespacedPodReflector) InferAdditionalRestarts

func (npr *NamespacedPodReflector) InferAdditionalRestarts(local, remote *corev1.PodStatus) int32

InferAdditionalRestarts estimates the number of remote pod restarts comparing the previously configured statues.

func (*NamespacedPodReflector) List added in v0.9.0

func (npr *NamespacedPodReflector) List() ([]interface{}, error)

List retrieves the list of reflected pods.

func (*NamespacedPodReflector) Logs

func (npr *NamespacedPodReflector) Logs(ctx context.Context, po, container string, opts api.ContainerLogOpts) (io.ReadCloser, error)

Logs retrieves the logs of a container of a reflected pod.

func (*NamespacedPodReflector) MapPodIP

func (npr *NamespacedPodReflector) MapPodIP(ctx context.Context, info *PodInfo, original string) (string, error)

MapPodIP maps the remote Pod address to the corresponding local one.

func (*NamespacedPodReflector) PortForward added in v0.7.1

func (npr *NamespacedPodReflector) PortForward(_ context.Context, name string, port int32, stream io.ReadWriteCloser) error

PortForward forwards a connection from local to the ports of a reflected pod.

func (*NamespacedPodReflector) RetrieveLegacyServiceAccountSecretName added in v0.7.0

func (npr *NamespacedPodReflector) RetrieveLegacyServiceAccountSecretName(info *PodInfo, saName string) (string, error)

RetrieveLegacyServiceAccountSecretName retrieves the name of the secret associated with a given service account (using the legacy approach).

func (*NamespacedPodReflector) RetrievePodInfo

func (npr *NamespacedPodReflector) RetrievePodInfo(po string) *PodInfo

RetrievePodInfo retrieves the pod information regarding a given pod.

func (*NamespacedPodReflector) ShouldUpdateShadowPod added in v0.6.0

func (npr *NamespacedPodReflector) ShouldUpdateShadowPod(ctx context.Context, shadow, target *vkv1alpha1.ShadowPod) bool

ShouldUpdateShadowPod checks whether it is necessary to update the remote shadowpod, based on the forged one.

func (*NamespacedPodReflector) Stats

Stats retrieves the stats of the reflected pods.

type PodHandler

type PodHandler interface {
	// List returns the list of reflected pods.
	List(context.Context) ([]*corev1.Pod, error)
	// Exec executes a command in a container of a reflected pod.
	Exec(ctx context.Context, namespace, pod, container string, cmd []string, attach api.AttachIO) error
	// Attach attaches to a process that is already running inside an existing container of a reflected pod.
	Attach(ctx context.Context, namespace, pod, container string, attach api.AttachIO) error
	// PortForward forwards a connection from local to the ports of a reflected pod.
	PortForward(ctx context.Context, namespace, pod string, port int32, stream io.ReadWriteCloser) error
	// Logs retrieves the logs of a container of a reflected pod.
	Logs(ctx context.Context, namespace, pod, container string, opts api.ContainerLogOpts) (io.ReadCloser, error)
	// Stats retrieves the stats of the reflected pods.
	Stats(ctx context.Context) (*statsv1alpha1.Summary, error)
}

PodHandler exposes an interface to interact with pods offloaded to the remote cluster.

type PodInfo

type PodInfo struct {
	PreventCreationUntilSeen bool

	Restarts  int32
	RemoteUID types.UID

	ServiceAccountSecret string
	OriginalIP           string
	TranslatedIP         string
}

PodInfo contains information about known pods.

type PodReflector

type PodReflector struct {
	manager.Reflector
	// contains filtered or unexported fields
}

PodReflector manages the Pod reflection towards a remote cluster.

func NewPodReflector

func NewPodReflector(
	remoteRESTConfig *rest.Config,
	remoteMetricsFactory MetricsFactory,
	ipamclient ipam.IpamClient,
	podReflectorconfig *PodReflectorConfig,
	reflectorConfig *generic.ReflectorConfig) *PodReflector

NewPodReflector returns a new PodReflector instance.

func (*PodReflector) Attach added in v0.7.0

func (pr *PodReflector) Attach(ctx context.Context, namespace, pod, container string, attach api.AttachIO) error

Attach attaches to a process that is already running inside an existing container of a reflected pod.

func (*PodReflector) Exec

func (pr *PodReflector) Exec(ctx context.Context, namespace, pod, container string, cmd []string, attach api.AttachIO) error

Exec executes a command in a container of a reflected pod.

func (*PodReflector) KubernetesServiceIPGetter added in v0.5.0

func (pr *PodReflector) KubernetesServiceIPGetter() func(ctx context.Context) (string, error)

KubernetesServiceIPGetter returns a function to retrieve the IP associated with the kubernetes.default service.

func (*PodReflector) List

func (pr *PodReflector) List(_ context.Context) ([]*corev1.Pod, error)

List returns the list of reflected pods.

func (*PodReflector) Logs

func (pr *PodReflector) Logs(ctx context.Context, namespace, pod, container string, opts api.ContainerLogOpts) (io.ReadCloser, error)

Logs retrieves the logs of a container of a reflected pod.

func (*PodReflector) NewFallback

NewFallback returns a new FallbackReflector instance.

func (*PodReflector) NewNamespaced

NewNamespaced returns a new NamespacedPodReflector instance.

func (*PodReflector) PortForward added in v0.7.1

func (pr *PodReflector) PortForward(ctx context.Context, namespace, pod string, port int32, stream io.ReadWriteCloser) error

PortForward forwards a connection from local to the ports of a reflected pod.

func (*PodReflector) Start

func (pr *PodReflector) Start(ctx context.Context, opts *options.ReflectorOpts)

Start starts the reflector.

func (*PodReflector) Stats

Stats retrieves the stats of the reflected pods.

func (*PodReflector) StopNamespace

func (pr *PodReflector) StopNamespace(local, remote string)

StopNamespace stops the reflection for a given namespace.

func (*PodReflector) String added in v0.9.0

func (pr *PodReflector) String() string

String returns the name of the PodReflector.

type PodReflectorConfig added in v0.8.0

type PodReflectorConfig struct {
	APIServerSupport    forge.APIServerSupportType
	DisableIPReflection bool
	HomeAPIServerHost   string
	HomeAPIServerPort   string
}

PodReflectorConfig represents the configuration of a PodReflector.

Jump to

Keyboard shortcuts

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