k8s

package
v1.18.0-pre.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: Apache-2.0 Imports: 29 Imported by: 2

Documentation

Overview

Package k8s abstracts all Kubernetes specific behaviour

Index

Constants

View Source
const (
	PodTableName = "k8s-pods"
)

Variables

View Source
var (
	PodNameIndex = newNameIndex[LocalPod]()
	PodTableCell = cell.Provide(NewPodTableAndReflector)
)
View Source
var (
	// ResourcesCell provides a set of handles to Kubernetes resources used throughout the
	// agent. Each of the resources share a client-go informer and backing store so we only
	// have one watch API call for each resource kind and that we maintain only one copy of each object.
	//
	// See pkg/k8s/resource/resource.go for documentation on the Resource[T] type.
	ResourcesCell = cell.Module(
		"k8s-resources",
		"Agent Kubernetes resources",

		cell.Config(k8s.DefaultConfig),
		LocalNodeCell,
		cell.Provide(
			k8s.ServiceResource,
			k8s.EndpointsResource,
			k8s.NamespaceResource,
			k8s.NetworkPolicyResource,
			k8s.CiliumNetworkPolicyResource,
			k8s.CiliumClusterwideNetworkPolicyResource,
			k8s.CiliumCIDRGroupResource,
			k8s.CiliumNodeResource,
			k8s.CiliumSlimEndpointResource,
			k8s.CiliumEndpointSliceResource,
			k8s.CiliumEnvoyConfigResource,
			k8s.CiliumClusterwideEnvoyConfigResource,
		),
	)

	LocalNodeCell = cell.Module(
		"k8s-local-node-resources",
		"Agent Kubernetes local node resources",

		cell.Provide(
			func(lc cell.Lifecycle, cs client.Clientset) (LocalNodeResource, error) {
				return k8s.NodeResource(
					lc, cs,
					func(opts *metav1.ListOptions) {
						opts.FieldSelector = fields.ParseSelectorOrDie("metadata.name=" + nodeTypes.GetName()).String()
					},
				)
			},
			func(params k8s.CiliumResourceParams) (LocalCiliumNodeResource, error) {
				return k8s.CiliumNodeResource(
					params,
					func(opts *metav1.ListOptions) {
						opts.FieldSelector = fields.ParseSelectorOrDie("metadata.name=" + nodeTypes.GetName()).String()
					},
				)
			},
		),
	)
)
View Source
var TablesCell = cell.Module(
	"k8s-tables",
	"StateDB tables of Kubernetes objects",

	PodTableCell,
)

TablesCell provides a set of StateDB tables for common Kubernetes objects. The tables are populated with the StateDB k8s reflector (pkg/k8s/statedb.go).

NOTE: When adding new k8s tables make sure to provide and register from a single provider to ensure reflector starts before anyone depending on the table. See NewPodTableAndReflector for example.

Functions

func NewPodTable

func NewPodTable(db *statedb.DB) (statedb.RWTable[LocalPod], error)

func NewPodTableAndReflector

func NewPodTableAndReflector(jg job.Group, db *statedb.DB, cs client.Clientset) (statedb.Table[LocalPod], error)

NewPodTableAndReflector returns the read-only Table[LocalPod] and registers the k8s reflector. These are combined to ensure any dependency on Table[LocalPod] will start after the reflector, ensuring that Start hooks can wait for the table to initialize.

func PodByName

func PodByName(namespace, name string) statedb.Query[LocalPod]

func WaitForNodeInformation added in v1.15.0

func WaitForNodeInformation(ctx context.Context, log logrus.FieldLogger, localNode LocalNodeResource, localCiliumNode LocalCiliumNodeResource) error

WaitForNodeInformation retrieves the node information via the CiliumNode or Kubernetes Node resource. This function will block until the information is received.

Types

type LocalCiliumNodeResource

type LocalCiliumNodeResource resource.Resource[*cilium_api_v2.CiliumNode]

LocalCiliumNodeResource is a resource.Resource[*cilium_api_v2.CiliumNode] but one which will only stream updates for the CiliumNode object associated with the node we are currently running on.

type LocalNodeResource

type LocalNodeResource resource.Resource[*slim_corev1.Node]

LocalNodeResource is a resource.Resource[*slim_corev1.Node] but one which will only stream updates for the node object associated with the node we are currently running on.

type LocalNodeResources added in v1.15.0

type LocalNodeResources struct {
	cell.In

	LocalNode       LocalNodeResource
	LocalCiliumNode LocalCiliumNodeResource
}

LocalNodeResources is a convenience struct to group CiliumNode and Node resources as cell constructor parameters.

type LocalPod

type LocalPod struct {
	*slim_corev1.Pod

	// UpdatedAt is the time when [LocalPod] was last updated, e.g. it
	// shows when the pod change was received from the api-server.
	UpdatedAt time.Time `json:"updatedAt" yaml:"updatedAt"`
}

LocalPod is Cilium's internal model of the pods running on this node.

func (LocalPod) TableHeader

func (p LocalPod) TableHeader() []string

func (LocalPod) TableRow

func (p LocalPod) TableRow() []string

type Resources

Resources is a convenience struct to group all the agent k8s resources as cell constructor parameters.

Jump to

Keyboard shortcuts

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