common

package
v0.5.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// KubeCfgFile default kube config file path.
	KubeCfgFile = ".kube/config"
	// KubeCfgTempName default temp kube config file name prefix.
	KubeCfgTempName = "autok3s-temp-*"
	// K3sManifestsDir k3s manifests dir.
	K3sManifestsDir = "/var/lib/rancher/k3s/server/manifests"
	// MasterInstanceName master instance name.
	MasterInstanceName = "autok3s.%s.master"
	// WorkerInstanceName worker instance name.
	WorkerInstanceName = "autok3s.%s.worker"
	// TagClusterPrefix cluster's tag prefix.
	TagClusterPrefix = "autok3s-"
	// StatusRunning instance running status.
	StatusRunning = "Running"
	// StatusCreating instance creating status.
	StatusCreating = "Creating"
	// StatusMissing instance missing status.
	StatusMissing = "Missing"
	// StatusFailed instance failed status.
	StatusFailed = "Failed"
	// StatusUpgrading instance upgrading status.
	StatusUpgrading = "Upgrading"
	// StatusRemoving instance removing status.
	StatusRemoving = "Removing"
	// UsageInfoTitle usage info title.
	UsageInfoTitle = "=========================== Prompt Info ==========================="
	// UsageContext usage info context.
	UsageContext = "Use 'autok3s kubectl config use-context %s'"
	// UsagePods usage  info pods.
	UsagePods = "Use 'autok3s kubectl get pods -A' get POD status`"
	// DBFolder default database dir.
	DBFolder = ".db"
	// DBFile default database file.
	DBFile = "autok3s.db"
)
View Source
const (
	KubeExplorerCommand = "kube-explorer"
)

Variables

View Source
var (
	// Debug used to enable log debug level.
	Debug = false
	// CfgPath default config file dir.
	CfgPath = filepath.Join(utils.UserHome(), ".autok3s")
	// Backoff default backoff variable, retry 20 times, total 570 seconds.
	Backoff = wait.Backoff{
		Duration: 30 * time.Second,
		Factor:   1,
		Steps:    20,
	}
	// DefaultDB default database store.
	DefaultDB        *Store
	ExplorerWatchers map[string]context.CancelFunc

	FileManager *ConfigFileManager
)

Functions

func CheckCommandExist added in v0.4.4

func CheckCommandExist(cmd string) error

func ConvertToCluster added in v0.5.0

func ConvertToCluster(state *ClusterState) types.Cluster

func DisableExplorer added in v0.4.4

func DisableExplorer(config string) error

DisableExplorer will stop kube-explorer server for specified K3s cluster

func EnableExplorer added in v0.4.4

func EnableExplorer(ctx context.Context, config string) (int, error)

EnableExplorer will start kube-explorer with random port for specified K3s cluster

func GetClusterPath added in v0.3.0

func GetClusterPath(clusterName, providerName string) string

GetClusterPath returns default cluster path.

func GetDB added in v0.4.0

func GetDB() (*gorm.DB, error)

GetDB open and returns database.

func GetDataSource added in v0.4.0

func GetDataSource() string

GetDataSource return default database file path.

func GetDefaultSSHKeyPath added in v0.3.0

func GetDefaultSSHKeyPath(clusterName, providerName string) string

GetDefaultSSHKeyPath returns default ssh key path.

func GetDefaultSSHPublicKeyPath added in v0.4.1

func GetDefaultSSHPublicKeyPath(clusterName, providerName string) string

GetDefaultSSHPublicKeyPath returns default public key path.

func GetLogFile added in v0.4.0

func GetLogFile(name string) (logFile *os.File, err error)

GetLogFile open and return log file.

func GetLogPath added in v0.4.0

func GetLogPath() string

GetLogPath returns log path.

func InitExplorer added in v0.4.4

func InitExplorer()

InitExplorer will start kube-explorer server for all K3s clusters which enabled explorer setting

func InitStorage added in v0.4.0

func InitStorage() error

InitStorage initializes database storage.

func NewLogger

func NewLogger(debug bool, w *os.File) *logrus.Logger

NewLogger returns new logger struct.

func StartKubeExplorer added in v0.4.4

func StartKubeExplorer(ctx context.Context, config string, port int) error

StartKubeExplorer start kube-explorer server listen on specified port

Types

type Broadcaster added in v0.4.0

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

Broadcaster sends events to multiple subscribers.

func NewBroadcaster added in v0.4.0

func NewBroadcaster() *Broadcaster

