Documentation ¶
Index ¶
- Constants
- Variables
- func CheckCommandExist(cmd string) error
- func ConvertToCluster(state *ClusterState) types.Cluster
- func DisableExplorer(config string) error
- func EnableExplorer(ctx context.Context, config string) (int, error)
- func GetClusterPath(clusterName, providerName string) string
- func GetDB() (*gorm.DB, error)
- func GetDataSource() string
- func GetDefaultSSHKeyPath(clusterName, providerName string) string
- func GetDefaultSSHPublicKeyPath(clusterName, providerName string) string
- func GetLogFile(name string) (logFile *os.File, err error)
- func GetLogPath() string
- func InitExplorer()
- func InitStorage() error
- func NewLogger(debug bool, w *os.File) *logrus.Logger
- func StartKubeExplorer(ctx context.Context, config string, port int) error
- type Broadcaster
- type ClusterState
- type ConfigFileManager
- func (c *ConfigFileManager) ClearCfgByContext(context string) error
- func (c *ConfigFileManager) MergeCfg(context string, configAccess clientcmd.ConfigAccess) (*api.Config, error)
- func (c *ConfigFileManager) OverwriteCfg(path string, context string, ...) error
- func (c *ConfigFileManager) RemoveCfg(context string, configAccess clientcmd.ConfigAccess) (*api.Config, error)
- func (c *ConfigFileManager) SaveCfg(context, tempFile string) error
- type Credential
- type Explorer
- type LogEvent
- type Setting
- type Store
- func (d *Store) BroadcastObject(obj interface{})
- func (d *Store) CreateCredential(cred *Credential) error
- func (d *Store) CreateTemplate(template *Template) error
- func (d *Store) DeleteCluster(name, provider string) error
- func (d *Store) DeleteCredential(id int) error
- func (d *Store) DeleteExplorer(clusterID string) error
- func (d *Store) DeleteTemplate(name, provider string) error
- func (d *Store) Explorer(apiOp *apitypes.APIRequest, schema *apitypes.APISchema, ...)
- func (d *Store) FindCluster(name, provider string) ([]*ClusterState, error)
- func (d *Store) GetCluster(name, provider string) (*ClusterState, error)
- func (d *Store) GetClusterByID(contextName string) (*ClusterState, error)
- func (d *Store) GetCredential(id int) (*Credential, error)
- func (d *Store) GetCredentialByProvider(provider string) ([]*Credential, error)
- func (d *Store) GetExplorer(clusterID string) (*Explorer, error)
- func (d *Store) GetSetting(name string) (*Setting, error)
- func (d *Store) GetTemplate(name, provider string) (*Template, error)
- func (d *Store) ListCluster(provider string) ([]*ClusterState, error)
- func (d *Store) ListCredential() ([]*Credential, error)
- func (d *Store) ListExplorer() ([]*Explorer, error)
- func (d *Store) ListSettings() ([]*Setting, error)
- func (d *Store) ListTemplates() ([]*Template, error)
- func (d *Store) Log(apiOp *apitypes.APIRequest, input chan *LogEvent)
- func (d *Store) Register()
- func (d *Store) SaveCluster(cluster *types.Cluster) error
- func (d *Store) SaveClusterState(state *ClusterState) error
- func (d *Store) SaveExplorer(exp *Explorer) error
- func (d *Store) SaveSetting(s *Setting) error
- func (d *Store) UpdateCredential(cred *Credential) error
- func (d *Store) UpdateTemplate(template *Template) error
- func (d *Store) WatchCluster(apiOp *apitypes.APIRequest, schema *apitypes.APISchema, ...)
- func (d *Store) WatchTemplate(apiOp *apitypes.APIRequest, schema *apitypes.APISchema, ...)
- type Subscriber
- type Template
Constants ¶
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" )
const (
KubeExplorerCommand = "kube-explorer"
)
Variables ¶
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 ConvertToCluster ¶ added in v0.5.0
func ConvertToCluster(state *ClusterState) types.Cluster
func DisableExplorer ¶ added in v0.4.4
DisableExplorer will stop kube-explorer server for specified K3s cluster
func EnableExplorer ¶ added in v0.4.4
EnableExplorer will start kube-explorer with random port for specified K3s cluster
func GetClusterPath ¶ added in v0.3.0
GetClusterPath returns default cluster path.
func GetDataSource ¶ added in v0.4.0
func GetDataSource() string
GetDataSource return default database file path.
func GetDefaultSSHKeyPath ¶ added in v0.3.0
GetDefaultSSHKeyPath returns default ssh key path.
func GetDefaultSSHPublicKeyPath ¶ added in v0.4.1
GetDefaultSSHPublicKeyPath returns default public key path.
func GetLogFile ¶ added in v0.4.0
GetLogFile open and return log file.
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.
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) 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 Store ¶ added in v0.4.0
Store holds broadcaster's API state.
func NewClusterDB ¶ added in v0.4.0
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
CreateTemplate create template.
func (*Store) DeleteCluster ¶ added in v0.4.0
DeleteCluster delete cluster.
func (*Store) DeleteCredential ¶ added in v0.4.0
DeleteCredential delete credential by ID.
func (*Store) DeleteExplorer ¶ added in v0.4.4
DeleteExplorer remove explorer setting for specified cluster
func (*Store) DeleteTemplate ¶ added in v0.4.0
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
GetExplorer return explorer setting for specified cluster
func (*Store) GetSetting ¶ added in v0.5.0
GetSetting return specified setting by name
func (*Store) GetTemplate ¶ added in v0.4.0
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
ListExplorer return all kube-explorer settings
func (*Store) ListSettings ¶ added in v0.5.0
ListSettings list all settings
func (*Store) ListTemplates ¶ added in v0.4.0
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
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
SaveExplorer save cluster kube-explorer settings
func (*Store) SaveSetting ¶ added in v0.5.0
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
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 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.