1
0
mirror of https://github.com/rancher/rke.git synced 2025-04-28 03:31:24 +00:00

Refactor types

This commit is contained in:
Darren Shepherd 2017-12-05 09:55:58 -07:00
parent 4a17ce82e3
commit df7e40188e
12 changed files with 49 additions and 49 deletions

View File

@ -9,16 +9,16 @@ import (
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
"github.com/rancher/rke/services"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/cert"
)
type Cluster struct {
v1.RancherKubernetesEngineConfig `yaml:",inline"`
v3.RancherKubernetesEngineConfig `yaml:",inline"`
ConfigPath string `yaml:"config_path"`
LocalKubeConfigPath string
EtcdHosts []*hosts.Host

View File

@ -10,10 +10,10 @@ import (
"github.com/rancher/rke/cluster"
"github.com/rancher/rke/services"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
)
func ConfigCommand() cli.Command {
@ -60,7 +60,7 @@ func getConfig(reader *bufio.Reader, text, def string) (string, error) {
}
}
func writeConfig(cluster *v1.RancherKubernetesEngineConfig, configFile string, print bool) error {
func writeConfig(cluster *v3.RancherKubernetesEngineConfig, configFile string, print bool) error {
yamlConfig, err := yaml.Marshal(*cluster)
if err != nil {
return err
@ -78,14 +78,14 @@ func writeConfig(cluster *v1.RancherKubernetesEngineConfig, configFile string, p
func clusterConfig(ctx *cli.Context) error {
configFile := ctx.String("name")
print := ctx.Bool("print")
cluster := v1.RancherKubernetesEngineConfig{}
cluster := v3.RancherKubernetesEngineConfig{}
// Get cluster config from user
reader := bufio.NewReader(os.Stdin)
// Generate empty configuration file
if ctx.Bool("empty") {
cluster.Nodes = make([]v1.RKEConfigNode, 1)
cluster.Nodes = make([]v3.RKEConfigNode, 1)
return writeConfig(&cluster, configFile, print)
}
@ -106,7 +106,7 @@ func clusterConfig(ctx *cli.Context) error {
}
// Get Hosts config
cluster.Nodes = make([]v1.RKEConfigNode, 0)
cluster.Nodes = make([]v3.RKEConfigNode, 0)
for i := 0; i < numberOfHostsInt; i++ {
hostCfg, err := getHostConfig(reader, i)
if err != nil {
@ -139,8 +139,8 @@ func clusterConfig(ctx *cli.Context) error {
return writeConfig(&cluster, configFile, print)
}
func getHostConfig(reader *bufio.Reader, index int) (*v1.RKEConfigNode, error) {
host := v1.RKEConfigNode{}
func getHostConfig(reader *bufio.Reader, index int) (*v3.RKEConfigNode, error) {
host := v3.RKEConfigNode{}
address, err := getConfig(reader, fmt.Sprintf("SSH Address of host (%d)", index+1), "")
if err != nil {
@ -210,14 +210,14 @@ func getHostConfig(reader *bufio.Reader, index int) (*v1.RKEConfigNode, error) {
return &host, nil
}
func getServiceConfig(reader *bufio.Reader) (*v1.RKEConfigServices, error) {
servicesConfig := v1.RKEConfigServices{}
servicesConfig.Etcd = v1.ETCDService{}
servicesConfig.KubeAPI = v1.KubeAPIService{}
servicesConfig.KubeController = v1.KubeControllerService{}
servicesConfig.Scheduler = v1.SchedulerService{}
servicesConfig.Kubelet = v1.KubeletService{}
servicesConfig.Kubeproxy = v1.KubeproxyService{}
func getServiceConfig(reader *bufio.Reader) (*v3.RKEConfigServices, error) {
servicesConfig := v3.RKEConfigServices{}
servicesConfig.Etcd = v3.ETCDService{}
servicesConfig.KubeAPI = v3.KubeAPIService{}
servicesConfig.KubeController = v3.KubeControllerService{}
servicesConfig.Scheduler = v3.SchedulerService{}
servicesConfig.Kubelet = v3.KubeletService{}
servicesConfig.Kubeproxy = v3.KubeproxyService{}
etcdImage, err := getConfig(reader, "Etcd Docker Image", "quay.io/coreos/etcd:latest")
if err != nil {
@ -268,8 +268,8 @@ func getServiceConfig(reader *bufio.Reader) (*v1.RKEConfigServices, error) {
return &servicesConfig, nil
}
func getAuthConfig(reader *bufio.Reader) (*v1.AuthConfig, error) {
authConfig := v1.AuthConfig{}
func getAuthConfig(reader *bufio.Reader) (*v3.AuthConfig, error) {
authConfig := v3.AuthConfig{}
authType, err := getConfig(reader, "Authentication Strategy", "x509")
if err != nil {
@ -279,8 +279,8 @@ func getAuthConfig(reader *bufio.Reader) (*v1.AuthConfig, error) {
return &authConfig, nil
}
func getNetworkConfig(reader *bufio.Reader) (*v1.NetworkConfig, error) {
networkConfig := v1.NetworkConfig{}
func getNetworkConfig(reader *bufio.Reader) (*v3.NetworkConfig, error) {
networkConfig := v3.NetworkConfig{}
networkPlugin, err := getConfig(reader, "Network Plugin Type", "flannel")
if err != nil {

View File

@ -7,14 +7,14 @@ import (
"github.com/docker/docker/client"
"github.com/rancher/rke/docker"
"github.com/rancher/rke/k8s"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/kubernetes"
)
type Host struct {
v1.RKEConfigNode
v3.RKEConfigNode
DClient *client.Client
IsControl bool
IsWorker bool

View File

@ -7,7 +7,7 @@ import (
"testing"
"github.com/rancher/rke/hosts"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
const (
@ -18,7 +18,7 @@ const (
func TestPKI(t *testing.T) {
cpHosts := []*hosts.Host{
&hosts.Host{
RKEConfigNode: v1.RKEConfigNode{
RKEConfigNode: v3.RKEConfigNode{
Address: "1.1.1.1",
InternalAddress: "192.168.1.5",
Role: []string{"controlplane"},

View File

@ -2,11 +2,11 @@ package services
import (
"github.com/rancher/rke/hosts"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
)
func RunControlPlane(controlHosts []*hosts.Host, etcdHosts []*hosts.Host, controlServices v1.RKEConfigServices) error {
func RunControlPlane(controlHosts []*hosts.Host, etcdHosts []*hosts.Host, controlServices v3.RKEConfigServices) error {
logrus.Infof("[%s] Building up Controller Plane..", ControlRole)
for _, host := range controlHosts {

View File

@ -7,11 +7,11 @@ import (
"github.com/docker/go-connections/nat"
"github.com/rancher/rke/docker"
"github.com/rancher/rke/hosts"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
)
func RunEtcdPlane(etcdHosts []*hosts.Host, etcdService v1.ETCDService) error {
func RunEtcdPlane(etcdHosts []*hosts.Host, etcdService v3.ETCDService) error {
logrus.Infof("[%s] Building up Etcd Plane..", ETCDRole)
initCluster := getEtcdInitialCluster(etcdHosts)
for _, host := range etcdHosts {
@ -37,7 +37,7 @@ func RemoveEtcdPlane(etcdHosts []*hosts.Host) error {
return nil
}
func buildEtcdConfig(host *hosts.Host, etcdService v1.ETCDService, initCluster string) (*container.Config, *container.HostConfig) {
func buildEtcdConfig(host *hosts.Host, etcdService v3.ETCDService, initCluster string) (*container.Config, *container.HostConfig) {
imageCfg := &container.Config{
Image: etcdService.Image,
Cmd: []string{"/usr/local/bin/etcd",

View File

@ -8,10 +8,10 @@ import (
"github.com/rancher/rke/docker"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
func runKubeAPI(host *hosts.Host, etcdHosts []*hosts.Host, kubeAPIService v1.KubeAPIService) error {
func runKubeAPI(host *hosts.Host, etcdHosts []*hosts.Host, kubeAPIService v3.KubeAPIService) error {
etcdConnString := GetEtcdConnString(etcdHosts)
imageCfg, hostCfg := buildKubeAPIConfig(host, kubeAPIService, etcdConnString)
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeAPIContainerName, host.Address, ControlRole)
@ -21,7 +21,7 @@ func removeKubeAPI(host *hosts.Host) error {
return docker.DoRemoveContainer(host.DClient, KubeAPIContainerName, host.Address)
}
func buildKubeAPIConfig(host *hosts.Host, kubeAPIService v1.KubeAPIService, etcdConnString string) (*container.Config, *container.HostConfig) {
func buildKubeAPIConfig(host *hosts.Host, kubeAPIService v3.KubeAPIService, etcdConnString string) (*container.Config, *container.HostConfig) {
imageCfg := &container.Config{
Image: kubeAPIService.Image,
Entrypoint: []string{"kube-apiserver",

View File

@ -7,10 +7,10 @@ import (
"github.com/rancher/rke/docker"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
func runKubeController(host *hosts.Host, kubeControllerService v1.KubeControllerService) error {
func runKubeController(host *hosts.Host, kubeControllerService v3.KubeControllerService) error {
imageCfg, hostCfg := buildKubeControllerConfig(kubeControllerService)
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeControllerContainerName, host.Address, ControlRole)
}
@ -19,7 +19,7 @@ func removeKubeController(host *hosts.Host) error {
return docker.DoRemoveContainer(host.DClient, KubeControllerContainerName, host.Address)
}
func buildKubeControllerConfig(kubeControllerService v1.KubeControllerService) (*container.Config, *container.HostConfig) {
func buildKubeControllerConfig(kubeControllerService v3.KubeControllerService) (*container.Config, *container.HostConfig) {
imageCfg := &container.Config{
Image: kubeControllerService.Image,
Entrypoint: []string{"kube-controller-manager",

View File

@ -8,10 +8,10 @@ import (
"github.com/rancher/rke/docker"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
func runKubelet(host *hosts.Host, kubeletService v1.KubeletService) error {
func runKubelet(host *hosts.Host, kubeletService v3.KubeletService) error {
imageCfg, hostCfg := buildKubeletConfig(host, kubeletService)
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeletContainerName, host.Address, WorkerRole)
}
@ -20,7 +20,7 @@ func removeKubelet(host *hosts.Host) error {
return docker.DoRemoveContainer(host.DClient, KubeletContainerName, host.Address)
}
func buildKubeletConfig(host *hosts.Host, kubeletService v1.KubeletService) (*container.Config, *container.HostConfig) {
func buildKubeletConfig(host *hosts.Host, kubeletService v3.KubeletService) (*container.Config, *container.HostConfig) {
imageCfg := &container.Config{
Image: kubeletService.Image,
Entrypoint: []string{"kubelet",

View File

@ -7,10 +7,10 @@ import (
"github.com/rancher/rke/docker"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
func runKubeproxy(host *hosts.Host, kubeproxyService v1.KubeproxyService) error {
func runKubeproxy(host *hosts.Host, kubeproxyService v3.KubeproxyService) error {
imageCfg, hostCfg := buildKubeproxyConfig(host, kubeproxyService)
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeproxyContainerName, host.Address, WorkerRole)
}
@ -19,7 +19,7 @@ func removeKubeproxy(host *hosts.Host) error {
return docker.DoRemoveContainer(host.DClient, KubeproxyContainerName, host.Address)
}
func buildKubeproxyConfig(host *hosts.Host, kubeproxyService v1.KubeproxyService) (*container.Config, *container.HostConfig) {
func buildKubeproxyConfig(host *hosts.Host, kubeproxyService v3.KubeproxyService) (*container.Config, *container.HostConfig) {
imageCfg := &container.Config{
Image: kubeproxyService.Image,
Entrypoint: []string{"kube-proxy",

View File

@ -7,10 +7,10 @@ import (
"github.com/rancher/rke/docker"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
func runScheduler(host *hosts.Host, schedulerService v1.SchedulerService) error {
func runScheduler(host *hosts.Host, schedulerService v3.SchedulerService) error {
imageCfg, hostCfg := buildSchedulerConfig(host, schedulerService)
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, SchedulerContainerName, host.Address, ControlRole)
}
@ -19,7 +19,7 @@ func removeScheduler(host *hosts.Host) error {
return docker.DoRemoveContainer(host.DClient, SchedulerContainerName, host.Address)
}
func buildSchedulerConfig(host *hosts.Host, schedulerService v1.SchedulerService) (*container.Config, *container.HostConfig) {
func buildSchedulerConfig(host *hosts.Host, schedulerService v3.SchedulerService) (*container.Config, *container.HostConfig) {
imageCfg := &container.Config{
Image: schedulerService.Image,
Entrypoint: []string{"kube-scheduler",

View File

@ -2,11 +2,11 @@ package services
import (
"github.com/rancher/rke/hosts"
"github.com/rancher/types/apis/cluster.cattle.io/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
)
func RunWorkerPlane(controlHosts []*hosts.Host, workerHosts []*hosts.Host, workerServices v1.RKEConfigServices) error {
func RunWorkerPlane(controlHosts []*hosts.Host, workerHosts []*hosts.Host, workerServices v3.RKEConfigServices) error {
logrus.Infof("[%s] Building up Worker Plane..", WorkerRole)
for _, host := range controlHosts {
// only one master for now