client

package
v0.0.0-...-9c8d8c7 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAnsibleVar = Vars{
	SkipVerifyNode:        false,
	KubeVersion:           "1.16.9",
	LbMode:                "openresty",
	LbKubeApiserverPort:   8443,
	KubePodSubnet:         "10.244.0.0/18",
	KubeServiceSubnet:     "10.244.64.0/18",
	KubeNetworkNodePrefix: 24,
	KubeMaxPods:           110,
	NetworkPlugin:         "calico",
	KubeletRootDir:        "/var/lib/kubelet",
	DockerStorageDir:      "/var/lib/docker",
	EtcdDataDir:           "/var/lib/etcd",
}

Functions

func ExecuteCommand

func ExecuteCommand()

func ExecuteDomainCheck

func ExecuteDomainCheck()

func ExecuteRequest

func ExecuteRequest()

func ExecuteSql

func ExecuteSql()

func GetConfig

func GetConfig() (*rest.Config, error)

func GetKubeClient

func GetKubeClient(kubeconfig string) (kubeClient *kubernetes.Clientset, err error)

创建 kubernetes 的客户端

func GetKubeInterface

func GetKubeInterface() *kubeInterface

GetKubeInterface 单例模式初始化客户端

func GetPublicIP

func GetPublicIP() string

func InitC7nLogs

func InitC7nLogs(client *kubernetes.Clientset, namespace string)

func InitConfiguration

func InitConfiguration(kubeconfig, namespace string) *action.Configuration

func InstallC7nTools

func InstallC7nTools(namespace string)

func RunHelmInstall

func RunHelmInstall(client *action.Install, chart string, vals map[string]interface{}, out io.Writer) (*release.Release, error)

Types

type BackendTask

type BackendTask struct {
	Name    string
	Success bool
}

type C7nLogs

type C7nLogs struct {
	Name string

	// 避免 yaml.Unmarshal 无法取地址
	Tasks map[string]*[]TaskInfo
	// contains filtered or unexported fields
}

type ChartArgs

type ChartArgs struct {
	RepoUrl     string
	Version     string
	Namespace   string
	ReleaseName string
	Verify      bool
	Keyring     string
	CertFile    string
	KeyFile     string
	CaFile      string
	ChartName   string
}

type ChartValue

type ChartValue struct {
	Name  string
	Value string
	Input utils.Input
	Case  string
	Check string
}

type Children

type Children struct {
	Lb         Hostname `yaml:"lb"`
	Etcd       Hostname `yaml:"etcd"`
	KubeMaster Hostname `yaml:"kube-master"`
	KubeWorker Hostname `yaml:"kube-worker"`
	NewMaster  Hostname `yaml:"new-master"`
	NewWorker  Hostname `yaml:"new-worker"`
	NewEtcd    Hostname `yaml:"new-etcd"`
}

type Cli

type Cli struct {
	IP       string //IP地址
	Username string //用户名
	Password string //密码
	Port     int    //端口号

	LastResult string //最近一次Run的结果
	// contains filtered or unexported fields
}

func NewSSHClient

func NewSSHClient(ip string, username string, password string, port ...int) *Cli

创建命令行对象 @param ip IP地址 @param username 用户名 @param password 密码 @param port 端口号,默认22

func (Cli) Run

func (c Cli) Run(shell string) (string, error)

执行shell @param shell shell脚本命令

type Group

type Group struct {
	Hosts    map[string]Host `yaml:"hosts,omitempty"`
	Vars     Vars            `yaml:"vars,omitempty"`
	Children Children        `yaml:"children,omitempty"`
}

type Helm3Client

type Helm3Client struct {
	*action.Configuration
}

helmClient 使用单例模式,

func NewHelm3Client

func NewHelm3Client(cfg *action.Configuration) *Helm3Client

func (*Helm3Client) Install

func (h *Helm3Client) Install(cArgs ChartArgs, vals map[string]interface{}, out io.Writer) (*release.Release, error)

func (*Helm3Client) Template

func (h *Helm3Client) Template(chartFile string, out io.Writer) (string, error)

func (*Helm3Client) Upgrade

func (h *Helm3Client) Upgrade(cArgs ChartArgs, vals map[string]interface{}, out io.Writer) (*release.Release, error)

type Host

type Host struct {
	AnsibleHost     string `yaml:"ansible_host,omitempty"`
	AnsiblePort     int    `yaml:"ansible_port,omitempty"`
	AnsibleUser     string `yaml:"ansible_user,omitempty"`
	AnsiblePassword string `yaml:"ansible_ssh_pass,omitempty"`
}

type Hostname

type Hostname struct {
	Hosts map[string]interface{} `yaml:"hosts"`
}

type Interface

type Interface interface {
	GetConfig() *config.C7nConfig

	GetHelmClient() *Helm3Client
}

Interface represents a client capable of

type Inventory

type Inventory struct {
	All Group `yaml:"all"`
}

func (*Inventory) AddHosts

func (i *Inventory) AddHosts(IPs []string)

func (*Inventory) AddNewEtcd

func (i *Inventory) AddNewEtcd(ip string)

func (*Inventory) AddNewMasters

