diff --git a/cluster.yml b/cluster.yml index 5060abee..6b95ae38 100644 --- a/cluster.yml +++ b/cluster.yml @@ -1,4 +1,5 @@ --- +auth_type: x509 network_plugin: flannel hosts: - hostname: server1 diff --git a/cluster/certificates.go b/cluster/certificates.go index 30df41f1..43232eca 100644 --- a/cluster/certificates.go +++ b/cluster/certificates.go @@ -12,8 +12,8 @@ import ( "k8s.io/client-go/util/cert" ) -func SetUpAuthentication(kubeCluster, currentCluster *Cluster, authType string) error { - if authType == X509AuthenticationProvider { +func SetUpAuthentication(kubeCluster, currentCluster *Cluster) error { + if kubeCluster.AuthType == X509AuthenticationProvider { var err error if currentCluster != nil { kubeCluster.Certificates, err = getClusterCerts(kubeCluster.KubeClient) diff --git a/cluster/cluster.go b/cluster/cluster.go index d57f4ccc..d4858bcf 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -5,6 +5,7 @@ import ( "net" "github.com/Sirupsen/logrus" + "github.com/alena1108/cluster-controller/client/v1" "github.com/rancher/rke/hosts" "github.com/rancher/rke/pki" "github.com/rancher/rke/services" @@ -13,8 +14,7 @@ import ( ) type Cluster struct { - Services services.Services `yaml:"services"` - Hosts []hosts.Host `yaml:"hosts"` + v1.RKEConfig `yaml:",inline"` EtcdHosts []hosts.Host WorkerHosts []hosts.Host ControlPlaneHosts []hosts.Host @@ -22,7 +22,6 @@ type Cluster struct { KubernetesServiceIP net.IP Certificates map[string]pki.CertificatePKI ClusterDomain string - NetworkPlugin string `yaml:"network_plugin"` ClusterCIDR string ClusterDNSServer string } diff --git a/cluster/hosts.go b/cluster/hosts.go index f675c396..1ec786c8 100644 --- a/cluster/hosts.go +++ b/cluster/hosts.go @@ -38,13 +38,16 @@ func (c *Cluster) InvertIndexHosts() error { for _, host := range c.Hosts { for _, role := range host.Role { logrus.Debugf("Host: " + host.Hostname + " has role: " + role) + newHost := hosts.Host{ + RKEConfigHost: host, + } switch role { case services.ETCDRole: - c.EtcdHosts = append(c.EtcdHosts, host) + c.EtcdHosts = append(c.EtcdHosts, newHost) case services.ControlRole: - c.ControlPlaneHosts = append(c.ControlPlaneHosts, host) + c.ControlPlaneHosts = append(c.ControlPlaneHosts, newHost) case services.WorkerRole: - c.WorkerHosts = append(c.WorkerHosts, host) + c.WorkerHosts = append(c.WorkerHosts, newHost) default: return fmt.Errorf("Failed to recognize host [%s] role %s", host.Hostname, role) } @@ -53,8 +56,8 @@ func (c *Cluster) InvertIndexHosts() error { return nil } -func (c *Cluster) SetUpHosts(authType string) error { - if authType == X509AuthenticationProvider { +func (c *Cluster) SetUpHosts() error { + if c.AuthType == X509AuthenticationProvider { logrus.Infof("[certificates] Deploying kubernetes certificates to Cluster nodes") err := pki.DeployCertificatesOnMasters(c.ControlPlaneHosts, c.Certificates) if err != nil { diff --git a/cmd/cluster.go b/cmd/cluster.go index 6f751375..aaf75ffd 100644 --- a/cmd/cluster.go +++ b/cmd/cluster.go @@ -21,12 +21,6 @@ func ClusterCommand() cli.Command { Value: "cluster.yml", EnvVar: "CLUSTER_FILE", }, - cli.StringFlag{ - Name: "auth-type", - Usage: "Specify authentication type", - Value: "x509", - EnvVar: "AUTH_TYPE", - }, } return cli.Command{ Name: "cluster", @@ -44,7 +38,7 @@ func ClusterCommand() cli.Command { } } -func ClusterUp(clusterFile, authType string) (string, string, string, string, error) { +func ClusterUp(clusterFile string) (string, string, string, string, error) { logrus.Infof("Building Kubernetes cluster") var APIURL, caCrt, clientCert, clientKey string kubeCluster, err := cluster.ParseConfig(clusterFile) @@ -62,12 +56,12 @@ func ClusterUp(clusterFile, authType string) (string, string, string, string, er return APIURL, caCrt, clientCert, clientKey, err } - err = cluster.SetUpAuthentication(kubeCluster, currentCluster, authType) + err = cluster.SetUpAuthentication(kubeCluster, currentCluster) if err != nil { return APIURL, caCrt, clientCert, clientKey, err } - err = kubeCluster.SetUpHosts(authType) + err = kubeCluster.SetUpHosts() if err != nil { return APIURL, caCrt, clientCert, clientKey, err } @@ -99,12 +93,11 @@ func ClusterUp(clusterFile, authType string) (string, string, string, string, er } func clusterUpFromCli(ctx *cli.Context) error { - authType := ctx.String("auth-type") clusterFile, err := resolveClusterFile(ctx) if err != nil { return fmt.Errorf("Failed to resolve cluster file: %v", err) } - _, _, _, _, err = ClusterUp(clusterFile, authType) + _, _, _, _, err = ClusterUp(clusterFile) return err } diff --git a/hosts/hosts.go b/hosts/hosts.go index 3492b17f..511b818b 100644 --- a/hosts/hosts.go +++ b/hosts/hosts.go @@ -2,19 +2,15 @@ package hosts import ( "github.com/Sirupsen/logrus" + "github.com/alena1108/cluster-controller/client/v1" "github.com/docker/docker/client" "github.com/rancher/rke/k8s" "k8s.io/client-go/kubernetes" ) type Host struct { - IP string `yaml:"ip"` - AdvertiseAddress string `yaml:"advertise_address"` - Role []string `yaml:"role"` - Hostname string `yaml:"hostname"` - User string `yaml:"user"` - DockerSocket string `yaml:"docker_socket"` - DClient *client.Client + v1.RKEConfigHost + DClient *client.Client } func ReconcileWorkers(currentWorkers []Host, newWorkers []Host, kubeClient *kubernetes.Clientset) error { diff --git a/pki/pki_test.go b/pki/pki_test.go index c290b39b..3db28cf9 100644 --- a/pki/pki_test.go +++ b/pki/pki_test.go @@ -6,6 +6,7 @@ import ( "net" "testing" + "github.com/alena1108/cluster-controller/client/v1" "github.com/rancher/rke/hosts" ) @@ -17,10 +18,13 @@ const ( func TestPKI(t *testing.T) { cpHosts := []hosts.Host{ hosts.Host{ - IP: "1.1.1.1", - AdvertiseAddress: "192.168.1.5", - Role: []string{"controlplane"}, - Hostname: "server1", + RKEConfigHost: v1.RKEConfigHost{ + IP: "1.1.1.1", + AdvertiseAddress: "192.168.1.5", + Role: []string{"controlplane"}, + Hostname: "server1", + }, + DClient: nil, }, } certificateMap, err := StartCertificatesGeneration(cpHosts, cpHosts, FakeClusterDomain, net.ParseIP(FakeKubernetesServiceIP)) diff --git a/services/controlplane.go b/services/controlplane.go index 50f4e417..03716a2b 100644 --- a/services/controlplane.go +++ b/services/controlplane.go @@ -2,10 +2,11 @@ package services import ( "github.com/Sirupsen/logrus" + "github.com/alena1108/cluster-controller/client/v1" "github.com/rancher/rke/hosts" ) -func RunControlPlane(controlHosts []hosts.Host, etcdHosts []hosts.Host, controlServices Services) error { +func RunControlPlane(controlHosts []hosts.Host, etcdHosts []hosts.Host, controlServices v1.RKEConfigServices) error { logrus.Infof("[%s] Building up Controller Plane..", ControlRole) for _, host := range controlHosts { // run kubeapi diff --git a/services/etcd.go b/services/etcd.go index d33abe69..c02d54c2 100644 --- a/services/etcd.go +++ b/services/etcd.go @@ -2,13 +2,14 @@ package services import ( "github.com/Sirupsen/logrus" + "github.com/alena1108/cluster-controller/client/v1" "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" "github.com/rancher/rke/docker" "github.com/rancher/rke/hosts" ) -func RunEtcdPlane(etcdHosts []hosts.Host, etcdService Etcd) error { +func RunEtcdPlane(etcdHosts []hosts.Host, etcdService v1.ETCDService) error { logrus.Infof("[%s] Building up Etcd Plane..", ETCDRole) for _, host := range etcdHosts { imageCfg, hostCfg := buildEtcdConfig(host, etcdService) @@ -21,7 +22,7 @@ func RunEtcdPlane(etcdHosts []hosts.Host, etcdService Etcd) error { return nil } -func buildEtcdConfig(host hosts.Host, etcdService Etcd) (*container.Config, *container.HostConfig) { +func buildEtcdConfig(host hosts.Host, etcdService v1.ETCDService) (*container.Config, *container.HostConfig) { imageCfg := &container.Config{ Image: etcdService.Image, Cmd: []string{"/usr/local/bin/etcd", diff --git a/services/kubeapi.go b/services/kubeapi.go index a4e94c28..7ee30856 100644 --- a/services/kubeapi.go +++ b/services/kubeapi.go @@ -1,6 +1,7 @@ package services import ( + "github.com/alena1108/cluster-controller/client/v1" "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" "github.com/rancher/rke/docker" @@ -8,13 +9,13 @@ import ( "github.com/rancher/rke/pki" ) -func runKubeAPI(host hosts.Host, etcdHosts []hosts.Host, kubeAPIService KubeAPI) error { +func runKubeAPI(host hosts.Host, etcdHosts []hosts.Host, kubeAPIService v1.KubeAPIService) error { etcdConnString := getEtcdConnString(etcdHosts) imageCfg, hostCfg := buildKubeAPIConfig(host, kubeAPIService, etcdConnString) return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeAPIContainerName, host.Hostname, ControlRole) } -func buildKubeAPIConfig(host hosts.Host, kubeAPIService KubeAPI, etcdConnString string) (*container.Config, *container.HostConfig) { +func buildKubeAPIConfig(host hosts.Host, kubeAPIService v1.KubeAPIService, etcdConnString string) (*container.Config, *container.HostConfig) { imageCfg := &container.Config{ Image: kubeAPIService.Image, Cmd: []string{"/hyperkube", diff --git a/services/kubecontroller.go b/services/kubecontroller.go index f33b198c..0ed04462 100644 --- a/services/kubecontroller.go +++ b/services/kubecontroller.go @@ -1,18 +1,19 @@ package services import ( + "github.com/alena1108/cluster-controller/client/v1" "github.com/docker/docker/api/types/container" "github.com/rancher/rke/docker" "github.com/rancher/rke/hosts" "github.com/rancher/rke/pki" ) -func runKubeController(host hosts.Host, kubeControllerService KubeController) error { +func runKubeController(host hosts.Host, kubeControllerService v1.KubeControllerService) error { imageCfg, hostCfg := buildKubeControllerConfig(kubeControllerService) return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeControllerContainerName, host.Hostname, ControlRole) } -func buildKubeControllerConfig(kubeControllerService KubeController) (*container.Config, *container.HostConfig) { +func buildKubeControllerConfig(kubeControllerService v1.KubeControllerService) (*container.Config, *container.HostConfig) { imageCfg := &container.Config{ Image: kubeControllerService.Image, Cmd: []string{"/hyperkube", diff --git a/services/kubelet.go b/services/kubelet.go index a050d79a..082a75ad 100644 --- a/services/kubelet.go +++ b/services/kubelet.go @@ -1,6 +1,7 @@ package services import ( + "github.com/alena1108/cluster-controller/client/v1" "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" "github.com/rancher/rke/docker" @@ -8,12 +9,12 @@ import ( "github.com/rancher/rke/pki" ) -func runKubelet(host hosts.Host, kubeletService Kubelet, isMaster bool) error { +func runKubelet(host hosts.Host, kubeletService v1.KubeletService, isMaster bool) error { imageCfg, hostCfg := buildKubeletConfig(host, kubeletService, isMaster) return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeletContainerName, host.Hostname, WorkerRole) } -func buildKubeletConfig(host hosts.Host, kubeletService Kubelet, isMaster bool) (*container.Config, *container.HostConfig) { +func buildKubeletConfig(host hosts.Host, kubeletService v1.KubeletService, isMaster bool) (*container.Config, *container.HostConfig) { imageCfg := &container.Config{ Image: kubeletService.Image, Cmd: []string{"/hyperkube", diff --git a/services/kubeproxy.go b/services/kubeproxy.go index fa304a46..69add76a 100644 --- a/services/kubeproxy.go +++ b/services/kubeproxy.go @@ -1,18 +1,19 @@ package services import ( + "github.com/alena1108/cluster-controller/client/v1" "github.com/docker/docker/api/types/container" "github.com/rancher/rke/docker" "github.com/rancher/rke/hosts" "github.com/rancher/rke/pki" ) -func runKubeproxy(host hosts.Host, kubeproxyService Kubeproxy) error { +func runKubeproxy(host hosts.Host, kubeproxyService v1.KubeproxyService) error { imageCfg, hostCfg := buildKubeproxyConfig(host, kubeproxyService) return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeproxyContainerName, host.Hostname, WorkerRole) } -func buildKubeproxyConfig(host hosts.Host, kubeproxyService Kubeproxy) (*container.Config, *container.HostConfig) { +func buildKubeproxyConfig(host hosts.Host, kubeproxyService v1.KubeproxyService) (*container.Config, *container.HostConfig) { imageCfg := &container.Config{ Image: kubeproxyService.Image, Cmd: []string{"/hyperkube", diff --git a/services/scheduler.go b/services/scheduler.go index 7fe7e6a0..4dcbf87f 100644 --- a/services/scheduler.go +++ b/services/scheduler.go @@ -1,18 +1,19 @@ package services import ( + "github.com/alena1108/cluster-controller/client/v1" "github.com/docker/docker/api/types/container" "github.com/rancher/rke/docker" "github.com/rancher/rke/hosts" "github.com/rancher/rke/pki" ) -func runScheduler(host hosts.Host, schedulerService Scheduler) error { +func runScheduler(host hosts.Host, schedulerService v1.SchedulerService) error { imageCfg, hostCfg := buildSchedulerConfig(host, schedulerService) return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, SchedulerContainerName, host.Hostname, ControlRole) } -func buildSchedulerConfig(host hosts.Host, schedulerService Scheduler) (*container.Config, *container.HostConfig) { +func buildSchedulerConfig(host hosts.Host, schedulerService v1.SchedulerService) (*container.Config, *container.HostConfig) { imageCfg := &container.Config{ Image: schedulerService.Image, Cmd: []string{"/hyperkube", diff --git a/services/types.go b/services/types.go deleted file mode 100644 index 093e5db4..00000000 --- a/services/types.go +++ /dev/null @@ -1,40 +0,0 @@ -package services - -type Services struct { - Etcd Etcd `yaml:"etcd"` - KubeAPI KubeAPI `yaml:"kube-api"` - KubeController KubeController `yaml:"kube-controller"` - Scheduler Scheduler `yaml:"scheduler"` - Kubelet Kubelet `yaml:"kubelet"` - Kubeproxy Kubeproxy `yaml:"kubeproxy"` -} - -type Etcd struct { - Image string `yaml:"image"` -} - -type KubeAPI struct { - Image string `yaml:"image"` - ServiceClusterIPRange string `yaml:"service_cluster_ip_range"` -} - -type KubeController struct { - Image string `yaml:"image"` - ClusterCIDR string `yaml:"cluster_cidr"` - ServiceClusterIPRange string `yaml:"service_cluster_ip_range"` -} - -type Kubelet struct { - Image string `yaml:"image"` - ClusterDomain string `yaml:"cluster_domain"` - InfraContainerImage string `yaml:"infra_container_image"` - ClusterDNSServer string `yaml:"cluster_dns_server"` -} - -type Kubeproxy struct { - Image string `yaml:"image"` -} - -type Scheduler struct { - Image string `yaml:"image"` -} diff --git a/services/workerplane.go b/services/workerplane.go index 2c014c3c..d6e7c0a4 100644 --- a/services/workerplane.go +++ b/services/workerplane.go @@ -2,10 +2,11 @@ package services import ( "github.com/Sirupsen/logrus" + "github.com/alena1108/cluster-controller/client/v1" "github.com/rancher/rke/hosts" ) -func RunWorkerPlane(controlHosts []hosts.Host, workerHosts []hosts.Host, workerServices Services) error { +func RunWorkerPlane(controlHosts []hosts.Host, workerHosts []hosts.Host, workerServices v1.RKEConfigServices) error { logrus.Infof("[%s] Building up Worker Plane..", WorkerRole) for _, host := range controlHosts { // only one master for now diff --git a/vendor.conf b/vendor.conf index ba185c72..8293eee4 100644 --- a/vendor.conf +++ b/vendor.conf @@ -1,18 +1,19 @@ # package github.com/rancher/rke -github.com/Sirupsen/logrus v0.10.0 -github.com/urfave/cli v1.18.0 -golang.org/x/crypto 2509b142fb2b797aa7587dad548f113b2c0f20ce -gopkg.in/yaml.v2 eb3733d160e74a9c7e442f435eb3bea458e1d19f -github.com/docker/docker ecf4125b85e0faa57d2739348e0d453c1d24d10c -github.com/docker/distribution 3800056b8832cf6075e78b282ac010131d8687bc -github.com/docker/go-connections 3ede32e2033de7505e6500d6c868c2b9ed9f169d -github.com/docker/go-units 0dadbb0345b35ec7ef35e228dabb8de89a65bf52 -golang.org/x/net 186fd3fc8194a5e9980a82230d69c1ff7134229f -github.com/opencontainers/go-digest 279bed98673dd5bef374d3b6e4b09e2af76183bf -github.com/gogo/protobuf 117892bf1866fbaa2318c03e50e40564c8845457 -github.com/opencontainers/image-spec 7c889fafd04a893f5c5f50b7ab9963d5d64e5242 -github.com/pkg/errors f15c970de5b76fac0b59abb32d62c17cc7bed265 -k8s.io/client-go v4.0.0 transitive=true -gopkg.in/check.v1 11d3bc7aa68e238947792f30573146a3231fc0f1 +github.com/Sirupsen/logrus v0.10.0 +github.com/urfave/cli v1.18.0 +golang.org/x/crypto 2509b142fb2b797aa7587dad548f113b2c0f20ce +gopkg.in/yaml.v2 eb3733d160e74a9c7e442f435eb3bea458e1d19f +github.com/docker/docker ecf4125b85e0faa57d2739348e0d453c1d24d10c +github.com/docker/distribution 3800056b8832cf6075e78b282ac010131d8687bc +github.com/docker/go-connections 3ede32e2033de7505e6500d6c868c2b9ed9f169d +github.com/docker/go-units 0dadbb0345b35ec7ef35e228dabb8de89a65bf52 +golang.org/x/net 186fd3fc8194a5e9980a82230d69c1ff7134229f +github.com/opencontainers/go-digest 279bed98673dd5bef374d3b6e4b09e2af76183bf +github.com/gogo/protobuf 117892bf1866fbaa2318c03e50e40564c8845457 +github.com/opencontainers/image-spec 7c889fafd04a893f5c5f50b7ab9963d5d64e5242 +github.com/pkg/errors f15c970de5b76fac0b59abb32d62c17cc7bed265 +k8s.io/client-go v4.0.0 transitive=true +gopkg.in/check.v1 11d3bc7aa68e238947792f30573146a3231fc0f1 +github.com/alena1108/cluster-controller 85168a7fe249bf97f703afe53f03d3654cc70350