package util
import "k8s.io/kubernetes/pkg/proxy/util"
Index ¶
- Constants
- func AddressSet(isValid func(ip net.IP) bool, addrs []net.Addr) sets.Set[string]
- func AppendPortIfNeeded(addr string, port int32) string
- func BuildPortsToEndpointsMap(endpoints *v1.Endpoints) map[string][]string
- func EnsureSysctl(sysctl utilsysctl.Interface, name string, newVal int) error
- func GetClusterIPByFamily(ipFamily v1.IPFamily, service *v1.Service) string
- func GetIPFamilyFromIP(ip net.IP) v1.IPFamily
- func GetLocalAddrSet() netutils.IPSet
- func GetLocalAddrs() ([]net.IP, error)
- func IPPart(s string) string
- func IsLoopBack(ip string) bool
- func IsVIPMode(ing v1.LoadBalancerIngress) bool
- func IsZeroCIDR(cidr string) bool
- func LogAndEmitIncorrectIPVersionEvent(recorder events.EventRecorder, fieldName, fieldValue, svcNamespace, svcName string, svcUID types.UID)
- func MapCIDRsByIPFamily(cidrsStrings []string) map[v1.IPFamily][]*net.IPNet
- func MapIPsByIPFamily(ipStrings []string) map[v1.IPFamily][]net.IP
- func OtherIPFamily(ipFamily v1.IPFamily) v1.IPFamily
- func PortPart(s string) (int, error)
- func RevertPorts(replacementPortsMap, originalPortsMap map[netutils.LocalPort]netutils.Closeable)
- func ShouldSkipService(service *v1.Service) bool
- func ShuffleStrings(s []string) []string
- type LineBuffer
- type NetworkInterfacer
- type NodePortAddresses
- func NewNodePortAddresses(family v1.IPFamily, cidrStrings []string, primaryIP net.IP) *NodePortAddresses
- func (npa *NodePortAddresses) ContainsIPv4Loopback() bool
- func (npa *NodePortAddresses) GetNodeIPs(nw NetworkInterfacer) ([]net.IP, error)
- func (npa *NodePortAddresses) MatchAll() bool
- func (npa *NodePortAddresses) String() string
- type RealNetwork
Constants ¶
const ( // IPv4ZeroCIDR is the CIDR block for the whole IPv4 address space IPv4ZeroCIDR = "0.0.0.0/0" // IPv6ZeroCIDR is the CIDR block for the whole IPv6 address space IPv6ZeroCIDR = "::/0" )
Functions ¶
func AddressSet ¶
AddressSet validates the addresses in the slice using the "isValid" function. Addresses that pass the validation are returned as a string Set.
func AppendPortIfNeeded ¶
AppendPortIfNeeded appends the given port to IP address unless it is already in "ipv4:port" or "[ipv6]:port" format.
func BuildPortsToEndpointsMap ¶
BuildPortsToEndpointsMap builds a map of portname -> all ip:ports for that portname. Explode Endpoints.Subsets[*] into this structure.
func EnsureSysctl ¶
func EnsureSysctl(sysctl utilsysctl.Interface, name string, newVal int) error
EnsureSysctl sets a kernel sysctl to a given numeric value.
func GetClusterIPByFamily ¶
GetClusterIPByFamily returns a service clusterip by family
func GetIPFamilyFromIP ¶
GetIPFamilyFromIP Returns the IP family of ipStr, or IPFamilyUnknown if ipStr can't be parsed as an IP
func GetLocalAddrSet ¶
GetLocalAddrSet return a local IPSet. If failed to get local addr, will assume no local ips.
func GetLocalAddrs ¶
GetLocalAddrs returns a list of all network addresses on the local system
func IPPart ¶
IPPart returns just the IP part of an IP or IP:port or endpoint string. If the IP part is an IPv6 address enclosed in brackets (e.g. "[fd00:1::5]:9999"), then the brackets are stripped as well.
func IsLoopBack ¶
IsLoopBack checks if a given IP address is a loopback address.
func IsVIPMode ¶
func IsVIPMode(ing v1.LoadBalancerIngress) bool
func IsZeroCIDR ¶
IsZeroCIDR checks whether the input CIDR string is either the IPv4 or IPv6 zero CIDR
func LogAndEmitIncorrectIPVersionEvent ¶
func LogAndEmitIncorrectIPVersionEvent(recorder events.EventRecorder, fieldName, fieldValue, svcNamespace, svcName string, svcUID types.UID)
LogAndEmitIncorrectIPVersionEvent logs and emits incorrect IP version event.
func MapCIDRsByIPFamily ¶
MapCIDRsByIPFamily maps a slice of CIDRs to their respective IP families (v4 or v6)
func MapIPsByIPFamily ¶
MapIPsByIPFamily maps a slice of IPs to their respective IP families (v4 or v6)
func OtherIPFamily ¶
OtherIPFamily returns the other ip family
func PortPart ¶
PortPart returns just the port part of an endpoint string.
func RevertPorts ¶
RevertPorts is closing ports in replacementPortsMap but not in originalPortsMap. In other words, it only closes the ports opened in this sync.
func ShouldSkipService ¶
ShouldSkipService checks if a given service should skip proxying
func ShuffleStrings ¶
ShuffleStrings copies strings from the specified slice into a copy in random order. It returns a new slice.
Types ¶
type LineBuffer ¶
type LineBuffer interface { // Write takes a list of arguments, each a string or []string, joins all the // individual strings with spaces, terminates with newline, and writes them to the // buffer. Any other argument type will panic. Write(args ...interface{}) // WriteBytes writes bytes to the buffer, and terminates with newline. WriteBytes(bytes []byte) // Reset clears the buffer Reset() // Bytes returns the contents of the buffer as a []byte Bytes() []byte // String returns the contents of the buffer as a string String() string // Lines returns the number of lines in the buffer. Note that more precisely, this // returns the number of times Write() or WriteBytes() was called; it assumes that // you never wrote any newlines to the buffer yourself. Lines() int }
LineBuffer is an interface for writing lines of input to a bytes.Buffer
func NewDiscardLineBuffer ¶
func NewDiscardLineBuffer() LineBuffer
NewDiscardLineBuffer returns a dummy LineBuffer that counts the number of writes but throws away the data. (This is used for iptables proxy partial syncs, to keep track of how many rules we managed to avoid having to sync.)
func NewLineBuffer ¶
func NewLineBuffer() LineBuffer
NewLineBuffer returns a new "real" LineBuffer
type NetworkInterfacer ¶
NetworkInterfacer defines an interface for several net library functions. Production code will forward to net library functions, and unit tests will override the methods for testing purposes.
type NodePortAddresses ¶
type NodePortAddresses struct {
// contains filtered or unexported fields
}
NodePortAddresses is used to handle the --nodeport-addresses flag
func NewNodePortAddresses ¶
func NewNodePortAddresses(family v1.IPFamily, cidrStrings []string, primaryIP net.IP) *NodePortAddresses
NewNodePortAddresses takes an IP family and the `--nodeport-addresses` value (which is assumed to contain only valid CIDRs, potentially of both IP families) and the primary IP (which will be used as node port address when `--nodeport-addresses` is empty). It will return a NodePortAddresses object for the given family. If there are no CIDRs of the given family then the CIDR "0.0.0.0/0" or "::/0" will be added (even if there are CIDRs of the other family).
func (*NodePortAddresses) ContainsIPv4Loopback ¶
func (npa *NodePortAddresses) ContainsIPv4Loopback() bool
ContainsIPv4Loopback returns true if npa's CIDRs contain an IPv4 loopback address.
func (*NodePortAddresses) GetNodeIPs ¶
func (npa *NodePortAddresses) GetNodeIPs(nw NetworkInterfacer) ([]net.IP, error)
GetNodeIPs return all matched node IP addresses for npa's CIDRs. If no matching IPs are found, it returns an empty list. NetworkInterfacer is injected for test purpose.
func (*NodePortAddresses) MatchAll ¶
func (npa *NodePortAddresses) MatchAll() bool
MatchAll returns true if npa matches all node IPs (of npa's given family)
func (*NodePortAddresses) String ¶
func (npa *NodePortAddresses) String() string
type RealNetwork ¶
type RealNetwork struct{}
RealNetwork implements the NetworkInterfacer interface for production code, just wrapping the underlying net library function calls.
func (RealNetwork) InterfaceAddrs ¶
func (RealNetwork) InterfaceAddrs() ([]net.Addr, error)
InterfaceAddrs wraps net.InterfaceAddrs(), it's a part of NetworkInterfacer interface.
Source Files ¶
endpoints.go linebuffer.go network.go nodeport_addresses.go utils.go
Directories ¶
Path | Synopsis |
---|---|
pkg/proxy/util/iptables | |
pkg/proxy/util/testing |
- Version
- v1.30.9
- Published
- Jan 15, 2025
- Platform
- js/wasm
- Imports
- 16 packages
- Last checked
- 4 minutes ago –
Tools for package owners.