mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
add K2Cluster object
This commit is contained in:
parent
1d5b364e8c
commit
5df0693ada
|
|
@ -1,149 +0,0 @@
|
|||
package v1alpha1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultPreDir = "kubekey"
|
||||
DefaultSSHPort = "22"
|
||||
DefaultDockerSockPath = "/var/run/docker.sock"
|
||||
DefaultLBPort = "6443"
|
||||
DefaultLBDomain = "lb.kubesphere.local"
|
||||
DefaultNetworkPlugin = "calico"
|
||||
DefaultPodsCIDR = "10.233.64.0/18"
|
||||
DefaultServiceCIDR = "10.233.0.0/18"
|
||||
DefaultKubeImageRepo = "kubekey"
|
||||
DefaultClusterName = "cluster.local"
|
||||
DefaultArch = "amd64"
|
||||
DefaultHostName = "allinone"
|
||||
DefaultEtcdRepo = "kubekey/etcd"
|
||||
DefaultEtcdVersion = "v3.3.12"
|
||||
DefaultEtcdPort = "2379"
|
||||
DefaultKubeVersion = "v1.17.4"
|
||||
DefaultCniVersion = "v0.8.2"
|
||||
DefaultHelmVersion = "v3.1.2"
|
||||
ETCDRole = "etcd"
|
||||
MasterRole = "master"
|
||||
WorkerRole = "worker"
|
||||
)
|
||||
|
||||
type K2Cluster struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
Spec ClusterCfg `json:"spec"`
|
||||
//Status ClusterStatus `json:"status"`
|
||||
}
|
||||
|
||||
type ClusterCfg struct {
|
||||
Hosts []HostCfg `yaml:"hosts" json:"hosts,omitempty"`
|
||||
LBKubeApiserver LBKubeApiserverCfg `yaml:"lbKubeapiserver" json:"lbKubeapiserver,omitempty"`
|
||||
KubeVersion string `yaml:"kubeVersion" json:"kubeVersion,omitempty"`
|
||||
KubeImageRepo string `yaml:"kubeImageRepo" json:"kubeImageRepo,omitempty"`
|
||||
KubeClusterName string `yaml:"kubeClusterName" json:"kubeClusterName,omitempty"`
|
||||
Network NetworkConfig `yaml:"network" json:"network,omitempty"`
|
||||
}
|
||||
|
||||
func (c ClusterCfg) GetObjectKind() schema.ObjectKind {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ClusterCfg) DeepCopyObject() runtime.Object {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
type Taint struct {
|
||||
Key string `json:"key,omitempty" yaml:"key"`
|
||||
Value string `json:"value,omitempty" yaml:"value"`
|
||||
Effect TaintEffect `json:"effect,omitempty" yaml:"effect"`
|
||||
}
|
||||
|
||||
type TaintEffect string
|
||||
|
||||
const (
|
||||
TaintEffectNoSchedule TaintEffect = "NoSchedule"
|
||||
TaintEffectPreferNoSchedule TaintEffect = "PreferNoSchedule"
|
||||
TaintEffectNoExecute TaintEffect = "NoExecute"
|
||||
)
|
||||
|
||||
type NodeInfo struct {
|
||||
HostName string
|
||||
}
|
||||
|
||||
type NetworkConfig struct {
|
||||
Plugin string `yaml:"plugin" json:"plugin,omitempty"`
|
||||
KubePodsCIDR string `yaml:"kube_pods_cidr" json:"kube_pods_cidr,omitempty"`
|
||||
KubeServiceCIDR string `yaml:"kube_service_cidr" json:"kube_service_cidr,omitempty"`
|
||||
}
|
||||
|
||||
type LBKubeApiserverCfg struct {
|
||||
Domain string `yaml:"domain" json:"domain,omitempty"`
|
||||
Address string `yaml:"address" json:"address,omitempty"`
|
||||
Port string `yaml:"port" json:"port,omitempty"`
|
||||
}
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) error {
|
||||
return RegisterDefaults(scheme)
|
||||
}
|
||||
|
||||
type ExternalEtcd struct {
|
||||
Endpoints []string
|
||||
CaFile string
|
||||
CertFile string
|
||||
KeyFile string
|
||||
}
|
||||
|
||||
func RegisterDefaults(scheme *runtime.Scheme) error {
|
||||
scheme.AddTypeDefaultingFunc(&ClusterCfg{}, func(obj interface{}) { SetDefaultClusterCfg(obj.(*ClusterCfg)) })
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cfg *ClusterCfg) GenerateHosts() []string {
|
||||
var lbHost string
|
||||
hostsList := []string{}
|
||||
|
||||
_, _, masters, _, _ := cfg.GroupHosts()
|
||||
if cfg.LBKubeApiserver.Address != "" {
|
||||
lbHost = fmt.Sprintf("%s %s", cfg.LBKubeApiserver.Address, cfg.LBKubeApiserver.Domain)
|
||||
} else {
|
||||
lbHost = fmt.Sprintf("%s %s", masters.Hosts[0].InternalAddress, DefaultLBDomain)
|
||||
}
|
||||
|
||||
for _, host := range cfg.Hosts {
|
||||
if host.HostName != "" {
|
||||
hostsList = append(hostsList, fmt.Sprintf("%s %s.%s %s", host.InternalAddress, host.HostName, cfg.KubeClusterName, host.HostName))
|
||||
}
|
||||
}
|
||||
|
||||
hostsList = append(hostsList, lbHost)
|
||||
return hostsList
|
||||
}
|
||||
|
||||
func (cfg *ClusterCfg) GenerateCertSANs() []string {
|
||||
clusterSvc := fmt.Sprintf("kubernetes.default.svc.%s", cfg.KubeClusterName)
|
||||
defaultCertSANs := []string{"kubernetes", "kubernetes.default", "kubernetes.default.svc", clusterSvc, "localhost", "127.0.0.1"}
|
||||
extraCertSANs := []string{}
|
||||
|
||||
extraCertSANs = append(extraCertSANs, cfg.LBKubeApiserver.Domain)
|
||||
extraCertSANs = append(extraCertSANs, cfg.LBKubeApiserver.Address)
|
||||
|
||||
for _, host := range cfg.Hosts {
|
||||
extraCertSANs = append(extraCertSANs, host.HostName)
|
||||
extraCertSANs = append(extraCertSANs, fmt.Sprintf("%s.%s", host.HostName, cfg.KubeClusterName))
|
||||
if host.SSHAddress != cfg.LBKubeApiserver.Address {
|
||||
extraCertSANs = append(extraCertSANs, host.SSHAddress)
|
||||
}
|
||||
if host.InternalAddress != host.SSHAddress && host.InternalAddress != cfg.LBKubeApiserver.Address {
|
||||
extraCertSANs = append(extraCertSANs, host.InternalAddress)
|
||||
}
|
||||
}
|
||||
|
||||
extraCertSANs = append(extraCertSANs, util.ParseIp(cfg.Network.KubeServiceCIDR)[0])
|
||||
|
||||
defaultCertSANs = append(defaultCertSANs, extraCertSANs...)
|
||||
return defaultCertSANs
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package v1alpha1
|
||||
|
||||
//const (
|
||||
// DefaultPreDir = "/tmp/kubekey"
|
||||
// DefaultSSHPort = "22"
|
||||
// DefaultDockerSockPath = "/var/run/docker.sock"
|
||||
// DefaultLBPort = "6443"
|
||||
// DefaultLBDomain = "lb.kubesphere.local"
|
||||
// DefaultNetworkPlugin = "calico"
|
||||
// DefaultPodsCIDR = "10.233.64.0/18"
|
||||
// DefaultServiceCIDR = "10.233.0.0/18"
|
||||
// DefaultKubeImageRepo = "kubekey"
|
||||
// DefaultClusterName = "cluster.local"
|
||||
// DefaultArch = "amd64"
|
||||
// DefaultHostName = "allinone"
|
||||
// DefaultEtcdRepo = "kubekey/etcd"
|
||||
// DefaultEtcdVersion = "v3.3.12"
|
||||
// DefaultEtcdPort = "2379"
|
||||
// DefaultKubeVersion = "v1.17.4"
|
||||
// DefaultCniVersion = "v0.8.2"
|
||||
// DefaultHelmVersion = "v3.1.2"
|
||||
// ETCDRole = "etcd"
|
||||
// MasterRole = "master"
|
||||
// WorkerRole = "worker"
|
||||
//)
|
||||
//
|
||||
//type HostConfig struct {
|
||||
// ID int `json:"-"`
|
||||
// PublicAddress string `json:"publicAddress"`
|
||||
// PrivateAddress string `json:"privateAddress"`
|
||||
// SSHPort int `json:"sshPort"`
|
||||
// SSHUsername string `json:"sshUsername"`
|
||||
// SSHPrivateKeyFile string `json:"sshPrivateKeyFile"`
|
||||
// SSHAgentSocket string `json:"sshAgentSocket"`
|
||||
// Bastion string `json:"bastion"`
|
||||
// BastionPort int `json:"bastionPort"`
|
||||
// BastionUser string `json:"bastionUser"`
|
||||
// Hostname string `json:"hostname"`
|
||||
// IsLeader bool `json:"isLeader"`
|
||||
// Untaint bool `json:"untaint"`
|
||||
//
|
||||
// // Information populated at the runtime
|
||||
// OperatingSystem string `json:"-"`
|
||||
//}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
package v1alpha1
|
||||
|
||||
type HostCfg struct {
|
||||
HostName string `yaml:"hostName" json:"hostName,omitempty"`
|
||||
SSHAddress string `yaml:"sshAddress" json:"sshAddress,omitempty"`
|
||||
InternalAddress string `yaml:"internalAddress" json:"internalAddress,omitempty"`
|
||||
Port string `yaml:"port" json:"port,omitempty"`
|
||||
User string `yaml:"user" json:"user,omitempty"`
|
||||
Password string `yaml:"password, omitempty" json:"password,omitempty"`
|
||||
SSHKeyPath string `yaml:"sshKeyPath, omitempty" json:"sshKeyPath,omitempty"`
|
||||
Role []string `yaml:"role" json:"role,omitempty" norman:"type=array[enum],options=etcd|master|worker|client"`
|
||||
ID int `yaml:"omitempty" json:"-"`
|
||||
IsEtcd bool `yaml:"omitempty"`
|
||||
IsMaster bool `yaml:"omitempty"`
|
||||
IsWorker bool `yaml:"omitempty"`
|
||||
IsClient bool `yaml:"omitempty"`
|
||||
}
|
||||
|
||||
type Hosts struct {
|
||||
Hosts []HostCfg
|
||||
}
|
||||
|
||||
func (cfg *ClusterCfg) GroupHosts() (*Hosts, *Hosts, *Hosts, *Hosts, *Hosts) {
|
||||
allHosts := Hosts{}
|
||||
etcdHosts := Hosts{}
|
||||
masterHosts := Hosts{}
|
||||
workerHosts := Hosts{}
|
||||
k8sHosts := Hosts{}
|
||||
|
||||
for _, host := range cfg.Hosts {
|
||||
//clusterNode := HostCfg{}
|
||||
for _, role := range host.Role {
|
||||
if role == "etcd" {
|
||||
host.IsEtcd = true
|
||||
}
|
||||
if role == "master" {
|
||||
host.IsMaster = true
|
||||
}
|
||||
if role == "worker" {
|
||||
host.IsWorker = true
|
||||
}
|
||||
}
|
||||
if host.IsEtcd == true {
|
||||
etcdHosts.Hosts = append(etcdHosts.Hosts, host)
|
||||
}
|
||||
if host.IsMaster == true {
|
||||
masterHosts.Hosts = append(masterHosts.Hosts, host)
|
||||
}
|
||||
if host.IsWorker == true {
|
||||
workerHosts.Hosts = append(workerHosts.Hosts, host)
|
||||
}
|
||||
if host.IsMaster == true || host.IsWorker == true {
|
||||
k8sHosts.Hosts = append(k8sHosts.Hosts, host)
|
||||
}
|
||||
allHosts.Hosts = append(allHosts.Hosts, host)
|
||||
}
|
||||
return &allHosts, &etcdHosts, &masterHosts, &workerHosts, &k8sHosts
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package v1alpha1
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
// GroupName is the name of the group used by this API
|
||||
const GroupName = "kubekey.io"
|
||||
|
||||
// SchemeGroupVersion is group version used to register API objects
|
||||
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
|
||||
|
||||
var (
|
||||
// SchemeBuilder points to a list of functions added to Scheme
|
||||
SchemeBuilder runtime.SchemeBuilder
|
||||
localSchemeBuilder = &SchemeBuilder
|
||||
// AddToScheme applies all the stored functions to the Scheme
|
||||
AddToScheme = localSchemeBuilder.AddToScheme
|
||||
)
|
||||
|
||||
func init() {
|
||||
localSchemeBuilder.Register(addKnownTypes, addDefaultingFuncs)
|
||||
}
|
||||
|
||||
// Kind takes an unqualified kind and returns GroupKind
|
||||
func Kind(kind string) schema.GroupKind {
|
||||
return SchemeGroupVersion.WithKind(kind).GroupKind()
|
||||
}
|
||||
|
||||
// Resource takes an unqualified resource and returns GroupResource
|
||||
func Resource(resource string) schema.GroupResource {
|
||||
return SchemeGroupVersion.WithResource(resource).GroupResource()
|
||||
}
|
||||
|
||||
func addKnownTypes(scheme *runtime.Scheme) error {
|
||||
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||
&ClusterCfg{})
|
||||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -4,8 +4,8 @@ import (
|
|||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/lithammer/dedent"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
package install
|
||||
|
||||
import (
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
ssh "github.com/pixiake/kubekey/util/ssh"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
ssh "github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Executor struct {
|
||||
cluster *kubekeyapi.ClusterCfg
|
||||
cluster *kubekeyapi.K2ClusterSpec
|
||||
logger *logrus.Logger
|
||||
}
|
||||
|
||||
func NewExecutor(cluster *kubekeyapi.ClusterCfg, logger *logrus.Logger) *Executor {
|
||||
func NewExecutor(cluster *kubekeyapi.K2ClusterSpec, logger *logrus.Logger) *Executor {
|
||||
return &Executor{
|
||||
cluster: cluster,
|
||||
logger: logger,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package install
|
||||
|
||||
import (
|
||||
"github.com/pixiake/kubekey/cluster/container-engine/docker"
|
||||
"github.com/pixiake/kubekey/cluster/etcd"
|
||||
"github.com/pixiake/kubekey/cluster/kubernetes"
|
||||
"github.com/pixiake/kubekey/cluster/preinstall"
|
||||
"github.com/pixiake/kubekey/plugins/network"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/util/task"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/container-engine/docker"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/etcd"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/kubernetes"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/preinstall"
|
||||
"github.com/pixiake/kubekey/pkg/plugins/network"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/task"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package v1alpha1
|
||||
|
||||
const (
|
||||
DefaultPreDir = "kubekey"
|
||||
DefaultSSHPort = "22"
|
||||
DefaultDockerSockPath = "/var/run/docker.sock"
|
||||
DefaultLBPort = "6443"
|
||||
DefaultLBDomain = "lb.kubesphere.local"
|
||||
DefaultNetworkPlugin = "calico"
|
||||
DefaultPodsCIDR = "10.233.64.0/18"
|
||||
DefaultServiceCIDR = "10.233.0.0/18"
|
||||
DefaultKubeImageRepo = "kubekey"
|
||||
DefaultClusterName = "cluster.local"
|
||||
DefaultArch = "amd64"
|
||||
DefaultHostName = "allinone"
|
||||
DefaultEtcdRepo = "kubekey/etcd"
|
||||
DefaultEtcdVersion = "v3.3.12"
|
||||
DefaultEtcdPort = "2379"
|
||||
DefaultKubeVersion = "v1.17.4"
|
||||
DefaultCniVersion = "v0.8.2"
|
||||
DefaultHelmVersion = "v3.1.2"
|
||||
ETCDRole = "etcd"
|
||||
MasterRole = "master"
|
||||
WorkerRole = "worker"
|
||||
)
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/util/ssh"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
|
@ -3,10 +3,10 @@ package etcd
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/cluster/etcd/tmpl"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/util/ssh"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/etcd/tmpl"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/pkg/errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -2,8 +2,8 @@ package tmpl
|
|||
|
||||
import (
|
||||
"github.com/lithammer/dedent"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
|
@ -159,7 +159,7 @@ mv *.pem ${SSLDIR}/
|
|||
`)))
|
||||
)
|
||||
|
||||
func GenerateEtcdSslCfg(cfg *kubekeyapi.ClusterCfg) (string, error) {
|
||||
func GenerateEtcdSslCfg(cfg *kubekeyapi.K2ClusterSpec) (string, error) {
|
||||
dnsList := []string{"localhost", "etcd.kube-system.svc.cluster.local", "etcd.kube-system.svc", "etcd.kube-system", "etcd"}
|
||||
ipList := []string{"127.0.0.1"}
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ func GenerateEtcdSslCfg(cfg *kubekeyapi.ClusterCfg) (string, error) {
|
|||
})
|
||||
}
|
||||
|
||||
func GenerateEtcdSslScript(cfg *kubekeyapi.ClusterCfg) (string, error) {
|
||||
func GenerateEtcdSslScript(cfg *kubekeyapi.K2ClusterSpec) (string, error) {
|
||||
var masters []string
|
||||
var hosts []string
|
||||
_, etcdNodes, masterNodes, _, _ := cfg.GroupHosts()
|
||||
|
|
@ -3,9 +3,9 @@ package tmpl
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/lithammer/dedent"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
|
@ -3,10 +3,10 @@ package kubernetes
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/cluster/kubernetes/tmpl"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/util/ssh"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/kubernetes/tmpl"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -3,10 +3,10 @@ package kubernetes
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/cluster/kubernetes/tmpl"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/util/ssh"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/kubernetes/tmpl"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -3,9 +3,9 @@ package tmpl
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/lithammer/dedent"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
|
@ -2,8 +2,8 @@ package tmpl
|
|||
|
||||
import (
|
||||
"github.com/lithammer/dedent"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
|
@ -38,10 +38,10 @@ ExecStart=/usr/local/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $
|
|||
`)))
|
||||
)
|
||||
|
||||
func GenerateKubeletService(cfg *kubekeyapi.ClusterCfg) (string, error) {
|
||||
func GenerateKubeletService(cfg *kubekeyapi.K2ClusterSpec) (string, error) {
|
||||
return util.Render(KubeletServiceTempl, util.Data{})
|
||||
}
|
||||
|
||||
func GenerateKubeletEnv(cfg *kubekeyapi.ClusterCfg) (string, error) {
|
||||
func GenerateKubeletEnv(cfg *kubekeyapi.K2ClusterSpec) (string, error) {
|
||||
return util.Render(KubeletEnvTempl, util.Data{})
|
||||
}
|
||||
|
|
@ -3,10 +3,10 @@ package preinstall
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/cluster/preinstall/tmpl"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/util/ssh"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/cluster/preinstall/tmpl"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
|
@ -2,8 +2,8 @@ package preinstall
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"path/filepath"
|
||||
)
|
||||
|
||||
func FilesDownloadHttp(cfg *kubekeyapi.ClusterCfg, filepath string, logger *log.Logger) error {
|
||||
func FilesDownloadHttp(cfg *kubekeyapi.K2ClusterSpec, filepath string, logger *log.Logger) error {
|
||||
kubeVersion := cfg.KubeVersion
|
||||
|
||||
kubeadmUrl := fmt.Sprintf("https://kubernetes-release.pek3b.qingstor.com/release/%s/bin/linux/%s/kubeadm", kubeVersion, kubekeyapi.DefaultArch)
|
||||
|
|
@ -75,7 +75,7 @@ func FilesDownloadHttp(cfg *kubekeyapi.ClusterCfg, filepath string, logger *log.
|
|||
return nil
|
||||
}
|
||||
|
||||
func Prepare(cfg *kubekeyapi.ClusterCfg, logger *log.Logger) error {
|
||||
func Prepare(cfg *kubekeyapi.K2ClusterSpec, logger *log.Logger) error {
|
||||
logger.Info("Install Files Download")
|
||||
|
||||
currentDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
|
|
@ -2,8 +2,8 @@ package tmpl
|
|||
|
||||
import (
|
||||
"github.com/lithammer/dedent"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ cat >>/etc/hosts<<EOF
|
|||
EOF
|
||||
`)))
|
||||
|
||||
func InitOsScript(cfg *kubekeyapi.ClusterCfg) (string, error) {
|
||||
func InitOsScript(cfg *kubekeyapi.K2ClusterSpec) (string, error) {
|
||||
hostlist := cfg.GenerateHosts()
|
||||
return util.Render(initOsScriptTmpl, util.Data{
|
||||
"Hosts": hostlist,
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package v1alpha1
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
|
|
@ -12,7 +13,7 @@ import (
|
|||
var Scheme = runtime.NewScheme()
|
||||
var Codecs = serializer.NewCodecFactory(Scheme, serializer.EnableStrict)
|
||||
|
||||
func LoadClusterCfg(clusterCfgPath string, logger *log.Logger) (*ClusterCfg, error) {
|
||||
func ParseK2ClusterObj(clusterCfgPath string, logger *log.Logger) (*v1alpha1.K2Cluster, error) {
|
||||
if len(clusterCfgPath) == 0 {
|
||||
return nil, errors.New("cluster configuration path not provided")
|
||||
}
|
||||
|
|
@ -22,11 +23,11 @@ func LoadClusterCfg(clusterCfgPath string, logger *log.Logger) (*ClusterCfg, err
|
|||
return nil, errors.Wrap(err, "unable to read the given cluster configuration file")
|
||||
}
|
||||
|
||||
return ParseClusterCfg(cluster)
|
||||
return ParseK2ClusterCfg(cluster)
|
||||
}
|
||||
|
||||
func ParseClusterCfg(cluster []byte) (*ClusterCfg, error) {
|
||||
initCfg := &ClusterCfg{}
|
||||
func ParseK2ClusterCfg(cluster []byte) (*v1alpha1.K2Cluster, error) {
|
||||
initCfg := &v1alpha1.K2Cluster{}
|
||||
if err := runtime.DecodeInto(Codecs.UniversalDecoder(), cluster, initCfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -34,8 +35,8 @@ func ParseClusterCfg(cluster []byte) (*ClusterCfg, error) {
|
|||
return GetDefaultClusterCfg(initCfg)
|
||||
}
|
||||
|
||||
func GetDefaultClusterCfg(cfg *ClusterCfg) (*ClusterCfg, error) {
|
||||
internalCfg := &ClusterCfg{}
|
||||
func GetDefaultClusterCfg(cfg *v1alpha1.K2Cluster) (*v1alpha1.K2Cluster, error) {
|
||||
internalCfg := &v1alpha1.K2Cluster{}
|
||||
|
||||
// Default and convert to the internal API type
|
||||
Scheme.Default(cfg)
|
||||
|
|
@ -46,28 +47,28 @@ func GetDefaultClusterCfg(cfg *ClusterCfg) (*ClusterCfg, error) {
|
|||
return internalCfg, nil
|
||||
}
|
||||
|
||||
func SetDefaultClusterCfg(cfg *ClusterCfg) *ClusterCfg {
|
||||
clusterCfg := &ClusterCfg{}
|
||||
func SetDefaultClusterCfg(cfg *v1alpha1.K2ClusterSpec) *v1alpha1.K2ClusterSpec {
|
||||
clusterCfg := &v1alpha1.K2ClusterSpec{}
|
||||
|
||||
cfg.Hosts = SetDefaultHostsCfg(cfg)
|
||||
cfg.LBKubeApiserver = SetDefaultLBCfg(cfg)
|
||||
cfg.Network = SetDefaultNetworkCfg(cfg)
|
||||
|
||||
if cfg.KubeImageRepo == "" {
|
||||
cfg.KubeImageRepo = DefaultKubeImageRepo
|
||||
cfg.KubeImageRepo = v1alpha1.DefaultKubeImageRepo
|
||||
}
|
||||
if cfg.KubeClusterName == "" {
|
||||
cfg.KubeClusterName = DefaultClusterName
|
||||
cfg.KubeClusterName = v1alpha1.DefaultClusterName
|
||||
}
|
||||
if cfg.KubeVersion == "" {
|
||||
cfg.KubeVersion = DefaultKubeVersion
|
||||
cfg.KubeVersion = v1alpha1.DefaultKubeVersion
|
||||
}
|
||||
clusterCfg = cfg
|
||||
return clusterCfg
|
||||
}
|
||||
|
||||
func SetDefaultHostsCfg(cfg *ClusterCfg) []HostCfg {
|
||||
var hostscfg []HostCfg
|
||||
func SetDefaultHostsCfg(cfg *v1alpha1.K2ClusterSpec) []v1alpha1.HostCfg {
|
||||
var hostscfg []v1alpha1.HostCfg
|
||||
if len(cfg.Hosts) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -105,8 +106,8 @@ func SetDefaultHostsCfg(cfg *ClusterCfg) []HostCfg {
|
|||
return hostscfg
|
||||
}
|
||||
|
||||
func SetDefaultLBCfg(cfg *ClusterCfg) LBKubeApiserverCfg {
|
||||
masterHosts := []HostCfg{}
|
||||
func SetDefaultLBCfg(cfg *v1alpha1.K2ClusterSpec) v1alpha1.LBKubeApiserverCfg {
|
||||
masterHosts := []v1alpha1.HostCfg{}
|
||||
hosts := SetDefaultHostsCfg(cfg)
|
||||
for _, host := range hosts {
|
||||
for _, role := range host.Role {
|
||||
|
|
@ -129,24 +130,24 @@ func SetDefaultLBCfg(cfg *ClusterCfg) LBKubeApiserverCfg {
|
|||
cfg.LBKubeApiserver.Address = masterHosts[0].InternalAddress
|
||||
}
|
||||
if cfg.LBKubeApiserver.Domain == "" {
|
||||
cfg.LBKubeApiserver.Domain = DefaultLBDomain
|
||||
cfg.LBKubeApiserver.Domain = v1alpha1.DefaultLBDomain
|
||||
}
|
||||
if cfg.LBKubeApiserver.Port == "" {
|
||||
cfg.LBKubeApiserver.Port = DefaultLBPort
|
||||
cfg.LBKubeApiserver.Port = v1alpha1.DefaultLBPort
|
||||
}
|
||||
defaultLbCfg := cfg.LBKubeApiserver
|
||||
return defaultLbCfg
|
||||
}
|
||||
|
||||
func SetDefaultNetworkCfg(cfg *ClusterCfg) NetworkConfig {
|
||||
func SetDefaultNetworkCfg(cfg *v1alpha1.K2ClusterSpec) v1alpha1.NetworkConfig {
|
||||
if cfg.Network.Plugin == "" {
|
||||
cfg.Network.Plugin = DefaultNetworkPlugin
|
||||
cfg.Network.Plugin = v1alpha1.DefaultNetworkPlugin
|
||||
}
|
||||
if cfg.Network.KubePodsCIDR == "" {
|
||||
cfg.Network.KubePodsCIDR = DefaultPodsCIDR
|
||||
cfg.Network.KubePodsCIDR = v1alpha1.DefaultPodsCIDR
|
||||
}
|
||||
if cfg.Network.KubeServiceCIDR == "" {
|
||||
cfg.Network.KubeServiceCIDR = DefaultServiceCIDR
|
||||
cfg.Network.KubeServiceCIDR = v1alpha1.DefaultServiceCIDR
|
||||
}
|
||||
|
||||
defaultNetworkCfg := cfg.Network
|
||||
|
|
@ -2,8 +2,8 @@ package calico
|
|||
|
||||
import (
|
||||
"github.com/lithammer/dedent"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
|
@ -811,7 +811,7 @@ metadata:
|
|||
# Source: calico/templates/configure-canal.yaml
|
||||
`)))
|
||||
|
||||
func GenerateCalicoFiles(cfg *kubekeyapi.ClusterCfg) (string, error) {
|
||||
func GenerateCalicoFiles(cfg *kubekeyapi.K2ClusterSpec) (string, error) {
|
||||
return util.Render(calicoTempl, util.Data{
|
||||
"KubePodsCIDR": cfg.Network.KubePodsCIDR,
|
||||
})
|
||||
|
|
@ -2,8 +2,8 @@ package flannel
|
|||
|
||||
import (
|
||||
"github.com/lithammer/dedent"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
|
@ -613,7 +613,7 @@ spec:
|
|||
|
||||
`)))
|
||||
|
||||
func GenerateFlannelFiles(cfg *kubekeyapi.ClusterCfg) (string, error) {
|
||||
func GenerateFlannelFiles(cfg *kubekeyapi.K2ClusterSpec) (string, error) {
|
||||
return util.Render(flannelTempl, util.Data{
|
||||
"KubePodsCIDR": cfg.Network.KubePodsCIDR,
|
||||
})
|
||||
|
|
@ -3,11 +3,11 @@ package network
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/plugins/network/calico"
|
||||
"github.com/pixiake/kubekey/plugins/network/flannel"
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/util/ssh"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/plugins/network/calico"
|
||||
"github.com/pixiake/kubekey/pkg/plugins/network/flannel"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
package manager
|
||||
|
||||
import (
|
||||
ssh2 "github.com/pixiake/kubekey/util/ssh"
|
||||
ssh2 "github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
|
||||
"github.com/pixiake/kubekey/util/runner"
|
||||
"github.com/pixiake/kubekey/pkg/util/runner"
|
||||
//"k8s.io/client-go/rest"
|
||||
//bootstraputil "k8s.io/cluster-bootstrap/token/util"
|
||||
//dynclient "sigs.k8s.io/manager-runtime/pkg/client"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
Cluster *kubekeyapi.ClusterCfg
|
||||
Cluster *kubekeyapi.K2ClusterSpec
|
||||
Logger logrus.FieldLogger
|
||||
Connector *ssh2.Dialer
|
||||
Runner *runner.Runner
|
||||
|
|
@ -2,14 +2,14 @@ package manager
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pixiake/kubekey/util/ssh"
|
||||
"github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/util/runner"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/util/runner"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -2,8 +2,8 @@ package runner
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
ssh2 "github.com/pixiake/kubekey/util/ssh"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
ssh2 "github.com/pixiake/kubekey/pkg/util/ssh"
|
||||
"github.com/pkg/errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
kubekeyapi "github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
)
|
||||
|
||||
// Connector holds a map of Connections
|
||||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
"github.com/pixiake/kubekey/pkg/apis/kubekey/v1alpha1"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package task
|
||||
|
||||
import (
|
||||
"github.com/pixiake/kubekey/util/manager"
|
||||
"github.com/pixiake/kubekey/pkg/util/manager"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"time"
|
||||
)
|
||||
Loading…
Reference in New Issue