util

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: MIT Imports: 71 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAllowFirewallRule added in v1.1.26

func AddAllowFirewallRule()

func AllContainerIsRunning added in v1.1.25

func AllContainerIsRunning(pod *v1.Pod) bool

func BytesToInt

func BytesToInt(b []byte) uint32

func CanI added in v1.1.20

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

func CleanExtensionLib added in v1.1.25

func CleanExtensionLib()

func Deduplicate added in v1.1.25

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

func DeleteAllowFirewallRule added in v1.1.26

func DeleteAllowFirewallRule()

func DeleteBlockFirewallRule added in v1.1.26

func DeleteBlockFirewallRule(_ context.Context)

func DoReq added in v1.1.21

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

func FindAllowFirewallRule added in v1.1.26

func FindAllowFirewallRule() bool

func GetAnnotation added in v1.1.18

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 added in v1.1.9

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 added in v1.1.9

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

GetCIDRFromResourceUgly use podIP/24 and serviceIP/16 as cidr

func GetEnv added in v1.1.27

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 added in v1.1.21

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 added in v1.1.26

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 added in v1.1.19

func IsIPv4(packet []byte) bool

func IsIPv6 added in v1.1.19

func IsIPv6(packet []byte) bool

func IsPortListening

func IsPortListening(port int) bool

func IsWindows

func IsWindows() bool

func Main added in v1.1.24

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

func Merge added in v1.1.32

func Merge[K comparable, V any](fromMap, ToMap map[K]V) map[K]V

func MoveToTemp added in v1.1.27

func MoveToTemp()

func Ping

func Ping(targetIP string) (bool, error)

func PortForwardPod

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

func Print added in v1.1.27

func Print(writer io.Writer, slogan string)

func PrintStatus added in v1.1.14

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

func PrintStatusInline added in v1.1.25

func PrintStatusInline(pod *corev1.Pod) string

func RolloutStatus

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

func Run added in v1.1.33

func Run(conf *SshConfig, cmd string, env []string) (output []byte, errOut []byte, err error)

func RunWithElevated

func RunWithElevated()

func RunWithRollingOutWithChecker

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

func RunningInContainer added in v1.2.0

func RunningInContainer() bool

RunningInContainer returns true if the current process runs from inside a docker container.

func SCP added in v1.1.30

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 added in v1.1.27

func StartupPProf(port int)

func WaitPod

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

func WaitPodToBeReady added in v1.1.27

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 added in v1.1.24

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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