Documentation
¶
Overview ¶
Package k8s contains all k8s related logic. +groupName=pkg
Index ¶
- Constants
- Variables
- func AnnotateNode(logger *slog.Logger, cs kubernetes.Interface, nodeName string, ...) (nodeAnnotation, error)
- func AnnotationsEqual(relevantAnnotations []string, anno1, anno2 map[string]string) bool
- func CiliumBGPAdvertisementResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumBGPAdvertisement], error)
- func CiliumBGPNodeConfigResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumBGPNodeConfig], error)
- func CiliumBGPPeerConfigResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumBGPPeerConfig], error)
- func CiliumBGPPeeringPolicyResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2alpha1.CiliumBGPPeeringPolicy], error)
- func CiliumCIDRGroupResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumCIDRGroup], error)
- func CiliumClusterwideNetworkPolicyResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumClusterwideNetworkPolicy], error)
- func CiliumEndpointSliceResource(params CiliumResourceParams, _ *node.LocalNodeStore, ...) (resource.Resource[*cilium_api_v2alpha1.CiliumEndpointSlice], error)
- func CiliumIdentityResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumIdentity], error)
- func CiliumNetworkPolicyResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumNetworkPolicy], error)
- func CiliumNodeResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumNode], error)
- func CiliumPodIPPoolResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2alpha1.CiliumPodIPPool], error)
- func CiliumSlimEndpointResource(params CiliumResourceParams, _ *node.LocalNodeStore, ...) (resource.Resource[*types.CiliumEndpoint], error)
- func ConvertCEPToCoreCEP(cep *cilium_v2.CiliumEndpoint) *cilium_v2alpha1.CoreCiliumEndpoint
- func ConvertCoreCiliumEndpointToTypesCiliumEndpoint(ccep *cilium_v2alpha1.CoreCiliumEndpoint, ns string) *types.CiliumEndpoint
- func ConvertToK8sV1LoadBalancerIngress(slimLBIngs []slim_corev1.LoadBalancerIngress) []v1.LoadBalancerIngress
- func ConvertToK8sV1ServiceAffinityConfig(saCfg *slim_corev1.SessionAffinityConfig) *v1.SessionAffinityConfig
- func ConvertToK8sV1ServicePorts(slimPorts []slim_corev1.ServicePort) []v1.ServicePort
- func ConvertToNetworkV1IngressLoadBalancerIngress(slimLBIngs []slim_corev1.LoadBalancerIngress) []networkingv1.IngressLoadBalancerIngress
- func EndpointsResource(logger *slog.Logger, lc cell.Lifecycle, cfg ConfigParams, cs client.Clientset, ...) (resource.Resource[*Endpoints], error)
- func EndpointsResourceWithIndexers(logger *slog.Logger, lc cell.Lifecycle, cfg ConfigParams, cs client.Clientset, ...) (resource.Resource[*Endpoints], error)
- func GetIdentitiesByKeyFunc(keyFunc func(map[string]string) allocator.AllocatorKey) func(obj any) ([]string, error)
- func GetPodMetadata(logger *slog.Logger, k8sNs nameLabelsGetter, pod *slim_corev1.Pod) (containerPorts []slim_corev1.ContainerPort, lbls map[string]string)
- func GetPolicyLabelsv1(logger *slog.Logger, np *slim_networkingv1.NetworkPolicy) labels.LabelArray
- func IsLocalCiliumNode(n *ciliumv2.CiliumNode) bool
- func K8sErrorHandler(_ context.Context, e error, _ string, _ ...any)
- func LBIPPoolsResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumLoadBalancerIPPool], error)
- func ListerWatcherToObservable(lw cache.ListerWatcher) stream.Observable[CacheStoreEvent]
- func NamespaceResource(lc cell.Lifecycle, cs client.Clientset, opts ...func(*metav1.ListOptions)) (resource.Resource[*slim_corev1.Namespace], error)
- func NetworkPolicyResource(lc cell.Lifecycle, cs client.Clientset, opts ...func(*metav1.ListOptions)) (resource.Resource[*slim_networkingv1.NetworkPolicy], error)
- func NodeResource(lc cell.Lifecycle, cs client.Clientset, opts ...func(*metav1.ListOptions)) (resource.Resource[*slim_corev1.Node], error)
- func OnDemandTable[Obj any](jobs job.Registry, health cell.Health, log *slog.Logger, db *statedb.DB, ...) (hive.OnDemand[statedb.Table[Obj]], error)
- func ParseNetworkPolicy(logger *slog.Logger, clusterName string, np *slim_networkingv1.NetworkPolicy) (api.Rules, error)
- func ParseNode(logger *slog.Logger, k8sNode *slim_corev1.Node, source source.Source) *nodeTypes.Node
- func ParseNodeAddressType(k8sAddress slim_corev1.NodeAddressType) (addressing.AddressType, error)
- func PodResource(lc cell.Lifecycle, cs client.Clientset, opts ...func(*metav1.ListOptions)) (resource.Resource[*slim_corev1.Pod], error)
- func RegisterReflector[Obj any](jobGroup job.Group, db *statedb.DB, cfg ReflectorConfig[Obj]) error
- func RemoveNodeAnnotations(c kubernetes.Interface, nodeName string, annotation nodeAnnotation) error
- func ServiceResource(lc cell.Lifecycle, cfg ConfigParams, cs client.Clientset, ...) (resource.Resource[*slim_corev1.Service], error)
- func TransformToCCNP(obj any) (any, error)
- func TransformToCNP(obj any) (any, error)
- func TransformToCiliumEndpoint(obj any) (any, error)
- type Backend
- type CacheStoreEvent
- type CacheStoreEventKind
- type CiliumResourceParams
- type Config
- type ConfigParams
- type EndpointSliceID
- type EndpointSlices
- type Endpoints
- type JSONPatch
- type MergeFunc
- type QueryAllFunc
- type ReflectorConfig
- type ServiceWatchConfig
- type TransformFunc
- type TransformManyFunc
Examples ¶
Constants ¶
const ( NamespaceIndex = "namespace" ByKeyIndex = "by-key-index" )
const ( // DefaultBufferSize is the maximum number of objects to commit to the table in one write transaction. // This limit does not apply to the initial listing (Replace()) which commits all listed objects in one // transaction. DefaultBufferSize = 10000 // DefaultBufferWaitTime is the amount of time to wait to fill the buffer before committing objects. // 10000 * 50ms => 200k objects per second throughput limit. DefaultBufferWaitTime = 50 * time.Millisecond )
const ( CacheStoreEventAdd = CacheStoreEventKind(iota) CacheStoreEventUpdate CacheStoreEventDelete CacheStoreEventReplace )
const ( // maximum number of operations a single json patch may contain. // See https://github.com/kubernetes/kubernetes/pull/74000 MaxJSONPatchOperations = 10000 )
const UseOriginalSourceAddressLabel = "cilium.io/use-original-source-address"
UseOriginalSourceAddressLabel is the k8s label that can be added to a `CiliumEnvoyConfig`. This way the Cilium BPF Metadata listener filter is configured to use the original source address when extracting the metadata for a request.
Variables ¶
var DefaultConfig = Config{ EnableK8sEndpointSlice: true, K8sServiceProxyName: "", }
DefaultConfig represents the default k8s resources config values.
Functions ¶
func AnnotateNode ¶ added in v0.15.7
func AnnotateNode(logger *slog.Logger, cs kubernetes.Interface, nodeName string, nd nodeTypes.Node, encryptKey uint8) (nodeAnnotation, error)
AnnotateNode writes v4 and v6 CIDRs and health IPs in the given k8s node name. In case of failure while updating the node, this function while spawn a go routine to retry the node update indefinitely.
func AnnotationsEqual ¶ added in v0.15.7
AnnotationsEqual returns whether the annotation with any key in relevantAnnotations is equal in anno1 and anno2.
func CiliumBGPAdvertisementResource ¶ added in v1.16.0
func CiliumBGPAdvertisementResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumBGPAdvertisement], error)
func CiliumBGPNodeConfigResource ¶ added in v1.16.0
func CiliumBGPNodeConfigResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumBGPNodeConfig], error)
func CiliumBGPPeerConfigResource ¶ added in v1.16.0
func CiliumBGPPeerConfigResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumBGPPeerConfig], error)
func CiliumBGPPeeringPolicyResource ¶ added in v1.16.0
func CiliumBGPPeeringPolicyResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2alpha1.CiliumBGPPeeringPolicy], error)
func CiliumCIDRGroupResource ¶ added in v0.15.7
func CiliumCIDRGroupResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumCIDRGroup], error)
func CiliumClusterwideNetworkPolicyResource ¶ added in v0.15.7
func CiliumClusterwideNetworkPolicyResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumClusterwideNetworkPolicy], error)
func CiliumEndpointSliceResource ¶ added in v1.15.0
func CiliumEndpointSliceResource(params CiliumResourceParams, _ *node.LocalNodeStore, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2alpha1.CiliumEndpointSlice], error)
CiliumEndpointSliceResource uses the "localNode" IndexFunc to build the resource indexer. The IndexFunc accesses the local node info to get its IP, so it depends on the local node store to initialize it before the first access. To reflect this, the node.LocalNodeStore dependency is explicitly requested in the function signature.
func CiliumIdentityResource ¶ added in v0.15.7
func CiliumIdentityResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumIdentity], error)
func CiliumNetworkPolicyResource ¶ added in v0.15.7
func CiliumNetworkPolicyResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumNetworkPolicy], error)
func CiliumNodeResource ¶ added in v0.15.7
func CiliumNodeResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumNode], error)
func CiliumPodIPPoolResource ¶ added in v0.15.7
func CiliumPodIPPoolResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2alpha1.CiliumPodIPPool], error)
func CiliumSlimEndpointResource ¶ added in v0.15.7
func CiliumSlimEndpointResource(params CiliumResourceParams, _ *node.LocalNodeStore, opts ...func(*metav1.ListOptions)) (resource.Resource[*types.CiliumEndpoint], error)
CiliumSlimEndpointResource uses the "localNode" IndexFunc to build the resource indexer. The IndexFunc accesses the local node info to get its IP, so it depends on the local node store to initialize it before the first access. To reflect this, the node.LocalNodeStore dependency is explicitly requested in the function signature.
func ConvertCEPToCoreCEP ¶ added in v0.15.7
func ConvertCEPToCoreCEP(cep *cilium_v2.CiliumEndpoint) *cilium_v2alpha1.CoreCiliumEndpoint
ConvertCEPToCoreCEP converts a CiliumEndpoint to a CoreCiliumEndpoint containing only a minimal set of entities used to
func ConvertCoreCiliumEndpointToTypesCiliumEndpoint ¶ added in v0.15.7
func ConvertCoreCiliumEndpointToTypesCiliumEndpoint(ccep *cilium_v2alpha1.CoreCiliumEndpoint, ns string) *types.CiliumEndpoint
ConvertCoreCiliumEndpointToTypesCiliumEndpoint converts CoreCiliumEndpoint object to types.CiliumEndpoint.
func ConvertToK8sV1LoadBalancerIngress ¶ added in v0.15.7
func ConvertToK8sV1LoadBalancerIngress(slimLBIngs []slim_corev1.LoadBalancerIngress) []v1.LoadBalancerIngress
func ConvertToK8sV1ServiceAffinityConfig ¶ added in v0.15.7
func ConvertToK8sV1ServiceAffinityConfig(saCfg *slim_corev1.SessionAffinityConfig) *v1.SessionAffinityConfig
func ConvertToK8sV1ServicePorts ¶ added in v0.15.7
func ConvertToK8sV1ServicePorts(slimPorts []slim_corev1.ServicePort) []v1.ServicePort
func ConvertToNetworkV1IngressLoadBalancerIngress ¶ added in v0.15.7
func ConvertToNetworkV1IngressLoadBalancerIngress(slimLBIngs []slim_corev1.LoadBalancerIngress) []networkingv1.IngressLoadBalancerIngress
func EndpointsResource ¶ added in v0.15.7
func EndpointsResourceWithIndexers ¶ added in v1.18.0
func GetIdentitiesByKeyFunc ¶ added in v1.16.0
func GetPodMetadata ¶ added in v0.15.7
func GetPodMetadata(logger *slog.Logger, k8sNs nameLabelsGetter, pod *slim_corev1.Pod) (containerPorts []slim_corev1.ContainerPort, lbls map[string]string)
GetPodMetadata returns the labels and annotations of the pod with the given namespace / name.
func GetPolicyLabelsv1 ¶ added in v0.15.7
func GetPolicyLabelsv1(logger *slog.Logger, np *slim_networkingv1.NetworkPolicy) labels.LabelArray
GetPolicyLabelsv1 extracts the name of np. It uses the name from the Cilium annotation if present. If the policy's annotations do not contain the Cilium annotation, the policy's name field is used instead.
func IsLocalCiliumNode ¶ added in v0.15.7
func IsLocalCiliumNode(n *ciliumv2.CiliumNode) bool
IsLocalCiliumNode returns true if the given CiliumNode object refers to the CiliumNode object representing the local node.
func K8sErrorHandler ¶ added in v0.15.7
K8sErrorHandler handles the error messages in a non verbose way by omitting repeated instances of the same error message for a timeout defined with k8sErrLogTimeout.
func LBIPPoolsResource ¶ added in v0.15.7
func LBIPPoolsResource(params CiliumResourceParams, opts ...func(*metav1.ListOptions)) (resource.Resource[*cilium_api_v2.CiliumLoadBalancerIPPool], error)
func ListerWatcherToObservable ¶ added in v1.17.0
func ListerWatcherToObservable(lw cache.ListerWatcher) stream.Observable[CacheStoreEvent]
ListerWatcherToObservable turns a ListerWatcher into an observable using the client-go's Reflector.
func NamespaceResource ¶ added in v0.15.7
func NetworkPolicyResource ¶ added in v0.15.7
func NetworkPolicyResource(lc cell.Lifecycle, cs client.Clientset, opts ...func(*metav1.ListOptions)) (resource.Resource[*slim_networkingv1.NetworkPolicy], error)
func NodeResource ¶ added in v0.15.7
func OnDemandTable ¶ added in v1.17.0
func OnDemandTable[Obj any](jobs job.Registry, health cell.Health, log *slog.Logger, db *statedb.DB, cfg ReflectorConfig[Obj]) (hive.OnDemand[statedb.Table[Obj]], error)
OnDemandTable provides an "on-demand" table of Kubernetes-derived objects. The table is not populated until it is first acquired. If the table should be cleared (to avoid holding onto the objects) when last reference is released, set [ReflectorConfig.ClearTableOnStop].
Intended to be used with cell.Provide. See [ExampleOnDemand] for example usage.
func ParseNetworkPolicy ¶ added in v0.10.0
func ParseNetworkPolicy(logger *slog.Logger, clusterName string, np *slim_networkingv1.NetworkPolicy) (api.Rules, error)
ParseNetworkPolicy parses a k8s NetworkPolicy. Returns a list of Cilium policy rules that can be added, along with an error if there was an error sanitizing the rules.
func ParseNode ¶ added in v0.10.0
func ParseNode(logger *slog.Logger, k8sNode *slim_corev1.Node, source source.Source) *nodeTypes.Node
ParseNode parses a kubernetes node to a cilium node
func ParseNodeAddressType ¶ added in v0.15.7
func ParseNodeAddressType(k8sAddress slim_corev1.NodeAddressType) (addressing.AddressType, error)
ParseNodeAddressType converts a Kubernetes NodeAddressType to a Cilium NodeAddressType. If the Kubernetes NodeAddressType does not have a corresponding Cilium AddressType, returns an error.
func PodResource ¶ added in v0.15.7
func RegisterReflector ¶ added in v1.17.0
RegisterReflector registers a Kubernetes to StateDB table reflector.
Intended to be used with cell.Invoke and the module's job group. See [ExampleRegisterReflector] for example usage.
Example ¶
package main
import (
"github.com/cilium/hive/cell"
"github.com/cilium/statedb"
"github.com/cilium/statedb/index"
corev1 "k8s.io/api/core/v1"
"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/k8s"
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
"github.com/cilium/cilium/pkg/k8s/utils"
)
var nodeNameIndex = statedb.Index[*corev1.Node, string]{
Name: "name",
FromObject: func(obj *corev1.Node) index.KeySet {
return index.NewKeySet(index.String(obj.Name))
},
FromKey: index.String,
Unique: true,
}
func newNodeTable(db *statedb.DB) (statedb.RWTable[*corev1.Node], error) {
tbl, err := statedb.NewTable(
"nodes",
nodeNameIndex,
)
if err != nil {
return nil, err
}
return tbl, db.RegisterTable(tbl)
}
func main() {
module := cell.Module(
"example-reflector",
"Reflector example",
cell.ProvidePrivate(
// Construct the table we're reflecting to.
newNodeTable,
// ReflectorConfig defines the ListerWatcher to use the fetch the objects
// and how to write them to the table.
func(client k8sClient.Clientset, tbl statedb.RWTable[*corev1.Node]) k8s.ReflectorConfig[*corev1.Node] {
return k8s.ReflectorConfig[*corev1.Node]{
Name: "nodes",
Table: tbl,
ListerWatcher: utils.ListerWatcherFromTyped(client.CoreV1().Nodes()),
}
},
),
// Provide Table[*Node] for read-access to all modules in the application.
cell.Provide(statedb.RWTable[*corev1.Node].ToTable),
// Register the reflector to this module's job group.
cell.Invoke(k8s.RegisterReflector[*corev1.Node]),
)
hive.New(module)
}
func RemoveNodeAnnotations ¶ added in v0.15.7
func RemoveNodeAnnotations(c kubernetes.Interface, nodeName string, annotation nodeAnnotation) error
func ServiceResource ¶ added in v0.15.7
func ServiceResource(lc cell.Lifecycle, cfg ConfigParams, cs client.Clientset, opts ...func(*metav1.ListOptions)) (resource.Resource[*slim_corev1.Service], error)
ServiceResource builds the Resource[Service] object.
func TransformToCCNP ¶ added in v0.15.7
TransformToCCNP transforms a *cilium_v2.CiliumClusterwideNetworkPolicy into a *types.SlimCNP without the Status field of the given CNP, or a cache.DeletedFinalStateUnknown into a cache.DeletedFinalStateUnknown with a *types.SlimCNP, also without the Status field of the given CNP, in its Obj. If obj is a *types.SlimCNP or a cache.DeletedFinalStateUnknown with a *types.SlimCNP in its Obj, obj is returned without any transformations. If the given obj can't be cast into either *cilium_v2.CiliumClusterwideNetworkPolicy nor cache.DeletedFinalStateUnknown, an error is returned.
func TransformToCNP ¶ added in v0.15.7
TransformToCNP transforms a *cilium_v2.CiliumNetworkPolicy into a *types.SlimCNP without the Status field of the given CNP, or a cache.DeletedFinalStateUnknown into a cache.DeletedFinalStateUnknown with a *types.SlimCNP, also without the Status field of the given CNP, in its Obj. If obj is a *types.SlimCNP or a cache.DeletedFinalStateUnknown with a *types.SlimCNP in its Obj, obj is returned without any transformations. If the given obj can't be cast into either *cilium_v2.CiliumNetworkPolicy nor cache.DeletedFinalStateUnknown, an error is returned.
func TransformToCiliumEndpoint ¶ added in v0.15.7
TransformToCiliumEndpoint transforms a *cilium_v2.CiliumEndpoint into a *types.CiliumEndpoint or a cache.DeletedFinalStateUnknown into a cache.DeletedFinalStateUnknown with a *types.CiliumEndpoint in its Obj. If obj is a *types.CiliumEndpoint or a cache.DeletedFinalStateUnknown with a *types.CiliumEndpoint in its Obj, obj is returned without any transformations. If the given obj can't be cast into either *cilium_v2.CiliumEndpoint nor cache.DeletedFinalStateUnknown, an error is returned.
Types ¶
type Backend ¶ added in v0.15.7
type Backend struct {
Ports map[loadbalancer.L4Addr][]string
NodeName string
Hostname string
Terminating bool
HintsForZones []string
Preferred bool
Zone string
}
Backend contains all ports, terminating state, and the node name of a given backend
+k8s:deepcopy-gen=true +deepequal-gen=false
func (*Backend) DeepCopy ¶ added in v0.15.7
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Backend.
func (*Backend) DeepCopyInto ¶ added in v0.15.7
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (*Backend) ToPortConfiguration ¶ added in v1.18.0
func (b *Backend) ToPortConfiguration() serviceStore.PortConfiguration
type CacheStoreEvent ¶ added in v1.17.0
type CacheStoreEvent struct {
Kind CacheStoreEventKind
Obj any
}
type CacheStoreEventKind ¶ added in v1.17.0
type CacheStoreEventKind int
type CiliumResourceParams ¶ added in v1.16.0
type CiliumResourceParams struct {
cell.In
Logger *slog.Logger
Lifecycle cell.Lifecycle
ClientSet client.Clientset
CRDSyncPromise promise.Promise[synced.CRDSync] `optional:"true"`
}
Dependencies for Cilium resources that may be used by Cilium Agent. When CRDSyncPromise is provided, watchers of resources using this will block until all CRDs used by the agent have been registered. Agent will fail to start if Cilium Operator does not register all the CRDs in time.
type Config ¶ added in v1.15.0
type Config struct {
EnableK8sEndpointSlice bool
// K8sServiceProxyName is the value of service.kubernetes.io/service-proxy-name label,
// that identifies the service objects Cilium should handle.
// If the provided value is an empty string, Cilium will manage service objects when
// the label is not present. For more details -
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/2447-Make-kube-proxy-service-abstraction-optional
K8sServiceProxyName string
}
Config defines the configuration options for k8s resources.
type ConfigParams ¶ added in v1.18.2
type ConfigParams struct {
cell.In
Config Config
WatchConfig ServiceWatchConfig
}
type EndpointSliceID ¶ added in v0.15.7
type EndpointSliceID struct {
ServiceName loadbalancer.ServiceName
EndpointSliceName string
}
EndpointSliceID identifies a Kubernetes EndpointSlice as well as the legacy v1.Endpoints.
func ParseEndpointSliceID ¶ added in v0.15.7
func ParseEndpointSliceID(es endpointSlice) EndpointSliceID
ParseEndpointSliceID parses a Kubernetes endpoints slice and returns a EndpointSliceID
func ParseEndpointsID ¶ added in v0.15.7
func ParseEndpointsID(ep *slim_corev1.Endpoints) EndpointSliceID
ParseEndpointsID parses a Kubernetes endpoints and returns the EndpointSliceID
type EndpointSlices ¶ added in v0.15.7
type EndpointSlices struct {
// contains filtered or unexported fields
}
EndpointSlices is the collection of all endpoint slices of a service. The map key is the name of the endpoint slice or the name of the legacy v1.Endpoint. The endpoints stored here are not namespaced since this structure is only used as a value of another map that is already namespaced.
+deepequal-gen=true
func NewEndpointsSlices ¶ added in v1.16.4
func NewEndpointsSlices() *EndpointSlices
NewEndpointsSlices returns a new EndpointSlices
func (*EndpointSlices) DeepEqual ¶ added in v0.15.7
func (in *EndpointSlices) DeepEqual(other *EndpointSlices) bool
DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.
func (*EndpointSlices) Delete ¶ added in v0.15.7
func (es *EndpointSlices) Delete(esName string) bool
Delete deletes the endpoint slice in the internal map. Returns true if there are not any more endpoints available in the map.
func (*EndpointSlices) GetEndpoints ¶ added in v0.15.7
func (es *EndpointSlices) GetEndpoints() *Endpoints
GetEndpoints returns a read only a single *Endpoints structure with all Endpoints' backends joined.
func (*EndpointSlices) Upsert ¶ added in v0.15.7
func (es *EndpointSlices) Upsert(esName string, e *Endpoints)
Upsert maps the 'esname' to 'e'. - 'esName': Name of the Endpoint Slice - 'e': Endpoints to store in the map
type Endpoints ¶ added in v0.15.7
type Endpoints struct {
types.UnserializableObject
slim_metav1.ObjectMeta
EndpointSliceID
// Backends is a map containing all backend IPs and ports. The key to
// the map is the backend IP in string form. The value defines the list
// of ports for that backend IP, plus an additional optional node name.
// Backends map[cmtypes.AddrCluster]*Backend
Backends map[cmtypes.AddrCluster]*Backend
}
Endpoints is an abstraction for the Kubernetes endpoints object. Endpoints consists of a set of backend IPs in combination with a set of ports and protocols. The name of the backend ports must match the names of the frontend ports of the corresponding service.
The Endpoints object is parsed from either an EndpointSlice (preferred) or Endpoint Kubernetes objects depending on the Kubernetes version.
+k8s:deepcopy-gen=true +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +deepequal-gen=true +deepequal-gen:private-method=true
func ParseEndpointSliceV1 ¶ added in v0.15.7
func ParseEndpointSliceV1(logger *slog.Logger, ep *slim_discovery_v1.EndpointSlice) *Endpoints
ParseEndpointSliceV1 parses a Kubernetes EndpointSlice resource. It reads ready and terminating state of endpoints in the EndpointSlice to return an EndpointSlice ID and a filtered list of Endpoints for service load-balancing.
func ParseEndpointSliceV1Beta1 ¶ added in v0.15.7
func ParseEndpointSliceV1Beta1(ep *slim_discovery_v1beta1.EndpointSlice) *Endpoints
ParseEndpointSliceV1Beta1 parses a Kubernetes EndpointsSlice v1beta1 resource It reads ready and terminating state of endpoints in the EndpointSlice to return an EndpointSlice ID and a filtered list of Endpoints for service load-balancing.
func ParseEndpoints ¶ added in v0.15.7
func ParseEndpoints(ep *slim_corev1.Endpoints) *Endpoints
ParseEndpoints parses a Kubernetes Endpoints resource
func (*Endpoints) DeepCopyInto ¶ added in v0.15.7
func (*Endpoints) DeepCopyObject ¶ added in v0.15.7
DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (*Endpoints) DeepEqual ¶ added in v0.15.7
DeepEqual returns true if both endpoints are deep equal.
type JSONPatch ¶ added in v0.15.7
type JSONPatch struct {
OP string `json:"op,omitempty"`
Path string `json:"path,omitempty"`
Value any `json:"value"`
}
JSONPatch structure based on the RFC 6902
type MergeFunc ¶ added in v1.17.0
type MergeFunc[Obj any] func(old Obj, new Obj) Obj
MergeFunc is an optional function to merge the new object with an existing object in th target table. Only invoked if an old object exists.
type QueryAllFunc ¶ added in v1.17.0
type QueryAllFunc[Obj any] func(statedb.ReadTxn, statedb.Table[Obj]) iter.Seq2[Obj, statedb.Revision]
QueryAllFunc is an optional function to give to the Kubernetes reflector to query all objects in the table that are managed by the reflector. It is used to delete all objects when the underlying cache.Reflector needs to Replace() all items for a resync.
type ReflectorConfig ¶ added in v1.17.0
type ReflectorConfig[Obj any] struct { // Mandatory name of the reflector. This is used as the table initializer name and as // the reflector job name. Name string // Mandatory table to reflect the objects to. Table statedb.RWTable[Obj] // Mandatory ListerWatcher to use to retrieve the objects. // // Use [utils.ListerWatcherFromTyped] to create one from the Clientset, e.g. // // var cs client.Clientset // utils.ListerWatcherFromTyped(cs.CoreV1().Nodes()) // ListerWatcher cache.ListerWatcher // Optional maximum number of objects to commit in one transaction. Uses default if left zero. // This does not apply to the initial listing which is committed in one go. BufferSize int // Optional amount of time to wait for the buffer to fill. Uses default if left zero. BufferWaitTime time.Duration // Optional function to transform the objects given by the ListerWatcher. This can // be used to convert into an internal model on the fly to save space and add additional // fields or to for example implement TableRow/TableHeader for the "db/show" command. // // The object given to the transform function can be modified without copying. Transform TransformFunc[Obj] // Optional function to transform the object to a set of objects to insert or delete. // If set, [Transform] must be nil. // // The object given to the transform function can be modified without copying. TransformMany TransformManyFunc[Obj] // Optional function to query all objects. Used when replacing the objects on resync. // This can be used to "namespace" the objects managed by this reflector, e.g. on // source.Source etc. // // This function becomes mandatory when working with multiple sources to avoid deleting // all objects when the underlying `cache.Reflector` needs to `Replace()` all items during // a resync. QueryAll QueryAllFunc[Obj] // Optional function to merge the new object with an existing object in the target // table. Merge MergeFunc[Obj] // Optional promise for waiting for the CRD referenced by the [ListerWatcher] to // be registered. CRDSync promise.Promise[synced.CRDSync] // Optional metric scope for updating the [metrics.KubernetesEventReceived] metric // when ingesting an object. MetricScope string // ClearTableOnStop if true will cause all inserted objects to be deleted (using QueryAll) // when the reflector is stopped. ClearTableOnStop bool }
func (ReflectorConfig[Obj]) JobName ¶ added in v1.17.0
func (cfg ReflectorConfig[Obj]) JobName() string
JobName returns the name of the background reflector job.
type ServiceWatchConfig ¶ added in v1.18.2
type ServiceWatchConfig struct {
// EnableHeadlessServiceWatch controls whether watches for Headless Services and
// Headless Services Endpoint Slices are enabled. Disabling the watch reduces
// the load on apiserver in clusters with headless services.
EnableHeadlessServiceWatch bool
}
func DefaultServiceWatchConfig ¶ added in v1.18.2
func DefaultServiceWatchConfig() ServiceWatchConfig
type TransformFunc ¶ added in v1.17.0
TransformFunc is an optional function to give to the reflector to transform the object returned by the ListerWatcher to the desired target object. If the function returns false the object is silently skipped.
The object given to the transform function can be modified without copying.
type TransformManyFunc ¶ added in v1.17.0
type TransformManyFunc[Obj any] func(txn statedb.ReadTxn, deleted bool, obj any) (toInsert, toDelete iter.Seq[Obj])
TransformManyFunc is an optional function to give to the reflector to transform the object returned by the ListerWatcher to the desired set of target objects to insert or delete.
The object given to the transform function can be modified without copying.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cilium.io/v2
Package v2 is the v2 version of the API.
|
Package v2 is the v2 version of the API. |
|
cilium.io/v2alpha1
Package v2alpha1 is the v2alpha1 version of the API.
|
Package v2alpha1 is the v2alpha1 version of the API. |
|
clientset/versioned/fake
This package has the automatically generated fake clientset.
|
This package has the automatically generated fake clientset. |
|
clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
|
This package contains the scheme of the automatically generated clientset. |
|
clientset/versioned/typed/cilium.io/v2
This package has the automatically generated typed clients.
|
This package has the automatically generated typed clients. |
|
clientset/versioned/typed/cilium.io/v2/fake
Package fake has the automatically generated clients.
|
Package fake has the automatically generated clients. |
|
clientset/versioned/typed/cilium.io/v2alpha1
This package has the automatically generated typed clients.
|
This package has the automatically generated typed clients. |
|
clientset/versioned/typed/cilium.io/v2alpha1/fake
Package fake has the automatically generated clients.
|
Package fake has the automatically generated clients. |
|
example
command
|
|
|
slim
|
|
|
k8s/api/core/v1
Package v1 is the v1 version of the core API.
|
Package v1 is the v1 version of the core API. |
|
k8s/api/discovery/v1
Package v1 contains slimmer versions of k8s discovery types.
|
Package v1 contains slimmer versions of k8s discovery types. |
|
k8s/api/discovery/v1beta1
Package v1beta1 contains slimmer versions of k8s discovery types.
|
Package v1beta1 contains slimmer versions of k8s discovery types. |
|
k8s/api/networking/v1
Package v1 contains slimmer versions of k8s networking types.
|
Package v1 contains slimmer versions of k8s networking types. |
|
k8s/apiextensions-client/clientset/versioned/fake
This package has the automatically generated fake clientset.
|
This package has the automatically generated fake clientset. |
|
k8s/apiextensions-client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
|
This package contains the scheme of the automatically generated clientset. |
|
k8s/apiextensions-client/clientset/versioned/typed/apiextensions/v1
This package has the automatically generated typed clients.
|
This package has the automatically generated typed clients. |
|
k8s/apiextensions-client/clientset/versioned/typed/apiextensions/v1/fake
Package fake has the automatically generated clients.
|
Package fake has the automatically generated clients. |
|
k8s/apis/apiextensions/v1
Package v1 is the v1 version of the API.
|
Package v1 is the v1 version of the API. |
|
k8s/apis/labels
Package labels implements a simple label system, parsing and matching selectors with sets of labels.
|
Package labels implements a simple label system, parsing and matching selectors with sets of labels. |
|
k8s/apis/meta/v1
Package v1 contains API types that are common to all versions.
|
Package v1 contains API types that are common to all versions. |
|
k8s/apis/meta/v1beta1
package v1beta1 is alpha objects from meta that will be introduced.
|
package v1beta1 is alpha objects from meta that will be introduced. |
|
k8s/apis/util/intstr
Package types contains slimmer versions of k8s types.
|
Package types contains slimmer versions of k8s types. |
|
k8s/client/clientset/versioned/fake
This package has the automatically generated fake clientset.
|
This package has the automatically generated fake clientset. |
|
k8s/client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
|
This package contains the scheme of the automatically generated clientset. |
|
k8s/client/clientset/versioned/typed/core/v1
This package has the automatically generated typed clients.
|
This package has the automatically generated typed clients. |
|
k8s/client/clientset/versioned/typed/core/v1/fake
Package fake has the automatically generated clients.
|
Package fake has the automatically generated clients. |
|
k8s/client/clientset/versioned/typed/discovery/v1
This package has the automatically generated typed clients.
|
This package has the automatically generated typed clients. |
|
k8s/client/clientset/versioned/typed/discovery/v1/fake
Package fake has the automatically generated clients.
|
Package fake has the automatically generated clients. |
|
k8s/client/clientset/versioned/typed/discovery/v1beta1
This package has the automatically generated typed clients.
|
This package has the automatically generated typed clients. |
|
k8s/client/clientset/versioned/typed/discovery/v1beta1/fake
Package fake has the automatically generated clients.
|
Package fake has the automatically generated clients. |
|
k8s/client/clientset/versioned/typed/networking/v1
This package has the automatically generated typed clients.
|
This package has the automatically generated typed clients. |
|
k8s/client/clientset/versioned/typed/networking/v1/fake
Package fake has the automatically generated clients.
|
Package fake has the automatically generated clients. |
|
Package synced provides tools for tracking if k8s resources have been initially sychronized with the k8s apiserver.
|
Package synced provides tools for tracking if k8s resources have been initially sychronized with the k8s apiserver. |
|
Package types contains slimmer versions of k8s types.
|
Package types contains slimmer versions of k8s types. |
|
Package version keeps track of the Kubernetes version the client is connected to
|
Package version keeps track of the Kubernetes version the client is connected to |
|
resources
This package contains exported resource identifiers and metric resource labels related to K8s watchers.
|
This package contains exported resource identifiers and metric resource labels related to K8s watchers. |
|
subscriber
Package subscriber implements a mechanism to represent K8s watcher subscribers and allows K8s events to objects / resources to notify their respective subscribers.
|
Package subscriber implements a mechanism to represent K8s watcher subscribers and allows K8s events to objects / resources to notify their respective subscribers. |