mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
add resolve config
This commit is contained in:
parent
2b78fe26d8
commit
e44a6822ea
|
|
@ -0,0 +1,58 @@
|
|||
package v1alpha1
|
||||
|
||||
type ClusterCfg struct {
|
||||
Hosts []HostCfg `yaml:"hosts" json:"hosts,omitempty"`
|
||||
LBKubeApiserver LBKubeApiserverCfg `yaml:"lb_kubeapiserver" json:"lb_kubeapiserver,omitempty"`
|
||||
KubeVersion string `yaml:"kube_version" json:"kube_version,omitempty"`
|
||||
KubeImageRepo string `yaml:"kube_image_repo" json:"kube_image_repo,omitempty"`
|
||||
KubeClusterName string `yaml:"kube_cluster_name" json:"kube_cluster_name,omitempty"`
|
||||
Network NetworkConfig `yaml:"network" json:"network,omitempty"`
|
||||
}
|
||||
|
||||
type HostCfg struct {
|
||||
HostName string `yaml:"hostName,omitempty" json:"hostName,omitempty"`
|
||||
Address string `yaml:"address" json:"address,omitempty"`
|
||||
Port string `yaml:"port" json:"port,omitempty"`
|
||||
InternalAddress string `yaml:"internal_address" json:"internalAddress,omitempty"`
|
||||
Role []string `yaml:"role" json:"role,omitempty" norman:"type=array[enum],options=etcd|worker|worker"`
|
||||
//HostnameOverride string `yaml:"hostname_override" json:"hostnameOverride,omitempty"`
|
||||
User string `yaml:"user" json:"user,omitempty"`
|
||||
Password string `yaml:"password" json:"password,omitempty"`
|
||||
//SSHAgentAuth bool `yaml:"ssh_agent_auth,omitempty" json:"sshAgentAuth,omitempty"`
|
||||
//SSHKey string `yaml:"ssh_key" json:"sshKey,omitempty" norman:"type=password"`
|
||||
SSHKeyPath string `yaml:"ssh_key_path" json:"sshKeyPath,omitempty"`
|
||||
//SSHCert string `yaml:"ssh_cert" json:"sshCert,omitempty"`
|
||||
//SSHCertPath string `yaml:"ssh_cert_path" json:"sshCertPath,omitempty"`
|
||||
//Labels map[string]string `yaml:"labels" json:"labels,omitempty"`
|
||||
//Taints []Taint `yaml:"taints" json:"taints,omitempty"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package v1alpha1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func GetClusterCfg(clusterCfgFile string) *ClusterCfg {
|
||||
if clusterCfgFile != "" {
|
||||
clusterInfo, err := ResolveClusterInfoFile(clusterCfgFile)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to parse the configuration file: ", err)
|
||||
}
|
||||
return clusterInfo
|
||||
} else {
|
||||
clusterInfo := &ClusterCfg{
|
||||
Hosts: []HostCfg{{
|
||||
Role: []string{"etcd", "master", "worker"},
|
||||
User: "root",
|
||||
}},
|
||||
Network: NetworkConfig{
|
||||
Plugin: DefaultNetworkPlugin,
|
||||
KubePodsCIDR: DefaultPodsCIDR,
|
||||
KubeServiceCIDR: DefaultServiceCIDR,
|
||||
},
|
||||
}
|
||||
return clusterInfo
|
||||
}
|
||||
}
|
||||
|
||||
func ResolveClusterInfoFile(configFile string) (*ClusterCfg, error) {
|
||||
fp, err := filepath.Abs(configFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to lookup current directory name: %v", err)
|
||||
}
|
||||
file, err := os.Open(fp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can not find cluster info file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
clusterInfo, err := GetYamlFile(configFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read file: %v", err)
|
||||
}
|
||||
|
||||
return clusterInfo, nil
|
||||
}
|
||||
|
||||
func GetYamlFile(filePath string) (*ClusterCfg, error) {
|
||||
result := ClusterCfg{}
|
||||
b, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//var m HostJson
|
||||
err = yaml.Unmarshal(b, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
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,20 +0,0 @@
|
|||
package v1alpha1
|
||||
|
||||
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:"-"`
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package install
|
||||
|
||||
import (
|
||||
kubekeyapi "github.com/pixiake/kubekey/apis/v1alpha1"
|
||||
)
|
||||
|
||||
func CreateCluster(clusterCfgFile string, addons string, pkg string) {
|
||||
kubekeyapi.GetClusterCfg(clusterCfgFile)
|
||||
}
|
||||
Loading…
Reference in New Issue