NewBroadcaster returns new broadcaster struct.

func (*Broadcaster) Broadcast added in v0.4.0

func (b *Broadcaster) Broadcast(v interface{})

Broadcast events to each subscriber.

func (*Broadcaster) Close added in v0.4.0

func (b *Broadcaster) Close()

Close all subscribers.

func (*Broadcaster) Evict added in v0.4.0

func (b *Broadcaster) Evict(s Subscriber)

Evict specified subscriber.

func (*Broadcaster) Register added in v0.4.0

func (b *Broadcaster) Register(sf subscriberFunc) Subscriber

Register helps init subscriber with specified subscribe function.

type ClusterState added in v0.4.0

type ClusterState struct {
	types.Metadata `json:",inline" mapstructure:",squash" gorm:"embedded"`
	Options        []byte `json:"options,omitempty" gorm:"type:bytes"`
	Status         string `json:"status" yaml:"status"`
	Standalone     bool   `json:"standalone" yaml:"standalone" gorm:"type:bool"`
	MasterNodes    []byte `json:"master-nodes,omitempty" gorm:"type:bytes"`
	WorkerNodes    []byte `json:"worker-nodes,omitempty" gorm:"type:bytes"`
	types.SSH      `json:",inline" mapstructure:",squash" gorm:"embedded"`
}

ClusterState cluster state struct.

type ConfigFileManager added in v0.4.2

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

ConfigFileManager struct for config file manager.

func (*ConfigFileManager) ClearCfgByContext added in v0.4.7

func (c *ConfigFileManager) ClearCfgByContext(context string) error

ClearCfgByContext clear kube config by specified context.

func (*ConfigFileManager) MergeCfg added in v0.4.2

func (c *ConfigFileManager) MergeCfg(context string, configAccess clientcmd.ConfigAccess) (*api.Config, error)

MergeCfg merges kubectl config file.

func (*ConfigFileManager) OverwriteCfg added in v0.4.2

func (c *ConfigFileManager) OverwriteCfg(path string, context string, cfg func(string, clientcmd.ConfigAccess) (*api.Config, error)) error

OverwriteCfg overwrites kubectl config file.

func (*ConfigFileManager) RemoveCfg added in v0.4.2

func (c *ConfigFileManager) RemoveCfg(context string, configAccess clientcmd.ConfigAccess) (*api.Config, error)

RemoveCfg removes kubectl config file.

func (*ConfigFileManager) SaveCfg added in v0.4.7

func (c *ConfigFileManager) SaveCfg(context, tempFile string) error

SaveCfg save kube config file.

type Credential added in v0.4.0

type Credential struct {
	ID       int    `json:"id" gorm:"type:integer"`
	Provider string `json:"provider"`
	Secrets  []byte `json:"secrets,omitempty" gorm:"type:bytes"`
}

Credential credential struct.

type Explorer added in v0.4.4

type Explorer struct {
	ContextName string `json:"context-name"`
	Enabled     bool   `json:"enabled"`
	Port        int    `json:"port"`
}

Explorer struct

type LogEvent added in v0.4.3

type LogEvent struct {
	Name        string
	ContextName string
}

LogEvent log event struct.

type Setting added in v0.5.0

type Setting struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Setting struct

type Store added in v0.4.0

type Store struct {
	*gorm.DB
	// contains filtered or unexported fields
}

Store holds broadcaster's API state.

func NewClusterDB added in v0.4.0

func NewClusterDB(ctx context.Context) (*Store, error)

NewClusterDB new cluster store.

func (*Store) BroadcastObject added in v0.4.3

func (d *Store) BroadcastObject(obj interface{})

BroadcastObject broadcast object.

func (*Store) CreateCredential added in v0.4.0

func (d *Store) CreateCredential(cred *Credential) error

CreateCredential create credential.

func (*Store) CreateTemplate added in v0.4.0

func (d *Store) CreateTemplate(template *Template) error

CreateTemplate create template.

func (*Store) DeleteCluster added in v0.4.0

func (d *Store) DeleteCluster(name, provider string) error

DeleteCluster delete cluster.

func (*Store) DeleteCredential added in v0.4.0

func (d *Store) DeleteCredential(id int) error

DeleteCredential delete credential by ID.

func (*Store) DeleteExplorer added in v0.4.4

func (d *Store) DeleteExplorer(clusterID string) error

DeleteExplorer remove explorer setting for specified cluster

func (*Store) DeleteTemplate added in v0.4.0

func (d *Store) DeleteTemplate(name, provider string) error

