kube

package
v0.0.0-...-1e2aa48 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SepAt     = "@"
	SepHyphen = "-"
	SepColon  = ":"

	DefaultRemotePort = 6443
)
View Source
const (
	// DefaultHost is the host used to represent remote master locally
	DefaultHost = "kubernetes"
)
View Source
const (
	// DefaultKubeConfigPath is default kubeconfig path on remote host.
	DefaultKubeConfigPath = "~/.kube/config"
)

Variables

View Source
var (
	ErrRemoteInvalidUser = errors.New("cube: user in remote kubeconfig is invalid")
	ErrRemoteInvalidCert = errors.New("cube: cert in remote kubeconfig is invalid")
	ErrConfigInvalid     = errors.New("cube: remote kubeconfig must have only one cluster")
)
View Source
var (
	ErrEmptyNameSuffix      = errors.New("cube: empty name-suffix for merge")
	ErrConfigAlreadyMerged  = errors.New("cube: kubeconfig already merged")
	ErrClusterAlreadyExists = errors.New("cube: cluster already exists")
	ErrContextAlreadyExists = errors.New("cube: context already exists")
	ErrUserAlreadyExists    = errors.New("cube: user already exists")
	ErrInvalidLocalPort     = errors.New("cube: invalid local port for merge")
)
View Source
var (
	ErrClusterNotFound       = errors.New("cube: cluster not found for purging")
	ErrMultipleClustersFound = errors.New("cube: multiple clusters found for purging")
)

Functions

func FindContextsByName

func FindContextsByName(kc *clientcmdapi.Config, name string, filter func(string) bool) map[string]*clientcmdapi.Context

func GetOccupiedLocalPort

func GetOccupiedLocalPort(srv string) (host string, port int, err error)

func GetPortForwardingCmd

func GetPortForwardingCmd(localPort int, remoteAPIAddr string, via string) string

func Load

func Load(configPath string) (*clientcmdapi.Config, error)

Load reads kubeconfig from file

func LocalCachePath

func LocalCachePath(remoteAddr string) string

LocalCachePath returns cache path for remote kubectl config by convention. that's, `~/.config/cube/cache/$HOST`.

func Write

func Write(kc *clientcmdapi.Config) ([]byte, error)

func WriteToFile

func WriteToFile(kc *clientcmdapi.Config, configPath string) error

Types

type ClusterInfo

type ClusterInfo struct {
	Name       string `json:"name"`
	SSHForward string `json:"sshForward"`
}

func ParseContext

func ParseContext(kc *clientcmdapi.Config, ctxName string) (*ClusterInfo, error)

func (ClusterInfo) String

func (f ClusterInfo) String() string

type ClusterInfos

type ClusterInfos []ClusterInfo

func ListAllClusters

func ListAllClusters() (ClusterInfos, error)

func (ClusterInfos) Len

func (c ClusterInfos) Len() int

func (ClusterInfos) Less

func (c ClusterInfos) Less(i, j int) bool

func (ClusterInfos) String

func (c ClusterInfos) String() string

func (ClusterInfos) Swap

func (c ClusterInfos) Swap(i, j int)

type ClusterKeyInfo

type ClusterKeyInfo struct {
	Kc *clientcmdapi.Config // config where the cluster info belongs to

	ClusterName string
	Cluster     *clientcmdapi.Cluster
	IsHTTP      bool // whether the schema of cluster's server address is `HTTP`

	CtxName string
	Ctx     *clientcmdapi.Context

	User *clientcmdapi.AuthInfo
}

ClusterKeyInfo contains key info about a k8s cluster from given kubectl config.

type DownloadResult

type DownloadResult struct {
	ClusterName string               // matched cluster name
	Kc          *clientcmdapi.Config // remote kubectl config

}

DownloadResult represents the download status

type Downloader

type Downloader struct {
	// contains filtered or unexported fields
}

Downloader download kubernetes config for remote cluster. also download cert files if necessary.

func NewDownloader

func NewDownloader(remoteAddr string) *Downloader

NewDownloader create a new remote config downloader.

func (*Downloader) Download

func (d *Downloader) Download() (DownloadResult, error)

Download fetches config and cert files.

type MergeOptions

type MergeOptions struct {
	RemoteAddr string
	NameSuffix string
	LocalPort  int
	Force      bool
}

MergeOptions represents options for merge

type Merger

type Merger interface {
	Merge() error
	Result() *clientcmdapi.Config
	LocalPort() int
	RemoteAPIAddr() string
}

Merger merge remote cluster config into local `~/.kube/config`

func NewMerger

func NewMerger(opts MergeOptions) Merger

type PurgeOptions

type PurgeOptions struct {
	Name string
	All  bool
}

PurgeOptions represent options for purge.

type Purger

type Purger interface {
	Purge() error
	Result() *clientcmdapi.Config
	Deleted() []string
}

Purger deletes Kubernetes configs under given conditions

func NewPurger

func NewPurger(opts PurgeOptions) Purger

Jump to

Keyboard shortcuts

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