utils

package
v0.0.0-...-53bcc3a Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressesDefault

func AddressesDefault(preferIPv6 bool, af AddressFilter) ([]net.IP, error)

AddressesDefault returns a slice of configured addresses in the current network namespace associated with default routes; IPv4 first (if any), then IPv6 (if any). You can optionally pass an AddressFilter to further filter down which addresses are considered

func AddressesRouting

func AddressesRouting(vips []net.IP, af AddressFilter, preferIPv6 bool) ([]net.IP, error)

AddressesRouting takes a slice of Virtual IPs and returns a configured address in the current network namespace that directly routes to at least one of those vips. If the interface containing that address is dual-stack, it will also return a single address of the opposite IP family. You can optionally pass an AddressFilter to further filter down which addresses are considered

func AlarmStabilization

func AlarmStabilization(cur_alrm bool, cur_defect bool, consecutive_ctr uint8, on_threshold uint8, off_threshold uint8) (bool, uint8)

func ConvertIpsToStrings

func ConvertIpsToStrings(ips []net.IP) []string

func CreateFileWatcher

func CreateFileWatcher(log logrus.FieldLogger, fileName string) (*fsnotify.Watcher, error)

func FletcherChecksum8

func FletcherChecksum8(inp string) uint8

func GetClientConfig

func GetClientConfig(kubeApiServerUrl, kubeconfigPath string) (*rest.Config, error)

getClientConfig returns a Kubernetes client Config.

func GetFileMd5

func GetFileMd5(filePath string) (string, error)

func GetInterfaceWithCidrByIP

func GetInterfaceWithCidrByIP(ip net.IP, strictMatch bool) (*net.Interface, *net.IPNet, error)

GetInterfaceWithCidrByIP returns the interface and network that has the passed IP address configured. It allows to run in a non-strict mode in which it's not required to match the exact IP address but only a subnet.

E.g. for interface configured as "192.168.1.1/24" strict mode asked about "192.168.1.2" returns FALSE whereas in non-strict mode it returns TRUE.

func GetLocalCIDRByIP

func GetLocalCIDRByIP(ip string) (string, error)

func IpInCidr

func IpInCidr(ipAddr, cidr string) (bool, error)

func IsIPv4

func IsIPv4(ip net.IP) bool

func IsIPv6

func IsIPv6(ip net.IP) bool

func IsKubernetesHealthy

func IsKubernetesHealthy(port uint16) (bool, error)

func IsNetIPv6

func IsNetIPv6(network net.IPNet) bool

func Mapper

func Mapper[T, U any](data []T, f func(T) U) []U

func RunWatcher

func RunWatcher(log logrus.FieldLogger, watcher *fsnotify.Watcher, fileName string) (bool, error)

func SetDebugLogLevel

func SetDebugLogLevel()

func ShortHostname

func ShortHostname() (shortName string, err error)

func SplitCIDR

func SplitCIDR(s string) (string, string, error)

func ValidNodeAddress

func ValidNodeAddress(address netlink.Addr) bool

ValidNodeAddress returns true if the address is suitable for a node's primary IP

func ValidOVNNodeAddress

func ValidOVNNodeAddress(address netlink.Addr) bool

ValidOVNNodeAddress returns true if the address is suitable for a node's primary IP and is not fd69::2 we intentionally don't filter ipv4 because it isn't necessary.

Types

type AddressFilter

type AddressFilter func(netlink.Addr) bool

AddressFilter is a function type to filter addresses

type FoundAddress

type FoundAddress struct {
	Network         net.IPNet
	Priority        int
	LinkIndex       int
	GatewayOnSubnet bool
}

type RouteFilter

type RouteFilter func(netlink.Route) bool

RouteFilter is a function type to filter routes

Jump to

Keyboard shortcuts

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