DeleteTemplate delete template.

func (*Store) Explorer added in v0.4.4

func (d *Store) Explorer(apiOp *apitypes.APIRequest, schema *apitypes.APISchema, input chan apitypes.APIEvent)

Explorer watch K3s cluster setting changes for kube-explorer

func (*Store) FindCluster added in v0.4.0

func (d *Store) FindCluster(name, provider string) ([]*ClusterState, error)

FindCluster find cluster.

func (*Store) GetCluster added in v0.4.0

func (d *Store) GetCluster(name, provider string) (*ClusterState, error)

GetCluster get cluster.

func (*Store) GetClusterByID added in v0.4.0

func (d *Store) GetClusterByID(contextName string) (*ClusterState, error)

GetClusterByID get cluster by ID.

func (*Store) GetCredential added in v0.4.0

func (d *Store) GetCredential(id int) (*Credential, error)

GetCredential get credential by ID.

func (*Store) GetCredentialByProvider added in v0.4.0

func (d *Store) GetCredentialByProvider(provider string) ([]*Credential, error)

GetCredentialByProvider get credential by provider.

func (*Store) GetExplorer added in v0.4.4

func (d *Store) GetExplorer(clusterID string) (*Explorer, error)

GetExplorer return explorer setting for specified cluster

func (*Store) GetSetting added in v0.5.0

func (d *Store) GetSetting(name string) (*Setting, error)

GetSetting return specified setting by name

func (*Store) GetTemplate added in v0.4.0

func (d *Store) GetTemplate(name, provider string) (*Template, error)

GetTemplate get template.

func (*Store) ListCluster added in v0.4.0

func (d *Store) ListCluster(provider string) ([]*ClusterState, error)

ListCluster list cluster.

func (*Store) ListCredential added in v0.4.0

func (d *Store) ListCredential() ([]*Credential, error)

ListCredential list credential.

func (*Store) ListExplorer added in v0.4.4

func (d *Store) ListExplorer() ([]*Explorer, error)

ListExplorer return all kube-explorer settings

func (*Store) ListSettings added in v0.5.0

func (d *Store) ListSettings() ([]*Setting, error)

ListSettings list all settings

func (*Store) ListTemplates added in v0.4.0

func (d *Store) ListTemplates() ([]*Template, error)

ListTemplates list template.

func (*Store) Log added in v0.4.0

func (d *Store) Log(apiOp *apitypes.APIRequest, input chan *LogEvent)

Log subscribe log.

func (*Store) Register added in v0.4.0

func (d *Store) Register()

Register register gorm create/update hook.

func (*Store) SaveCluster added in v0.4.0

func (d *Store) SaveCluster(cluster *types.Cluster) error

SaveCluster save cluster.

func (*Store) SaveClusterState added in v0.4.0

func (d *Store) SaveClusterState(state *ClusterState) error

SaveClusterState save cluster state.

func (*Store) SaveExplorer added in v0.4.4

func (d *Store) SaveExplorer(exp *Explorer) error

SaveExplorer save cluster kube-explorer settings

func (*Store) SaveSetting added in v0.5.0

func (d *Store) SaveSetting(s *Setting) error

SaveSetting save settings

func (*Store) UpdateCredential added in v0.4.0

func (d *Store) UpdateCredential(cred *Credential) error

UpdateCredential update credential.

func (*Store) UpdateTemplate added in v0.4.0

func (d *Store) UpdateTemplate(template *Template) error

UpdateTemplate update template.

func (*Store) WatchCluster added in v0.4.0

func (d *Store) WatchCluster(apiOp *apitypes.APIRequest, schema *apitypes.APISchema, input chan apitypes.APIEvent)

WatchCluster watch cluster.

func (*Store) WatchTemplate added in v0.4.0

func (d *Store) WatchTemplate(apiOp *apitypes.APIRequest, schema *apitypes.APISchema, input chan apitypes.APIEvent)

WatchTemplate watch template.

type Subscriber added in v0.4.0

type Subscriber chan interface{}

Subscriber interface chan.

type Template added in v0.4.0

type Template struct {
	types.Metadata `json:",inline" mapstructure:",squash" gorm:"embedded"`
	Options        []byte `json:"options,omitempty" gorm:"type:bytes"`
	types.SSH      `json:",inline" mapstructure:",squash" gorm:"embedded"`
	IsDefault      bool `json:"is-default" gorm:"type:bool"`
}

Template template struct.

Jump to

Keyboard shortcuts

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