core

package
v0.0.0-...-420457a Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorExitOSCase = -1 // 错误直接退出类型

	ErrorMasterEmpty    = "your master is empty."             // master节点ip为空
	ErrorVersionEmpty   = "your kubernetes version is empty." // kubernetes 版本号为空
	ErrorFileNotExist   = "your package file is not exist."   // 离线安装包为空
	ErrorPkgURLNotExist = "Your package url is incorrect."    // 离线安装包为http路径不对

	// etcd backup
	ETCDSNAPSHOTDEFAULTNAME = "snapshot"
	ETCDDEFAULTBACKUPDIR    = "/data/supkube/etcd-backup"
	ETCDDEFAULTRESTOREDIR   = "/opt/supkube/etcd-restore"
	ETCDDATADIR             = "/var/lib/etcd"
	TMPDIR                  = "/tmp"

	// kube file
	KUBECONTROLLERCONFIGFILE = "/etc/kubernetes/controller-manager.conf"
	KUBESCHEDULERCONFIGFILE  = "/etc/kubernetes/scheduler.conf"

	// CriSocket
	DefaultDockerCRISocket     = "/var/run/dockershim.sock"
	DefaultContainerdCRISocket = "/run/containerd/containerd.sock"
	DefaultCgroupDriver        = "cgroupfs"
	DefaultSystemdCgroupDriver = "systemd"

	KubeadmV1beta1 = "kubeadm.k8s.io/v1beta1"
	KubeadmV1beta2 = "kubeadm.k8s.io/v1beta2"
	KubeadmV1beta3 = "kubeadm.k8s.io/v1beta3"
)
View Source
const (
	InitTemplateText = string(InitConfigurationDefault +
		ClusterConfigurationDefault +
		kubeproxyConfigDefault +
		kubeletConfigDefault)
	JoinCPTemplateText = string(bootstrapTokenDefault +
		JoinConfigurationDefault +
		kubeletConfigDefault)

	InitConfigurationDefault = `` /* 166-byte string literal not displayed */

	JoinConfigurationDefault = `` /* 186-byte string literal not displayed */

	ClusterConfigurationDefault = `` /* 1137-byte string literal not displayed */

	ContainerdShell = `` /* 132-byte string literal not displayed */

	DockerShell = `driver=$(docker info -f "{{.CgroupDriver}}")
	echo "${driver}"`
)

Variables

View Source
var (
	JoinToken       string
	TokenCaCertHash string
	CertificateKey  string
)
View Source
var (
	MasterIPs         []string
	NodeIPs           []string
	CertSANS          []string
	DNSDomain         string
	APIServerCertSANs []string
	SSHConfig         sshutil.SSH
	APIServer         string
	CertPath          = cert.ConfigDir + "/pki"
	CertEtcdPath      = cert.ConfigDir + "/pki/etcd"
	EtcdCacart        = cert.ConfigDir + "/pki/etcd/ca.crt"
	EtcdCert          = cert.ConfigDir + "/pki/etcd/healthcheck-client.crt"
	EtcdKey           = cert.ConfigDir + "/pki/etcd/healthcheck-client.key"

	CriSocket    string
	CgroupDriver string
	KubeadmAPI   string

	VIP     string
	PkgURL  string
	Version string
	Repo    string
	PodCIDR string
	SvcCIDR string

	Envs          []string // read env from -e
	PackageConfig string   // install/delete package config
	Values        string   // values for  install package values.yaml
	WorkDir       string   // workdir for install/delete package home

	Ipvs         care.LvsCare
	LvscareImage ipvs.LvscareImage
	KubeadmFile  string

	Network string // network type, calico or flannel etc..

	WithoutCNI bool // if true don't install cni plugin

	Interface string //network interface name, like "eth.*|en.*"

	BGP bool // the ipip mode of the calico

	MTU string // mtu size

	YesRx = regexp.MustCompile("^(?i:y(?:es)?)$")

	CleanForce bool
	CleanAll   bool

	Vlog int

	InDocker     bool
	SnapshotName string
	EtcdBackDir  string
	RestorePath  string

	OssEndpoint      string
	AccessKeyID      string
	AccessKeySecrets string
	BucketName       string
	ObjectPath       string
)
View Source
var ConfigType string

Functions

func BuildInit

func BuildInit()

BuildInit is

func BuildJoin

func BuildJoin(joinMasters, joinNodes []string)

BuildJoin is

func CanUpgradeByNewVersion

