2017-11-06 20:50:41 +00:00
|
|
|
package cluster
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/rancher/rke/k8s"
|
|
|
|
"github.com/rancher/rke/pki"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-11-08 00:32:55 +00:00
|
|
|
ClusterDNSServerIPEnvName = "RKE_DNS_SERVER"
|
2017-11-06 20:50:41 +00:00
|
|
|
ClusterDomainEnvName = "RKE_CLUSTER_DOMAIN"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Cluster) DeployK8sAddOns() error {
|
2017-11-08 00:32:55 +00:00
|
|
|
err := c.deployKubeDNS()
|
|
|
|
return err
|
2017-11-06 20:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
2017-11-08 00:32:55 +00:00
|
|
|
fmt.Sprintf("%s=%s", ClusterDNSServerIPEnvName, c.ClusterDNSServer),
|
2017-11-06 20:50:41 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|