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

Merge pull request #2 from moelsayed/add_network_plugin_support

add network plugin support
This commit is contained in:
Alena Prokharchyk
2017-11-07 16:03:19 -08:00
committed by GitHub
13 changed files with 504 additions and 1 deletions

42
cluster/addons.go Normal file
View File

@@ -0,0 +1,42 @@
package cluster
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/rancher/rke/k8s"
"github.com/rancher/rke/pki"
)
const (
ClusterDnsServerIPEnvName = "RKE_DNS_SERVER"
ClusterDomainEnvName = "RKE_CLUSTER_DOMAIN"
)
func (c *Cluster) DeployK8sAddOns() error {
if err := c.deployKubeDNS(); err != nil {
return err
}
return nil
}
func (c *Cluster) deployKubeDNS() error {
logrus.Infof("[plugins] Setting up KubeDNS")
deployerHost := c.ControlPlaneHosts[0]
kubectlCmd := []string{"apply -f /addons/kubedns*.yaml"}
env := []string{
fmt.Sprintf("%s=%s", pki.KubeAdminConfigENVName, c.Certificates[pki.KubeAdminCommonName].Config),
fmt.Sprintf("%s=%s", ClusterDnsServerIPEnvName, c.ClusterDnsServer),
fmt.Sprintf("%s=%s", ClusterDomainEnvName, c.ClusterDomain),
}
logrus.Infof("[plugins] Executing the deploy command..")
err := k8s.RunKubectlCmd(deployerHost.DClient, deployerHost.Hostname, kubectlCmd, env)
if err != nil {
return fmt.Errorf("Failed to run kubectl command: %v", err)
}
logrus.Infof("[plugins] kubeDNS deployed successfully..")
return nil
}

View File

@@ -22,6 +22,9 @@ type Cluster struct {
KubernetesServiceIP net.IP
Certificates map[string]pki.CertificatePKI
ClusterDomain string
NetworkPlugin string `yaml:"network_plugin"`
ClusterCIDR string
ClusterDnsServer string
}
const (
@@ -65,6 +68,8 @@ func ParseConfig(clusterFile string) (*Cluster, error) {
return nil, fmt.Errorf("Failed to get Kubernetes Service IP: %v", err)
}
c.ClusterDomain = c.Services.Kubelet.ClusterDomain
c.ClusterCIDR = c.Services.KubeController.ClusterCIDR
c.ClusterDnsServer = c.Services.Kubelet.ClusterDnsServer
return c, nil
}

30
cluster/network.go Normal file
View File

@@ -0,0 +1,30 @@
package cluster
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/rancher/rke/k8s"
"github.com/rancher/rke/pki"
)
const (
ClusterCIDREnvName = "RKE_CLUSTER_CIDR"
)
func (c *Cluster) DeployNetworkPlugin() error {
logrus.Infof("[network] Setting up network plugin: %s", c.NetworkPlugin)
deployerHost := c.ControlPlaneHosts[0]
kubectlCmd := []string{"apply -f /network/" + c.NetworkPlugin + ".yaml"}
env := []string{
fmt.Sprintf("%s=%s", pki.KubeAdminConfigENVName, c.Certificates[pki.KubeAdminCommonName].Config),
fmt.Sprintf("%s=%s", ClusterCIDREnvName, c.ClusterCIDR),
}
logrus.Infof("[network] Executing the deploy command..")
err := k8s.RunKubectlCmd(deployerHost.DClient, deployerHost.Hostname, kubectlCmd, env)
if err != nil {
return fmt.Errorf("Failed to run kubectl command: %v", err)
}
logrus.Infof("[network] Network plugin deployed successfully..")
return nil
}