util

package
v0.3.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: GPL-3.0 Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ResolvConf      = "/etc/resolv.conf"
	FieldNameserver = "nameserver"
	FieldDomain     = "domain"
	FieldSearch     = "search"
)
View Source
const ResourceHeartBeatIntervalMinus = 5

Variables

View Source
var KtHome = fmt.Sprintf("%s/.ktctl", UserHome)
View Source
var UserHome = os.Getenv("HOME")

Functions

func Append added in v0.2.0

func Append(base string, inc string) string

Append Add segment to a comma separated string

func BackgroundRun

func BackgroundRun(cmdCtx *CMDContext) error

BackgroundRun run cmd in background with context

func CanRun added in v0.2.4

func CanRun(cmd *exec.Cmd) bool

CanRun check whether a command can execute successful

func CleanRsaKeys added in v0.1.0

func CleanRsaKeys()

CleanRsaKeys ...

func Contains added in v0.1.0

func Contains(obj interface{}, target interface{}) bool

Contains check whether obj exist in target, the type of target can be an array, slice or map

func CreateDirIfNotExist

func CreateDirIfNotExist(dir string)

CreateDirIfNotExist create dir

func DropHosts added in v0.0.12

func DropHosts()

DropHosts ...

func DumpHosts added in v0.0.12

func DumpHosts(hostsMap map[string]string) bool

DumpHosts DumpToHosts

func ExtractErrorMessage added in v0.2.3

func ExtractErrorMessage(msg string) string

ExtractErrorMessage extract error from log

func ExtractNetMaskFromCidr added in v0.1.0

func ExtractNetMaskFromCidr(cidr string) string

ExtractNetMaskFromCidr extract net mask length (e.g. 16) from cidr (e.g. 1.2.3.4/16)

func FindBrokenPort added in v0.2.2

func FindBrokenPort(exposePorts string) string

FindBrokenPort Check if all ports has process listening to Return empty string if all ports are listened, otherwise return the first broken port

func FixFileOwner added in v0.1.1

func FixFileOwner(path string)

FixFileOwner set owner to original user when run with sudo

func GetDaemonRunning added in v0.1.0

func GetDaemonRunning(componentName string) int

GetDaemonRunning fetch daemon pid if exist

func GetLocalDomains added in v0.1.2

func GetLocalDomains() string

func GetLocalUserName added in v0.2.0

func GetLocalUserName() string

GetLocalUserName get current username

func GetOutboundIP

func GetOutboundIP() (address string)

GetOutboundIP Get preferred outbound ip of this machine

func GetRandomSSHPort

func GetRandomSSHPort() int

GetRandomSSHPort get pod random ssh port

func GetTimestamp added in v0.1.1

func GetTimestamp() string

GetTimestamp get current time stamp

func IsCmd added in v0.1.1

func IsCmd() bool

IsCmd check running in windows cmd shell

func IsLinux added in v0.1.0

func IsLinux() bool

IsLinux check runtime is windows

func IsPidFileExist added in v0.1.0

func IsPidFileExist() bool

IsPidFileExist check pid file is exist or not

func IsProcessExist added in v0.1.0

func IsProcessExist(pid int) bool

IsProcessExist check whether specified process still running

func IsWindows added in v0.0.12

func IsWindows() bool

IsWindows check runtime is windows

func KubeConfig added in v0.1.0

func KubeConfig() string

KubeConfig location of kube-config file

func MapContains added in v0.2.3

func MapContains(subset, fullset map[string]string) bool

func MapEquals added in v0.2.5

func MapEquals(src, target map[string]string) bool

func MapPut added in v0.2.3

func MapPut(m map[string]string, k, v string)

func MergeMap added in v0.2.4

func MergeMap(m1 map[string]string, m2 map[string]string) map[string]string

func ParsePortMapping added in v0.2.3

func ParsePortMapping(exposePort string) (int, int, error)

ParsePortMapping parse <port> or <localPort>:<removePort> parameter

func PrivateKeyPath added in v0.0.12

func PrivateKeyPath(name string) string

PrivateKeyPath ...

func RandomPort added in v0.2.3

func RandomPort() int

RandomPort Generate random number [1024, 65535)

func RandomSeconds added in v0.2.5

func RandomSeconds(min, max int) time.Duration

RandomSeconds Generate random duration number in second

func RandomString

func RandomString(n int) string

RandomString Generate random string

func RemoveColor added in v0.2.3

func RemoveColor(msg string) string

RemoveColor remove shell color character in text

func RunAndWait added in v0.2.4

func RunAndWait(cmd *exec.Cmd, isDebug bool) error

RunAndWait run cmd

func SetupConfigMapHeartBeat added in v0.1.2

func SetupConfigMapHeartBeat(ctx context.Context, client coreV1.ConfigMapInterface, name string)

SetupConfigMapHeartBeat setup heartbeat watcher for config map

func SetupPodHeartBeat added in v0.2.0

func SetupPodHeartBeat(ctx context.Context, client coreV1.PodInterface, name string)

SetupPodHeartBeat setup heartbeat watcher for deployment

func SetupPortForwardHeartBeat added in v0.1.2

func SetupPortForwardHeartBeat(port int)

SetupPortForwardHeartBeat setup heartbeat watcher for port forward

func SetupServiceHeartBeat added in v0.1.2

func SetupServiceHeartBeat(ctx context.Context, client coreV1.ServiceInterface, name string)

SetupServiceHeartBeat setup heartbeat watcher for service

func String2Map added in v0.0.12

func String2Map(str string) map[string]string

String2Map Convert parameter string to real map "k1=v1,k2=v2" -> {"k1":"v1","k2","v2"}

func WaitPortBeReady added in v0.1.1

func WaitPortBeReady(waitTime, port int) bool

WaitPortBeReady return true when port is ready It waits at most waitTime seconds, then return false.

func WritePidFile added in v0.0.12

func WritePidFile(componentName string) error

WritePidFile write pid to file

func WritePrivateKey added in v0.1.0

func WritePrivateKey(privateKeyPath string, data []byte) error

WritePrivateKey write ssh private key to privateKeyPath

Types

type CMDContext added in v0.2.4

type CMDContext struct {
	Ctx     context.Context
	Cmd     *exec.Cmd
	Name    string
	IsDebug bool
	Stop    chan struct{} // notify parent current Cmd occur error
}

CMDContext context of cmd

type SSHCredential added in v0.1.0

type SSHCredential struct {
	RemoteHost     string
	Port           string
	PrivateKeyPath string
}

SSHCredential ssh info

func NewDefaultSSHCredential added in v0.1.0

func NewDefaultSSHCredential() *SSHCredential

NewDefaultSSHCredential ...

type SSHGenerator added in v0.1.0

type SSHGenerator struct {
	PrivateKey, PublicKey []byte
	PrivateKeyPath        string
}

SSHGenerator ssh key pair generator

func Generate added in v0.1.0

func Generate(privateKeyPath string) (*SSHGenerator, error)

Generate generate SSHGenerator

func NewSSHGenerator added in v0.1.0

func NewSSHGenerator(privateKey string, publicKey string, privateKeyPath string) *SSHGenerator

NewSSHGenerator create ssh generator

Jump to

Keyboard shortcuts

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