util

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 56 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TrafficManager string = "kubevpn.traffic.manager"
	OriginData     string = "origin_data"
	REVERSE        string = "REVERSE"
	Connect        string = "Connect"
	MacToIP        string = "MAC_TO_IP"
	DHCP           string = "DHCP"
	Splitter       string = "#"
	EndSignOK      string = "EndSignOk"
	EndSignFailed  string = "EndSignFailed"
)

Variables

View Source
var (
	SPool = sync.Pool{
		New: func() interface{} {
			return make([]byte, smallBufferSize)
		},
	}
	MPool = sync.Pool{
		New: func() interface{} {
			return make([]byte, mediumBufferSize)
		},
	}
	LPool = sync.Pool{
		New: func() interface{} {
			return make([]byte, largeBufferSize)
		},
	}
)
View Source
var (
	// KeepAliveTime is the keep alive time period for TCP connection.
	KeepAliveTime = 180 * time.Second
	// DialTimeout is the timeout of dial.
	DialTimeout = 10 * time.Second
)
View Source
var Debug bool

Debug is a flag that enables the debug log.

View Source
var (
	//	network layer ip needs 20 bytes
	//	transport layer UDP header needs 8 bytes
	//	UDP over TCP header needs 22 bytes
	DefaultMTU = 1500 - 20 - 8 - 21
)
View Source
var IpMask net.IPMask
View Source
var IpRange net.IP
View Source
var RouterIP net.IPNet

Functions

func AddFirewallRule

func AddFirewallRule()

func BytesToInt

func BytesToInt(b []byte) uint32

func DeleteConfigMap

func DeleteConfigMap(clientset *kubernetes.Clientset, namespace, configMapName string)

func DeletePod

func DeletePod(clientset *kubernetes.Clientset, namespace, podName string) error

func DeleteWindowsFirewallRule

func DeleteWindowsFirewallRule()

DeleteWindowsFirewallRule Delete all action block firewall rule

func FindRule

func FindRule() bool

func GenerateKey

func GenerateKey(kubeconfigBytes []byte, namespace string) string

GenerateKey todo jetbrains rename will modify cluster name, it will make this function invalid

func GetAvailableUDPPortOrDie

func GetAvailableUDPPortOrDie() int

func GetClientSetByKubeconfigBytes

func GetClientSetByKubeconfigBytes(kubeconfigBytes []byte) (*kubernetes.Clientset, error)

func GetContextWithLogger

func GetContextWithLogger(writer io.WriteCloser) context.Context

func GetLoggerFromContext

func GetLoggerFromContext(ctx context.Context) *log.Logger

func GetMacAddress

func GetMacAddress() net.HardwareAddr

func GetOwnerReferences

func GetOwnerReferences(object k8sruntime.Object) *metav1.OwnerReference

func GetScale

func GetScale(object k8sruntime.Object) int

func GetTopControllerBaseOnPodLabel

func GetTopControllerBaseOnPodLabel(factory cmdutil.Factory, clientset coreV1.PodInterface, namespace string, selector labels.Selector) (info *runtimeresource.Info, err error)

func GetUnstructuredObject

func GetUnstructuredObject(f cmdutil.Factory, namespace string, workloads string) (*runtimeresource.Info, error)

func InitLogger

func InitLogger(debug bool)

func IsAdmin

func IsAdmin() bool

func IsContainerNotFoundError

func IsContainerNotFoundError(err error) bool

IsContainerNotFoundError checks whether the error is container not found error.

func IsPortListening

func IsPortListening(port int) bool

func IsSudoDaemonServing

func IsSudoDaemonServing() bool

func IsWindows

func IsWindows() bool

func MergeOrReplaceAnnotation

func MergeOrReplaceAnnotation(c rest.Interface, namespace, resource, name, k, v string) error

func NewLogger

func NewLogger(writer io.WriteCloser) *log.Logger

func Ping

func Ping(targetIP string) (bool, error)

func PortForwardPod

func PortForwardPod(
	config *rest.Config,
	clientset *rest.RESTClient,
	podName,
	namespace,
	portPair string,
	readyChan chan struct{},
	stopChan <-chan struct{},
) error

func RunWithElevated

func RunWithElevated() error

func Shell

func Shell(clientset *kubernetes.Clientset, restclient *rest.RESTClient, config *rest.Config, podName, containerName, namespace, cmd string) (string, error)

func ShellWithStream

func ShellWithStream(clientset *kubernetes.Clientset, restclient *rest.RESTClient, config *rest.Config, podName, namespace, cmd string, writer io.Writer) error

func UpdateReplicasScale

func UpdateReplicasScale(clientset *kubernetes.Clientset, namespace string, controller ResourceTupleWithScale) error

func WaitPortToBeFree

func WaitPortToBeFree(port int, timeout time.Duration) error

Types

type Format

type Format struct {
	log.Formatter
}

func (*Format) Format

func (*Format) Format(e *log.Entry) ([]byte, error)
2009/01/23 01:23:23 d.go:23: message

same like log.SetFlags(log.LstdFlags | log.Lshortfile)

type ForwardedPort

type ForwardedPort struct {
	Local  uint16
	Remote uint16
}

ForwardedPort contains a Local:Remote port pairing.

type PatchOperation

type PatchOperation struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value,omitempty"`
}

type PortForwarder

type PortForwarder struct {
	Ready chan struct{}
	// contains filtered or unexported fields
}

PortForwarder knows how to listen for local connections and forward them to a remote pod via an upgraded HTTP request.

func New

func New(dialer httpstream.Dialer, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error)

New creates a new PortForwarder with localhost listen addresses.

func NewOnAddresses

func NewOnAddresses(dialer httpstream.Dialer, addresses []string, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error)

NewOnAddresses creates a new PortForwarder with custom listen addresses.

func (*PortForwarder) Close

func (pf *PortForwarder) Close()

Close stops all listeners of PortForwarder.

func (*PortForwarder) ForwardPorts

func (pf *PortForwarder) ForwardPorts() error

ForwardPorts formats and executes a port forwarding request. The connection will remain open until stopChan is closed.

func (*PortForwarder) GetPorts

func (pf *PortForwarder) GetPorts() ([]ForwardedPort, error)

GetPorts will return the ports that were forwarded; this can be used to retrieve the locally-bound port in cases where the input was port 0. This function will signal an error if the Ready channel is nil or if the listeners are not ready yet; this function will succeed after the Ready channel has been closed.

type ResourceTuple

type ResourceTuple struct {
	Resource string
	Name     string
}

func SplitResourceTypeName

func SplitResourceTypeName(s string) (ResourceTuple, bool, error)

splitResourceTypeName handles type/name resource formats and returns a resource tuple (empty or not), whether it successfully found one, and an error

func (ResourceTuple) String

func (r ResourceTuple) String() string

type ResourceTupleWithScale

type ResourceTupleWithScale struct {
	Resource string
	Name     string
	Scale    int
}

Jump to

Keyboard shortcuts

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