func CanUpgradeByNewVersion(new, old string) error

func Cmp

func Cmp(a, b net.IP) int

Cmp compares two IPs, returning the usual ordering: a < b : -1 a == b : 0 a > b : 1

func CompressTar

func CompressTar(srcDirPath string, destFilePath string) error

func CompressZip

func CompressZip(fileDir string, outputPath string) error

CompressZip is compress all file in fileDir , and zip to outputPath like unix zip ./ -r a.zip

func Confirm

func Confirm(prompt string) bool

send the prompt and get result

func DecodeIPs

func DecodeIPs(ips []string) []string

func DownloadFile

func DownloadFile(location string) (filePATH, md5 string)

func Dump

func Dump(path string, content interface{}) error

func ExitDeleteCase

func ExitDeleteCase(pkgURL string) bool

func ExitInitCase

func ExitInitCase() bool

ExitOSCase is

func ExitInstallCase

func ExitInstallCase(pkgURL string) bool

func ExitUpgradeCase

func ExitUpgradeCase(version, pkgURL, cfgFile string) error

func FetchAbsPath

func FetchAbsPath() string

获取绝对路径

func FileExist

func FileExist(path string) bool

func For120

func For120(version string) bool

func GetConfirmResult

func GetConfirmResult(str string) bool

like y|yes|Y|YES return true

func GetMajorMinorInt

func GetMajorMinorInt(version string) (major, minor int)

GetMajorMinorInt

func GetRemoteHostName

func GetRemoteHostName(hostIP string) string

func IPFormat

func IPFormat(host string) string

IPFormat is

func JoinTemplate

func JoinTemplate(ip string, cgroup string) []byte

JoinTemplate is generate JoinCP nodes configuration by master ip.

func JoinTemplateFromTemplateContent

func JoinTemplateFromTemplateContent(templateContent, ip, cgroup string) []byte

func KubeadmConfig

func KubeadmConfig()

func Load

func Load(path string, content interface{}) error

func NextIP

func NextIP(ip net.IP) net.IP

NextIP returns IP incremented by 1

func ParseIPs

func ParseIPs(ips []string) []string

ParseIPs 解析ip 192.168.0.2-192.168.0.6

func RandString

func RandString(len int) string

RandString 生成随机字符串

func SendPackage

func SendPackage(location string, hosts []string, dst string, before, after *string) string

location : url md5 dst: /root hook: cd /root && rm -rf kube && tar zxvf %s && cd /root/kube/shell && sh init.sh

func SetHosts

func SetHosts(hostIP, hostName string)

SetHosts set hosts. if can't access to hostName, set /etc/hosts

func SliceRemoveStr

func SliceRemoveStr(ss []string, s string) (result []string)

func Template

func Template() []byte

Template is

func TemplateFromTemplateContent

func TemplateFromTemplateContent(templateContent string) []byte

func VersionToInt

func VersionToInt(version string) int

VersionToInt v1.15.6 => 115

func VersionToIntAll

func VersionToIntAll(version string) int

VersionToIntAll v1.19.1 ==> 1191

Types

type Apply

type Apply interface {
	KubeApply(name string)
}

type Check

type Check interface {
	CheckValid()
}

type Clean

type Clean interface {
	Clean()
}

Clean is

type CleanCluster

type CleanCluster interface {
	Check
	Clean
}

type CommandType

type CommandType string
const InitMaster CommandType = "initMaster"

command type

const JoinMaster CommandType = "joinMaster"
const JoinNode CommandType = "joinNode"

type Config

type Config struct {
	Masters []string
	Nodes   []string
	//config from kubeadm.cfg. ex. cluster.local
	DNSDomain         string
	APIServerCertSANs []string

	//SSHConfig
	User       string
	Passwd     string
	PrivateKey string
	PkPassword string
	//ApiServer ex. apiserver.cluster.local
	APIServerDomain string
	Network         string
	VIP             string
	PkgURL          string
	Version         string
	Repo            string
	PodCIDR         string
	SvcCIDR         string
	//certs location
	CertPath     string
	CertEtcdPath string
	//lvscare images
	LvscareName string
	LvscareTag  string
}

Config for ~/.supkube/config.yaml

func (*Config) Dump

func (c *Config) Dump(path string)

Dump is

func (*Config) Load

func (c *Config) Load(path string) (err error)

Load is

func (*Config) ShowDefaultConfig

func (c *Config) ShowDefaultConfig()

type Init

