From fce6b15f1869bb537f2c9f7ca4bebd7da27d25ac Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Mon, 26 Feb 2018 16:27:07 -0700 Subject: [PATCH] Add ability to deploy jobs with kubectl and not job task This API is used solely in rancher local clusters. --- cluster/addons.go | 14 ++++++++++++++ cluster/cluster.go | 1 + 2 files changed, 15 insertions(+) diff --git a/cluster/addons.go b/cluster/addons.go index cda00a6a..31a8dacc 100644 --- a/cluster/addons.go +++ b/cluster/addons.go @@ -1,8 +1,11 @@ package cluster import ( + "bytes" "context" "fmt" + "os" + "os/exec" "time" "github.com/rancher/rke/addons" @@ -66,10 +69,21 @@ func (c *Cluster) deployKubeDNS(ctx context.Context) error { } log.Infof(ctx, "[addons] KubeDNS deployed successfully..") return nil +} +func (c *Cluster) deployWithKubectl(ctx context.Context, addonYaml string) error { + buf := bytes.NewBufferString(addonYaml) + cmd := exec.Command("kubectl", "--kubeconfig", c.LocalKubeConfigPath, "apply", "-f", "-") + cmd.Stdin = buf + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() } func (c *Cluster) doAddonDeploy(ctx context.Context, addonYaml, resourceName string) error { + if c.UseKubectlDeploy { + return c.deployWithKubectl(ctx, addonYaml) + } err := c.StoreAddonConfigMap(ctx, addonYaml, resourceName) if err != nil { diff --git a/cluster/cluster.go b/cluster/cluster.go index e5834124..5574bc37 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -40,6 +40,7 @@ type Cluster struct { LocalConnDialerFactory hosts.DialerFactory PrivateRegistriesMap map[string]v3.PrivateRegistry K8sWrapTransport k8s.WrapTransport + UseKubectlDeploy bool } const (