func (i *Inventory) AddNewMasters(IPs []string)

func (*Inventory) AddNewWorkers

func (i *Inventory) AddNewWorkers(IPs []string)

func (*Inventory) GetHosts

func (i *Inventory) GetHosts() []string

func (*Inventory) GetKubeMaster

func (i *Inventory) GetKubeMaster() []string

func (*Inventory) MoveToEtcd

func (i *Inventory) MoveToEtcd()

func (*Inventory) MoveToKubeMasters

func (i *Inventory) MoveToKubeMasters()

func (*Inventory) MoveToKubeWorkers

func (i *Inventory) MoveToKubeWorkers()

type K8sClient

type K8sClient struct {
	Namespace string
	// contains filtered or unexported fields
}

func NewK8sClient

func NewK8sClient(kclient *kubernetes.Clientset, ns string) *K8sClient

func (*K8sClient) CreateImagePullSecret

func (k *K8sClient) CreateImagePullSecret(server, username, password, secretName string) (*v1.Secret, error)

func (*K8sClient) CreateNamespace

func (k *K8sClient) CreateNamespace(namespace string) error

func (*K8sClient) CreatePv

func (k *K8sClient) CreatePv(pv *v1.PersistentVolume) (*v1.PersistentVolume, error)

func (*K8sClient) CreatePvc

func (k *K8sClient) CreatePvc(namespace string, pvc *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error)

func (*K8sClient) DeleteDaemonSet

func (k *K8sClient) DeleteDaemonSet(namespace, daemonSet string) error

func (*K8sClient) DeletePvc

func (k *K8sClient) DeletePvc(namespace, pvc string) error

func (*K8sClient) ExecCommand

func (k *K8sClient) ExecCommand(podName, command string) error

func (*K8sClient) GetClientSet

func (k *K8sClient) GetClientSet() *kubernetes.Clientset

func (*K8sClient) GetClusterResource

func (k *K8sClient) GetClusterResource() (int64, int64)

func (*K8sClient) GetNamespace

func (k *K8sClient) GetNamespace(namespace string) (ns *v1.Namespace, err error)

func (*K8sClient) GetPv

func (k *K8sClient) GetPv(pvName string) (pv *v1.PersistentVolume, err error)

Get exist pv

func (*K8sClient) GetPvc

func (k *K8sClient) GetPvc(namespace, pvcName string) (pvc *v1.PersistentVolumeClaim, err error)

Get exist pvc

func (*K8sClient) GetServerVersion

func (k *K8sClient) GetServerVersion() (*version.Info, error)

func (*K8sClient) PatchServiceAccount

func (k *K8sClient) PatchServiceAccount(sa, ips string)

type Metrics

type Metrics struct {
	CPU        int64
	Memory     int64
	Province   string
	City       string
	Version    string
	Status     string
	ErrorMsg   []string
	CurrentApp string
	Mux        sync.Mutex
	Ip         string
	Mail       string
}

func (*Metrics) Send

func (m *Metrics) Send()

type PreValue

type PreValue struct {
	Name  string
	Value string
	Check string
	Input utils.Input
}

type PreValueList

type PreValueList []*PreValue

type TaskInfo

type TaskInfo struct {
	// 唯一值
	Name      string
	Namespace string
	RefName   string
	// 任务类型: Release, task, persistence
	Type string
	// 资源对象的状态
	Status string
	// 错误原因
	Reason string
	Date   time.Time
	// 保存的配置项
	Values   []ChartValue
	Resource config.Resource

	TaskType string
	Version  string
	Prefix   string
}

TaskInfo 用于保存安装过程中的信息,包括 Release 的配置项,以及其他的状态等

保存到 k8s cm 中,Type 将 task 分为3类:release,task,persistent

func GetTask

func GetTask(task string) (*TaskInfo, error)

func NewReleaseJobTask

func NewReleaseJobTask(rlsJob, taskType, version string) *TaskInfo

func NewReleaseTask

func NewReleaseTask(release, namespace, version, prefix string) *TaskInfo

func SaveTask

func SaveTask(t TaskInfo) (*TaskInfo, error)

type Vars

type Vars struct {
	SkipVerifyNode        bool   `yaml:"skip_verify_node"`
	KubeVersion           string `yaml:"kube_version,omitempty"`
	LbMode                string `yaml:"lb_mode,omitempty"`
	LbKubeApiserverPort   int    `yaml:"lb_kube_apiserver_port,omitempty"`
	KubePodSubnet         string `yaml:"kube_pod_subnet,omitempty"`
	KubeServiceSubnet     string `yaml:"kube_service_subnet,omitempty"`
	KubeNetworkNodePrefix int    `yaml:"kube_network_node_prefix,omitempty"`
	KubeMaxPods           int    `yaml:"kube_max_pods,omitempty"`
	NetworkPlugin         string `yaml:"network_plugin,omitempty"`
	KubeletRootDir        string `yaml:"kubelet_root_dir,omitempty"`
	DockerStorageDir      string `yaml:"docker_storage_dir,omitempty"`
	EtcdDataDir           string `yaml:"etcd_data_dir,omitempty"`
}

Jump to

Keyboard shortcuts

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