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 (