type Init interface {
	Check
	Send
	PreInit
	Join
	Print
}

type Install

type Install interface {
	Check
	Send
	Apply
}

type Installer

type Installer struct {
	Hosts     []string
	Masters   []string
	Nodes     []string
	Network   string
	APIServer string
}

Installer is

func (*Installer) CheckValid

func (s *Installer) CheckValid()

CheckValid is

func (*Installer) Command

func (s *Installer) Command(version string, name CommandType) (cmd string)

func (*Installer) CreateKubeconfig

func (s *Installer) CreateKubeconfig()

func (*Installer) GenerateCert

func (s *Installer) GenerateCert()

func (*Installer) GeneratorCerts

func (s *Installer) GeneratorCerts()

GeneratorToken is 这里主要是为了获取CertificateKey

func (*Installer) GeneratorToken

func (s *Installer) GeneratorToken()

GeneratorToken is

func (*Installer) InstallMaster0

func (s *Installer) InstallMaster0()

InstallMaster0 is

func (*Installer) JoinMasters

func (s *Installer) JoinMasters(masters []string)

JoinMasters is

func (*Installer) JoinNodes

func (s *Installer) JoinNodes()

JoinNodes is

func (*Installer) KubeadmConfigInstall

func (s *Installer) KubeadmConfigInstall()

KubeadmConfigInstall is

func (*Installer) Print

func (s *Installer) Print(process ...string)

Print is

func (*Installer) PrintFinish

func (s *Installer) PrintFinish()

func (*Installer) Send

func (s *Installer) Send()

Send is send the exec to /usr/bin/

func (*Installer) SendJoinMasterKubeConfigs

func (s *Installer) SendJoinMasterKubeConfigs(masters []string)

func (*Installer) SendKubeConfigs

func (s *Installer) SendKubeConfigs(masters []string)

SendKubeConfigs

func (*Installer) SendPackage

func (s *Installer) SendPackage()

SendPackage is

type Join

type Join interface {
	JoinMasters()
	JoinNodes()
	GeneratorToken()
}

Join is

type JoinNodeAndMaster

type JoinNodeAndMaster interface {
	Check
	Send
	Join
}

type KubeadmType

type KubeadmType struct {
	Kind      string `yaml:"kind,omitempty"`
	APIServer struct {
		CertSANs []string `yaml:"certSANs,omitempty"`
	} `yaml:"apiServer"`
	Networking struct {
		DNSDomain string `yaml:"dnsDomain,omitempty"`
	} `yaml:"networking"`
}

func KubeadmDataFromYaml

func KubeadmDataFromYaml(context string) *KubeadmType

根据yaml转换kubeadm结构

type Pool

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

func NewPool

func NewPool(size int) *Pool

func (*Pool) Add

func (p *Pool) Add(delta int)

func (*Pool) Done

func (p *Pool) Done()

func (*Pool) Wait

func (p *Pool) Wait()

type PreInit

type PreInit interface {
	KubeadmConfigInstall()
	InstallMaster0()
}

PreInit is

type Print

type Print interface {
	Print(process ...string)
}

Print is

type Send

type Send interface {
	SendPackage()
}

Send is

type Upgrade

type Upgrade struct {
	Config
	NewVersion   string
	NewPkgURL    string
	IPtoHostName map[string]string
	Client       *kubernetes.Clientset
}

func NewUpgrade

func NewUpgrade(version, pkgURL string) *Upgrade

func (*Upgrade) GetHostNamesFromIps

func (u *Upgrade) GetHostNamesFromIps(ips []string) []string

func (*Upgrade) GetIPByHostname

func (u *Upgrade) GetIPByHostname(host string) string

func (*Upgrade) SendPackage

func (u *Upgrade) SendPackage()

SendPackage is send new pkg to all nodes.

func (*Upgrade) SetIPtoHostName

func (u *Upgrade) SetIPtoHostName()

func (*Upgrade) SetUP

func (u *Upgrade) SetUP()

func (*Upgrade) UpgradeMaster0

func (u *Upgrade) UpgradeMaster0()

UpgradeMaster0 is upgrade master first.

func (*Upgrade) UpgradeNodes

func (u *Upgrade) UpgradeNodes()

UpgradeNodes is upgrade nodes.

func (*Upgrade) UpgradeOtherMaster

func (u *Upgrade) UpgradeOtherMaster()

UpgradeOtherMaster is upgrade other master.

Jump to

Keyboard shortcuts

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