agent

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent provides access to configuration stored as custom resources.

Configuration custom resources can be defined per node, per group or as a default resource. These are named 'node.$NODE_NAME', 'group.$GROUP_NAME', and 'default' respectively. If a node-specific configuration exists, it is always used for the node. Otherwise either a group-specific or the default configuration is used depending on whether the node belongs to a group. A node can be assigned to a group by setting the group label on the node. By default this group label is 'config.nri/group'.

func New

func New(cfgIf ConfigInterface, options ...Option) (*Agent, error)

New creates an agent with the given options.

func (*Agent) GetPodResources added in v0.8.0

func (a *Agent) GetPodResources(ns, pod string, timeout time.Duration) (*podresapi.PodResources, error)

GetPodResources queries the given pod's resources.

func (*Agent) GoGetPodResources added in v0.8.0

func (a *Agent) GoGetPodResources(ns, pod string, timeout time.Duration) <-chan *podresapi.PodResources

GoGetPodResources queries the given pod's resources asynchronously.

func (*Agent) GoListPodResources added in v0.8.0

func (a *Agent) GoListPodResources(timeout time.Duration) <-chan *podresapi.PodResourcesList

GoListPodResources lists all pods' resources asynchronously.

func (*Agent) KubeClient added in v0.15.0

func (a *Agent) KubeClient() *client.Client

KubeClient returns the shared kubernetes client wrapper. Returns nil before setupClients has run successfully.

func (*Agent) KubeConfig added in v0.15.0

func (a *Agent) KubeConfig() string

KubeConfig returns the kubeconfig file path this agent was configured with. Returns the empty string when running with in-cluster credentials.

func (*Agent) ListPodResources added in v0.8.0

func (a *Agent) ListPodResources(timeout time.Duration) (*podresapi.PodResourcesList, error)

ListPodResources lists all pods' resources.

func (*Agent) NodeName added in v0.15.0

func (a *Agent) NodeName() string

NodeName returns the kubernetes node name this agent is running on.

func (*Agent) PurgePodResources added in v0.9.4

func (a *Agent) PurgePodResources(ns, pod string)

PurgePodResources removes any cached resources for the given pod.

func (*Agent) RestConfig added in v0.15.0

func (a *Agent) RestConfig() *rest.Config

RestConfig returns a copy of the REST config used by the shared kubernetes client, or nil before setupClients has run successfully.

func (*Agent) Start

func (a *Agent) Start(notifyFn NotifyFn) error

func (*Agent) Stop

func (a *Agent) Stop()

Stop asks the agent to stop. It does not wait for the event loop to finish; Start() returns once that has happened.

func (*Agent) UpdateNodeExtendedResources added in v0.13.0

func (a *Agent) UpdateNodeExtendedResources(resources map[string]*resource.Quantity) error

UpdateNodeExtendedResources records 'resources' as the desired state of the local Node's status.capacity and wakes the reconciler to take care of status change.

'resources' must describe the *complete* desired state:

  • A non-nil value publishes (adds/replaces) the named resource with the given capacity.
  • A nil value whose key contains no '*' removes that exact resource if it is currently present on the Node.
  • A nil value whose key contains '*' is an ownership pattern: every resource currently on the Node that matches the pattern but is not being published is removed.

If the resources map is empty or nil, nothing is to be published or removed, and therefore querying and modifying Node status/capacity is omitted.

Because every request carries the full desired state, a newer request fully supersedes older ones; the reconciler therefore coalesces bursts and only ever drives the Node towards the most recent request.

func (*Agent) UpdateNrtCR

func (a *Agent) UpdateNrtCR(policy string, zones []*policyapi.TopologyZone) error

UpdateNrtCR records the given data as the desired state of the node's node resource topology CR and wakes the reconciler to write it.

A newer request replaces older ones. The reconciler writes the latest snapshot only, so bursts coalesce and an old snapshot never overwrites a new one.

type ConfigInterface

type ConfigInterface interface {
	// Set the preferred client and configuration for cluster/apiserver access.
	SetKubeClient(cli *http.Client, cfg *rest.Config) error
	// Create a watch for monitoring the named custom resource.
	CreateWatch(ctx context.Context, namespace, name string) (watch.Interface, error)
	// Patch the status subresource of the named custom resource.
	PatchStatus(ctx context.Context, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) error
	// Unmarshal custom resource which was read from the given file.
	Unmarshal(data []byte, file string) (runtime.Object, error)
}

ConfigInterface is used by the agent to access config custom resources.

func BalloonsConfigInterface

func BalloonsConfigInterface() ConfigInterface

BalloonsConfigInterface returns a ConfigInterface for the balloons policy.

func TemplateConfigInterface

func TemplateConfigInterface() ConfigInterface

TemplateConfigInterface returns a ConfigInterface for the template policy.

func TopologyAwareConfigInterface

func TopologyAwareConfigInterface() ConfigInterface

TopologyAwareConfigInterface returns a ConfigInterface for the topology-aware policy.

type NotifyFn

type NotifyFn func(cfg any) (bool, error)

NotifyFn is a function to call when the effective configuration changes.

type Option

type Option func(*Agent) error

Option is an option for the agent.

func WithConfigFile

func WithConfigFile(file string) Option

WithConfigFile sets up the agent to monitor a configuration file instead of custom resources.

func WithConfigGroupLabel

func WithConfigGroupLabel(label string) Option

WithConfigGroupLabel sets the key used to label nodes into config groups.

func WithConfigNamespace

func WithConfigNamespace(ns string) Option

WithConfigNamespace sets the namespace used for config custom resources.

func WithKubeConfig

func WithKubeConfig(kc string) Option

WithKubeConfig sets the location of the config file to use for K8s cluster access. An unset config file implies in-cluster configuration or lack of need for cluster access.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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