utils

package
v0.0.0-...-c316130 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 41 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// SysClassNet is a directory for network interface data
	SysClassNet = "/sys/class/net"
)

Variables

View Source
var CipherMap map[string]uint16

Functions

func CheckGrpcServerStatus

func CheckGrpcServerStatus(target string, log *log.Entry, grpcDial GrpcDialType) (bool, error)

CheckGrpcServerStatus will check gRPC server status using gRPC health check

func CleanIntfConfCache

func CleanIntfConfCache(dataDir, refid, podIface string) error

func ConvertCiphers

func ConvertCiphers(ciphers []string) ([]uint16, error)

func CreateCipherMap

func CreateCipherMap()

func DefaultCipherSuites

func DefaultCipherSuites() []string

func GetCDQList

func GetCDQList(pf string, devicePath string) ([]*types.InterfaceInfo, error)

func GetClientCredentials

func GetClientCredentials() (credentials.TransportCredentials, error)

GetClientCredentials returns gRPC client credential based on user provided configuration. if "--insecure=true" it will provide insecure.NewCredentials if "--insecure=false" && "--mtls=true" it will provide mTLS credentials otherwise only server side validation with CA added in client CA pool

func GetDataDirPath

func GetDataDirPath(t string) string

GetDataDirPath will return path to cache directory of given type

func GetIPFromIPAM

func GetIPFromIPAM(ec *EnvConfigurer, ipamExecAdd IpamExecAddFunc) (*net.IPNet, error)

GetIPFromIPAM will request IP address from host-local IPAM, it will be used as Infra host interface

func GetIntfPciAddress

func GetIntfPciAddress(ifName string, prefix string) (string, error)

GetIntfPciAddress takes in an interface name as string and returns it's PCI address when prefix will be not empty it will be prepended before default "/sys/class/net" directory name

func GetK8sClient

func GetK8sClient(config *rest.Config) (kubernetes.Interface, error)

func GetK8sConfig

func GetK8sConfig() (*rest.Config, error)

func GetNodeIP

func GetNodeIP(client kubernetes.Interface, nodeName string) (string, error)

func GetNodeIPFromEnv

func GetNodeIPFromEnv() (ipAddr string, err error)

func GetNodeName

func GetNodeName() (string, error)

func GetNodeNetInterface

func GetNodeNetInterface(k8sclient kubernetes.Interface, nodeName string, ifGetter InterfaceAddressGetter, logEntry *log.Entry) (string, error)

func GetNodePodsCIDR

func GetNodePodsCIDR(k8sclient kubernetes.Interface, nodeName string) (string, error)

func GetSubnets

func GetSubnets(client kubernetes.Interface) error

GetSubnets gets service and pod subnet

func GetTapInterfaces

func GetTapInterfaces(prefix string) ([]*types.InterfaceInfo, error)

GetTapInterfaces returns a list of host Tap interance info matching a naming prefix using "prefix"

func GetVFList

func GetVFList(pf string, prefix string) ([]*types.InterfaceInfo, error)

GetVFList returns SRIOV-VF for given pf network interface name when prefix will be not empty it will be prepended before default "/sys/class/net" directory name

func GrpcDial

func GrpcDial(target string, connType ConnType, s Service) (*grpc.ClientConn, error)

func GrpcDialInsecure

