1
0
mirror of https://github.com/rancher/rke.git synced 2025-09-17 23:49:06 +00:00

Use RKE cluster controller structures

This commit is contained in:
galal-hussein
2017-11-09 21:50:49 +02:00
parent ad69078b06
commit 3cfe3d7ea8
17 changed files with 66 additions and 101 deletions

View File

@@ -1,4 +1,5 @@
---
auth_type: x509
network_plugin: flannel
hosts:
- hostname: server1

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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))

View File

@@ -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

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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"`
}

View File

@@ -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

View File

@@ -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