Documentation ¶
Index ¶
- Constants
- Variables
- func Append(base string, inc string) string
- func ArrayDelete(arr []string, item string) []string
- func ArrayEquals(src, target []string) bool
- func BackgroundRun(cmdCtx *CMDContext) error
- func CanRun(cmd *exec.Cmd) bool
- func CleanRsaKeys()
- func Contains(obj interface{}, target interface{}) bool
- func CreateDirIfNotExist(dir string) error
- func ExtractErrorMessage(msg string) string
- func ExtractHostIp(url string) string
- func FindBrokenLocalPort(exposePorts string) string
- func FindInvalidRemotePort(exposePorts string, svcPorts map[int]string) string
- func FixFileOwner(path string)
- func GetAdminUserName() string
- func GetDaemonRunning(componentName string) int
- func GetLocalUserName() string
- func GetRandomTcpPort() (int, error)
- func GetTime() int64
- func GetTimestamp() string
- func IsCmd() bool
- func IsLinux() bool
- func IsProcessExist(pid int) bool
- func IsRunAsAdmin() bool
- func IsWindows() bool
- func MapContains(subset, fullset map[string]string) bool
- func MapEquals(src, target map[string]string) bool
- func MapPut(m map[string]string, k, v string) map[string]string
- func MergeMap(m1, m2 map[string]string) map[string]string
- func ParsePortMapping(exposePort string) (int, int, error)
- func ParseTimestamp(timestamp string) int64
- func PrivateKeyPath(name string) string
- func RandomPort() int
- func RandomSeconds(min, max int) time.Duration
- func RandomString(n int) string
- func RemoveColor(msg string) string
- func RunAndWait(cmd *exec.Cmd) (string, string, error)
- func String2Map(str string) map[string]string
- func WaitPortBeReady(waitTime, port int) bool
- func WritePidFile(componentName string, ch chan os.Signal) error
- func WritePrivateKey(privateKeyPath string, data []byte) error
- type CMDContext
- type InterpretableReader
- type SSHGenerator
Constants ¶
const ( // EnvKubeConfig environment variable for kube config file EnvKubeConfig = "KUBECONFIG" // KubernetesToolkit name of this tool KubernetesToolkit = "kt" // ComponentConnect connect command ComponentConnect = "connect" // ComponentExchange exchange command ComponentExchange = "exchange" // ComponentMesh mesh command ComponentMesh = "mesh" // ComponentPreview preview command ComponentPreview = "preview" // ConnectModeShuttle sshuttle mode ConnectModeShuttle = "sshuttle" // ConnectModeTun2Socks tun2socks mode ConnectModeTun2Socks = "tun2socks" // ExchangeModeScale scale mode ExchangeModeScale = "scale" // ExchangeModeEphemeral ephemeral mode ExchangeModeEphemeral = "ephemeral" // ExchangeModeSelector selector mode ExchangeModeSelector = "selector" // MeshModeAuto auto mode MeshModeAuto = "auto" // MeshModeManual manual mode MeshModeManual = "manual" // DnsModeLocalDns local dns mode DnsModeLocalDns = "localDNS" // DnsModePodDns pod dns mode DnsModePodDns = "podDNS" // DnsModeHosts hosts dns mode DnsModeHosts = "hosts" // ControlBy label used for mark shadow pod ControlBy = "control-by" // KtTarget label used for service selecting shadow or route pod KtTarget = "kt-target" // KtRole label used for auto mesh roles KtRole = "kt-role" // KtConfig annotation used for clean up context KtConfig = "kt-config" // KtUser annotation used for record independent username KtUser = "kt-user" // KtSelector annotation used for record service origin selector KtSelector = "kt-selector" // KtRefCount annotation used for count of shared pod / service KtRefCount = "kt-ref-count" // KtLastHeartBeat annotation used for timestamp of last heart beat KtLastHeartBeat = "kt-last-heart-beat" // KtLock annotation used for avoid auto mesh conflict KtLock = "kt-lock" // PostfixRsaKey postfix of local private key name PostfixRsaKey = "_id_rsa" // RouterBin path to router executable RouterBin = "/usr/sbin/router" // DumpHostsLock path to lock file for dump hosts DumpHostsLock = "hosts.lock" // SshBitSize ssh bit size SshBitSize = 2048 // SshAuthKey auth key name SshAuthKey = "authorized" // SshAuthPrivateKey ssh private key SshAuthPrivateKey = "privateKey" // DefaultNamespace default namespace DefaultNamespace = "default" // KtExchangeContainer name of exchange ephemeral container KtExchangeContainer = "kt-exchange" // DefaultContainer default container name DefaultContainer = "standalone" // StuntmanServiceSuffix suffix of stuntman service name StuntmanServiceSuffix = "-kt-stuntman" // RouterPodSuffix suffix of router pod name RouterPodSuffix = "-kt-router" // ExchangePodInfix exchange pod name ExchangePodInfix = "-kt-exchange-" // MeshPodInfix mesh pod and mesh service name MeshPodInfix = "-kt-mesh-" // RectifierPodPrefix rectifier pod name RectifierPodPrefix = "kt-rectifier-" // RoleConnectShadow shadow role RoleConnectShadow = "shadow-connect" // RoleExchangeShadow shadow role RoleExchangeShadow = "shadow-exchange" // RoleMeshShadow shadow role RoleMeshShadow = "shadow-mesh" // RolePreviewShadow shadow role RolePreviewShadow = "shadow-preview" // RoleRouter router role RoleRouter = "router" // TunNameWin tun device name in windows TunNameWin = "KtConnectTunnel" // TunNameLinux tun device name in linux TunNameLinux = "kt0" // TunNameMac tun device name in MacOS TunNameMac = "utun" // AlternativeDnsPort alternative port for local dns AlternativeDnsPort = 10053 )
const Eol = "\n"
const FieldDomain = "domain"
const FieldNameserver = "nameserver"
const FieldSearch = "search"
const HostsFilePath = "/etc/hosts"
const IpAddrPattern = "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"
const ResolvConf = "/etc/resolv.conf"
Variables ¶
var KtHome = fmt.Sprintf("%s/.ktctl", UserHome)
var TimeDifference int64 = 0
TimeDifference seconds between remote and local time
var UserHome = os.Getenv("HOME")
Functions ¶
func ArrayDelete ¶ added in v0.3.2
func ArrayEquals ¶ added in v0.3.2
func BackgroundRun ¶
func BackgroundRun(cmdCtx *CMDContext) error
BackgroundRun run cmd in background with context
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 ¶
CreateDirIfNotExist create dir
func ExtractErrorMessage ¶ added in v0.2.3
ExtractErrorMessage extract error from log
func ExtractHostIp ¶ added in v0.3.3
ExtractHostIp Get host ip address from url
func FindBrokenLocalPort ¶ added in v0.3.0
FindBrokenLocalPort Check if all ports has process listening to Return empty string if all ports are listened, otherwise return the first broken port
func FindInvalidRemotePort ¶ added in v0.3.0
FindInvalidRemotePort Check if all ports exist in provide service
func FixFileOwner ¶ added in v0.1.1
func FixFileOwner(path string)
FixFileOwner set owner to original user when run with sudo
func GetAdminUserName ¶ added in v0.3.0
func GetAdminUserName() string
func GetDaemonRunning ¶ added in v0.1.0
GetDaemonRunning fetch daemon pid if exist
func GetLocalUserName ¶ added in v0.2.0
func GetLocalUserName() string
GetLocalUserName get current username
func GetRandomTcpPort ¶ added in v0.3.1
GetRandomTcpPort get pod random ssh port
func IsProcessExist ¶ added in v0.1.0
IsProcessExist check whether specified process still running
func IsRunAsAdmin ¶ added in v0.3.0
func IsRunAsAdmin() bool
func MapContains ¶ added in v0.2.3
func ParsePortMapping ¶ added in v0.2.3
ParsePortMapping parse <port> or <localPort>:<removePort> parameter
func ParseTimestamp ¶ added in v0.3.0
ParseTimestamp parse timestamp to unix time
func RandomPort ¶ added in v0.2.3
func RandomPort() int
RandomPort Generate random number [1024, 65535)
func RandomSeconds ¶ added in v0.2.5
RandomSeconds Generate random duration number in second
func RemoveColor ¶ added in v0.2.3
RemoveColor remove shell color character in text
func RunAndWait ¶ added in v0.2.4
RunAndWait run cmd
func String2Map ¶ added in v0.0.12
String2Map Convert parameter string to real map "k1=v1,k2=v2" -> {"k1":"v1","k2","v2"}
func WaitPortBeReady ¶ added in v0.1.1
WaitPortBeReady return true when port is ready It waits at most waitTime seconds, then return false.
func WritePidFile ¶ added in v0.0.12
WritePidFile write pid to file
func WritePrivateKey ¶ added in v0.1.0
WritePrivateKey write ssh private key to privateKeyPath
Types ¶
type CMDContext ¶ added in v0.2.4
CMDContext context of cmd
type InterpretableReader ¶ added in v0.3.1
type InterpretableReader struct {
// contains filtered or unexported fields
}
func NewInterpretableReader ¶ added in v0.3.1
func NewInterpretableReader(r io.Reader) InterpretableReader
func (InterpretableReader) Cancel ¶ added in v0.3.1
func (r InterpretableReader) Cancel()
type SSHGenerator ¶ added in v0.1.0
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