util

package
v1.1.30 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: MIT Imports: 71 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAllowFirewallRule

func AddAllowFirewallRule()

func AllContainerIsRunning

func AllContainerIsRunning(pod *v1.Pod) bool

func BytesToInt

func BytesToInt(b []byte) uint32

func CanI

func CanI(clientset *kubernetes.Clientset, sa, ns string, resource *rbacv1.PolicyRule) (allowed bool, err error)

func CleanExtensionLib

func CleanExtensionLib()

func Deduplicate

func Deduplicate(cidr []*net.IPNet) (result []*net.IPNet)

func DeleteAllowFirewallRule

func DeleteAllowFirewallRule()

func DeleteBlockFirewallRule

func DeleteBlockFirewallRule(_ context.Context)

func DoReq

func DoReq(request *http.Request) (body []byte, err error)

func FindAllowFirewallRule

func FindAllowFirewallRule() bool

func GetAnnotation

func GetAnnotation(f util.Factory, ns string, resources string) (map[string]string, error)

func GetAvailableTCPPortOrDie

func GetAvailableTCPPortOrDie() int

func GetAvailableUDPPortOrDie

func GetAvailableUDPPortOrDie() int

func GetCIDRElegant

func GetCIDRElegant(clientset *kubernetes.Clientset, restclient *rest.RESTClient, restconfig *rest.Config, namespace string) (result []*net.IPNet, err1 error)

GetCIDRElegant 1) dump cluster info 2) grep cmdline 3) create svc + cat *.conflist 4) create svc + get pod ip with svc mask

func GetCIDRFromResourceUgly

func GetCIDRFromResourceUgly(clientset *kubernetes.Clientset, namespace string) ([]*net.IPNet, error)

GetCIDRFromResourceUgly use podIP/24 and serviceIP/16 as cidr

func GetEnv

func GetEnv(ctx context.Context, f util.Factory, ns, pod string) (map[string][]string, error)

func GetPodTemplateSpecPath

func GetPodTemplateSpecPath(u *unstructured.Unstructured) (*v1.PodTemplateSpec, []string, error)

func GetTlsDomain

func GetTlsDomain(namespace string) string

func GetTopOwnerReference

func GetTopOwnerReference(factory cmdutil.Factory, namespace, workload string) (*runtimeresource.Info, error)

func GetTopOwnerReferenceBySelector

func GetTopOwnerReferenceBySelector(factory cmdutil.Factory, namespace, selector string) (sets.Set[string], error)

GetTopOwnerReferenceBySelector assume pods, controller has same labels

func GetUnstructuredObject

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

func GetUnstructuredObjectBySelector

func GetUnstructuredObjectBySelector(f cmdutil.Factory, namespace string, selector string) ([]*runtimeresource.Info, error)

func GetUnstructuredObjectList

func GetUnstructuredObjectList(f cmdutil.Factory, namespace string, workloads []string) ([]*runtimeresource.Info, error)

func Heartbeats

func Heartbeats()

func InitLogger

func InitLogger(debug bool)

func IsAdmin

func IsAdmin() bool

func IsIPv4

func IsIPv4(packet []byte) bool

func IsIPv6

func IsIPv6(packet []byte) bool

func IsPortListening

func IsPortListening(port int) bool

func IsWindows

func IsWindows() bool

func Main

func Main(remoteEndpoint, localEndpoint *netip.AddrPort, conf *SshConfig, done chan struct{}) error

func MoveToTemp

func MoveToTemp()

func Ping

func Ping(targetIP string) (bool, error)

func PortForwardPod

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

func Print

func Print(writer io.Writer, slogan string)

func PrintStatus

func PrintStatus(pod *corev1.Pod, writer io.Writer)

func PrintStatusInline

func PrintStatusInline(pod *corev1.Pod) string

func RolloutStatus

func RolloutStatus(ctx1 context.Context, factory cmdutil.Factory, namespace, workloads string, timeout time.Duration) error

func RunWithElevated

func RunWithElevated()

func RunWithRollingOutWithChecker

func RunWithRollingOutWithChecker(cmd *osexec.Cmd, checker func(log string)) (string, string, error)

func SCP

func SCP(conf *SshConfig, filename string, commands ...string) error

SCP copy file to remote and exec command

func Shell

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

func StartupPProf

func StartupPProf(port int)

func WaitPod

func WaitPod(podInterface v12.PodInterface, list metav1.ListOptions, checker func(*v1.Pod) bool) error

func WaitPodToBeReady

func WaitPodToBeReady(ctx context.Context, podInterface v12.PodInterface, selector metav1.LabelSelector) error

func WaitPortToBeFree

func WaitPortToBeFree(ctx context.Context, port int) 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 PodRouteConfig

type PodRouteConfig struct {
	LocalTunIPv4 string
	LocalTunIPv6 string
}

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 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 SshConfig

type SshConfig struct {
	Addr        string
	User        string
	Password    string
	Keyfile     string
	ConfigAlias string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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