Skip to content

Commit

Permalink
Merge pull request #297 from drallgood/worker-init
Browse files Browse the repository at this point in the history
adding cloud-init script to add-worker cmd
  • Loading branch information
xetys authored Nov 28, 2019
2 parents bb96f50 + fd58c4e commit 17356c0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/cluster_add_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -41,6 +42,13 @@ You can specify the worker server type as in cluster create.`,
return errors.New("flag --worker-server-type is required")
}

var cloudInit string
if cloudInit, _ = cmd.Flags().GetString("cloud-init"); cloudInit != "" {
if _, err := os.Stat(cloudInit); os.IsNotExist(err) {
return errors.New("cloud-init file not found")
}
}

if err != nil {
return err
}
Expand All @@ -53,6 +61,7 @@ You can specify the worker server type as in cluster create.`,
_, cluster := AppConf.Config.FindClusterByName(name)
workerServerType, _ := cmd.Flags().GetString("worker-server-type")
datacenters, _ := cmd.Flags().GetStringSlice("datacenters")
cloudInit, _ := cmd.Flags().GetString("cloud-init")
var sshKeyName string

for _, node := range cluster.Nodes {
Expand All @@ -66,6 +75,10 @@ You can specify the worker server type as in cluster create.`,
log.Fatal("master not found")
}

if cloudInit != "" {
cluster.CloudInitFile = cloudInit
}

maxNo := 0
for _, node := range cluster.Nodes {
if !node.IsMaster {
Expand Down Expand Up @@ -133,4 +146,5 @@ func init() {
clusterAddWorkerCmd.Flags().String("worker-server-type", "cx11", "Server type used of workers")
clusterAddWorkerCmd.Flags().IntP("nodes", "n", 2, "Number of nodes for the cluster")
clusterAddWorkerCmd.Flags().StringSlice("datacenters", []string{"fsn1-dc8", "nbg1-dc3", "hel1-dc2", "fsn1-dc14"}, "Can be used to filter datacenters by their name")
clusterAddWorkerCmd.Flags().StringP("cloud-init", "", "", "Cloud-init file for node preconfiguration")
}

0 comments on commit 17356c0

Please sign in to comment.