func GrpcDialInsecure(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func GrpcDialWithCred

func GrpcDialWithCred(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func IsIn

func IsIn(str string, s []string) bool

func LogInit

func LogInit(logDir string, logLevel string) error

func MakeTimestampMilli

func MakeTimestampMilli() uint64

func NewCalicoWatcher

func NewCalicoWatcher(timeout time.Duration, configPath string, newFsWatcher func() (*fsnotify.Watcher, error)) (*calicoWatcher, error)

NewCalicoWatcher returns new watcher for Calico's config file

func NewGrpcServer

func NewGrpcServer(params ServerParams) (*grpc.Server, error)

func NewGrpcWatcher

func NewGrpcWatcher(timeout, sleepDuration time.Duration, target string, dialFunc GrpcDialType, checkHealth checkGrpcServerStatusType) *grpcWatcher

NewGrpcWatcher returns new gRPC watcher

func ReadInterfaceConf

func ReadInterfaceConf(dataDir, refid, podIface string) (*types.InterfaceInfo, error)

func RegisterSignalHandlers

func RegisterSignalHandlers() <-chan struct{}

RegisterSignalHandlers registers a signal handler for capturedSignals and starts a goroutine that will block until a signal is received. The first signal received will cause the stopCh channel to be closed, giving the opportunity to the program to exist gracefully. If a second signal is received before then, we will force exit with code 1.

func ReleaseIPFromIPAM

func ReleaseIPFromIPAM(ec *EnvConfigurer, ipamExecDel IpamExecDelFunc) error

ReleaseIPFromIPAM will release IP address assigned for Infra host interface

func RemoveStr

func RemoveStr(str string, s []string) []string

func SaveInterfaceConf

func SaveInterfaceConf(dataDir, refid, podIface string, conf *types.InterfaceInfo) error

func StrDiff

func StrDiff(str1, str2 []string) []string

func ValidCiphers

func ValidCiphers(ciphers []string) bool

func ValidLogLevel

func ValidLogLevel(logLevel string) bool

func VerifiedFilePath

func VerifiedFilePath(fileName string, allowedDir string) (string, error)

VerifiedFilePath validates a file for potential file path traversal attacks. It returns the real filepath after cleaning and evaluiating any symlinks in the path. It returns error if the "fileName" is not within the "allowedDir", point to a non-privileged location or "fileName" points to a file outside of allowed dir.

func WaitFor

func WaitFor(w watcher) error

WaitFor will wait for watcher result

Types

type CDQManager

type CDQManager interface {
	CreateIntf() (*types.InterfaceInfo, error)
	RemoveIntf(*types.InterfaceInfo) error
}

func NewCDQManager

func NewCDQManager(masterIntf string, log *log.Entry) (CDQManager, error)

NewCDQManager returns a singleton instance of CDQManager for a master inteface

type Conn

type Conn int
const (
	UnknownMod Conn = iota
	Client
	Server
)

type ConnType

type ConnType int
const (
	UnknownConn ConnType = iota
	Insecure
	TLS
	MTLS
)

func GetConnType

func GetConnType(conn string) ConnType

type DefaultInterfaceAddressGetter

type DefaultInterfaceAddressGetter struct{}

func (*DefaultInterfaceAddressGetter) GetAddr

type EnvConfigurer

type EnvConfigurer struct {
	// contains filtered or unexported fields
}

func NewEnvConfigurer

func NewEnvConfigurer(varCfg variableConfigurer, calicoConfig string) *EnvConfigurer

NewEnvConfigurer will return new environment configurer

type GrpcDialType

type GrpcDialType func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

type IdStack

type IdStack struct {
	// contains filtered or unexported fields
}

func NewIdStack

func NewIdStack() *IdStack

func (*IdStack) GetTop

func (st *IdStack) GetTop() int

func (*IdStack) InitIdStack

func (st *IdStack) InitIdStack()

func (*IdStack) IsStackEmpty

func (st *IdStack) IsStackEmpty() bool

func (*IdStack) IsStackFull

func (st *IdStack) IsStackFull() bool

func (*IdStack) Pop

func (st *IdStack) Pop() int

func (*IdStack) Push

func (st *IdStack) Push(value int) bool

func (*IdStack) SetTop

func (st *IdStack) SetTop(top int)

type InterfaceAddressGetter

type InterfaceAddressGetter interface {
	GetAddr(net.Interface) ([]net.Addr, error)
}

type IpamExecAddFunc

type IpamExecAddFunc func(plugin string, netconf []byte) (cniTypes.Result, error)

IpamExecAddFunc can be used to point to IPAM add function

type IpamExecDelFunc

type IpamExecDelFunc func(plugin string, netconf []byte) error

IpamExecDelFunc can be used to point to IPAM delete function

type OsVariableConfigurer

type OsVariableConfigurer struct{}

func NewOsVariableConfigurer

func NewOsVariableConfigurer() *OsVariableConfigurer

NewOsVariableConfigurer will return new variable configurer based on os package

type ServerParams

type ServerParams struct {
	KeepAlive bool
	ConnType  ConnType
	ConClient Service
}

type Service

type Service int
const (
	UnknownService Service = iota
	InfraAgent
	InfraManager
	Infrap4dGrpcServer
	Infrap4dGnmiServer
)

Jump to

Keyboard shortcuts

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