Documentation
¶
Index ¶
- Constants
- func NewIPTablesHandlers(config *options.KubeRouterConfig) (map[v1core.IPFamily]utils.IPTablesHandler, ...)
- func NewKnftablesInterfaces(ctx context.Context, config *options.KubeRouterConfig) (map[v1core.IPFamily]knftables.Interface, error)
- type Informers
- type NetworkPolicyController
- type NetworkPolicyControllerBase
- func (npc *NetworkPolicyControllerBase) ListNamespaceByLabels(namespaceSelector labels.Selector) ([]*api.Namespace, error)
- func (npc *NetworkPolicyControllerBase) ListPodsByNamespaceAndLabels(namespace string, podSelector labels.Selector) (ret []*api.Pod, err error)
- func (npc *NetworkPolicyControllerBase) NamespaceEventHandler() cache.ResourceEventHandler
- func (npc *NetworkPolicyControllerBase) NetworkPolicyEventHandler() cache.ResourceEventHandler
- func (npc *NetworkPolicyControllerBase) OnNetworkPolicyUpdate(obj any)
- func (npc *NetworkPolicyControllerBase) OnPodUpdate(obj any)
- func (npc *NetworkPolicyControllerBase) PodEventHandler() cache.ResourceEventHandler
- func (npc *NetworkPolicyControllerBase) RequestFullSync()
- type NetworkPolicyControllerIptables
- type NetworkPolicyControllerNftables
Constants ¶
const (
PodCompleted api.PodPhase = "Completed"
)
Variables ¶
This section is empty.
Functions ¶
func NewIPTablesHandlers ¶
func NewIPTablesHandlers(config *options.KubeRouterConfig) ( map[v1core.IPFamily]utils.IPTablesHandler, map[v1core.IPFamily]utils.IPSetHandler, error)
Types ¶
type Informers ¶ added in v2.11.0
type Informers interface {
Pods() cache.SharedIndexInformer
Namespaces() cache.SharedIndexInformer
NetworkPolicies() cache.SharedIndexInformer
}
Informers is the set of shared informers the NPC reads from. We declare it here rather than accepting a full informer factory so that the controller can only reach the resources it actually watches.
type NetworkPolicyController ¶
type NetworkPolicyController interface {
Run(healthChan chan<- *healthcheck.ControllerHeartbeat, stopCh <-chan struct{}, wg *sync.WaitGroup)
RequestFullSync()
PodEventHandler() cache.ResourceEventHandler
NamespaceEventHandler() cache.ResourceEventHandler
NetworkPolicyEventHandler() cache.ResourceEventHandler
// contains filtered or unexported methods
}
NetworkPolicyController provides both ingress and egress filtering for pods as per the defined network policies. This interface has two implementations: one using iptables/ipsets and one using nftables. The implementation is selected via the UseNftablesForNetpol configuration option.
Both implementations use a similar architecture with per-pod firewall chains and per-policy chains. Each pod requiring ingress or egress filtering gets a pod-specific chain. Each network policy has its own chain with rules matching source and destination pod IPs (via ipsets or nftables sets). Traffic is filtered by jumping from top-level chains (INPUT, FORWARD, OUTPUT) to pod-specific chains, then to matching network policy chains, until a match accepts the packet or it gets dropped.
func NewNetworkPolicyController ¶
func NewNetworkPolicyController(clientset kubernetes.Interface, config *options.KubeRouterConfig, informers Informers, ipsetMutex *sync.Mutex, linkQ utils.LocalLinkQuerier, iptablesCmdHandlers map[v1core.IPFamily]utils.IPTablesHandler, ipSetHandlers map[v1core.IPFamily]utils.IPSetHandler, ipRanges svcip.RangeQuerier, knftInterfaces map[v1core.IPFamily]knftables.Interface, ) (NetworkPolicyController, error)
NewNetworkPolicyController returns new NetworkPolicyController object
type NetworkPolicyControllerBase ¶ added in v2.11.0
type NetworkPolicyControllerBase struct {
MetricsEnabled bool
// contains filtered or unexported fields
}
NetworkPolicyController struct to hold information required by NetworkPolicyController
func (*NetworkPolicyControllerBase) ListNamespaceByLabels ¶ added in v2.11.0
func (*NetworkPolicyControllerBase) ListPodsByNamespaceAndLabels ¶ added in v2.11.0
func (*NetworkPolicyControllerBase) NamespaceEventHandler ¶ added in v2.11.0
func (npc *NetworkPolicyControllerBase) NamespaceEventHandler() cache.ResourceEventHandler
func (*NetworkPolicyControllerBase) NetworkPolicyEventHandler ¶ added in v2.11.0
func (npc *NetworkPolicyControllerBase) NetworkPolicyEventHandler() cache.ResourceEventHandler
func (*NetworkPolicyControllerBase) OnNetworkPolicyUpdate ¶ added in v2.11.0
func (npc *NetworkPolicyControllerBase) OnNetworkPolicyUpdate(obj any)
OnNetworkPolicyUpdate handles updates to network policy from the kubernetes api server
func (*NetworkPolicyControllerBase) OnPodUpdate ¶ added in v2.11.0
func (npc *NetworkPolicyControllerBase) OnPodUpdate(obj any)
OnPodUpdate handles updates to pods from the Kubernetes api server
func (*NetworkPolicyControllerBase) PodEventHandler ¶ added in v2.11.0
func (npc *NetworkPolicyControllerBase) PodEventHandler() cache.ResourceEventHandler
func (*NetworkPolicyControllerBase) RequestFullSync ¶ added in v2.11.0
func (npc *NetworkPolicyControllerBase) RequestFullSync()
RequestFullSync allows the request of a full network policy sync without blocking the callee
type NetworkPolicyControllerIptables ¶ added in v2.11.0
type NetworkPolicyControllerIptables struct {
*NetworkPolicyControllerBase
// contains filtered or unexported fields
}
NetworkPolicyControllerIptables is the iptables-based implementation of NetworkPolicyController. It uses iptables chains and ipsets to enforce Kubernetes network policies. This is the original implementation and is used when UseNftablesForNetpol is disabled (the default behavior).
func NewNetworkPolicyControllerIptables ¶ added in v2.11.0
func NewNetworkPolicyControllerIptables( npcBase *NetworkPolicyControllerBase, config *options.KubeRouterConfig, iptablesCmdHandlers map[v1core.IPFamily]utils.IPTablesHandler, ipSetHandlers map[v1core.IPFamily]utils.IPSetHandler) (*NetworkPolicyControllerIptables, error)
NewNetworkPolicyControllerIptables returns new NetworkPolicyControllerIptables object
func (*NetworkPolicyControllerIptables) Cleanup ¶ added in v2.11.0
func (npc *NetworkPolicyControllerIptables) Cleanup()
Cleanup cleanup configurations done
func (*NetworkPolicyControllerIptables) Run ¶ added in v2.11.0
func (npc *NetworkPolicyControllerIptables) Run( healthChan chan<- *healthcheck.ControllerHeartbeat, stopCh <-chan struct{}, wg *sync.WaitGroup)
Run runs forever till we receive notification on stopCh
type NetworkPolicyControllerNftables ¶ added in v2.11.0
type NetworkPolicyControllerNftables struct {
*NetworkPolicyControllerBase
// contains filtered or unexported fields
}
NetworkPolicyControllerNftables is the nftables-based implementation of NetworkPolicyController. It uses nftables chains and named sets (instead of iptables chains and ipsets) to enforce Kubernetes network policies. This implementation is enabled via the UseNftablesForNetpol configuration option and provides the same network policy functionality as the iptables implementation.
func NewNetworkPolicyControllerNftables ¶ added in v2.11.0
func NewNetworkPolicyControllerNftables( npcBase *NetworkPolicyControllerBase, config *options.KubeRouterConfig, knftInterfaces map[v1core.IPFamily]knftables.Interface) (*NetworkPolicyControllerNftables, error)
func (*NetworkPolicyControllerNftables) Cleanup ¶ added in v2.11.0
func (npc *NetworkPolicyControllerNftables) Cleanup()
Cleanup removes the nftables tables created by kube-router for network policies.
func (*NetworkPolicyControllerNftables) Run ¶ added in v2.11.0
func (npc *NetworkPolicyControllerNftables) Run( healthChan chan<- *healthcheck.ControllerHeartbeat, stopCh <-chan struct{}, wg *sync.WaitGroup)
Run runs forever till we receive notification on stopCh