Merge pull request #61 from andyz-dev/always-on
[Feature] Implement --always-on flag for the create command
This commit is contained in:
commit
6dfb1e054b
@ -122,6 +122,7 @@ func CreateCluster(c *cli.Context) error {
|
||||
c.String("name"),
|
||||
c.StringSlice("volume"),
|
||||
portmap,
|
||||
c.Bool("auto-restart"),
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: failed to create cluster\n%+v", err)
|
||||
@ -196,6 +197,7 @@ func CreateCluster(c *cli.Context) error {
|
||||
c.String("api-port"),
|
||||
portmap,
|
||||
c.Int("port-auto-offset"),
|
||||
c.Bool("auto-restart"),
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: failed to create worker node for cluster %s\n%+v", c.String("name"), err)
|
||||
|
||||
@ -63,7 +63,7 @@ func startContainer(verbose bool, config *container.Config, hostConfig *containe
|
||||
}
|
||||
|
||||
func createServer(verbose bool, image string, apiPort string, args []string, env []string,
|
||||
name string, volumes []string, nodeToPortSpecMap map[string][]string) (string, error) {
|
||||
name string, volumes []string, nodeToPortSpecMap map[string][]string, autoRestart bool) (string, error) {
|
||||
log.Printf("Creating server using %s...\n", image)
|
||||
|
||||
containerLabels := make(map[string]string)
|
||||
@ -95,6 +95,10 @@ func createServer(verbose bool, image string, apiPort string, args []string, env
|
||||
Privileged: true,
|
||||
}
|
||||
|
||||
if autoRestart {
|
||||
hostConfig.RestartPolicy.Name = "unless-stopped"
|
||||
}
|
||||
|
||||
if len(volumes) > 0 && volumes[0] != "" {
|
||||
hostConfig.Binds = volumes
|
||||
}
|
||||
@ -125,7 +129,7 @@ func createServer(verbose bool, image string, apiPort string, args []string, env
|
||||
|
||||
// createWorker creates/starts a k3s agent node that connects to the server
|
||||
func createWorker(verbose bool, image string, args []string, env []string, name string, volumes []string,
|
||||
postfix int, serverPort string, nodeToPortSpecMap map[string][]string, portAutoOffset int) (string, error) {
|
||||
postfix int, serverPort string, nodeToPortSpecMap map[string][]string, portAutoOffset int, autoRestart bool) (string, error) {
|
||||
containerLabels := make(map[string]string)
|
||||
containerLabels["app"] = "k3d"
|
||||
containerLabels["component"] = "worker"
|
||||
@ -161,6 +165,10 @@ func createWorker(verbose bool, image string, args []string, env []string, name
|
||||
Privileged: true,
|
||||
}
|
||||
|
||||
if autoRestart {
|
||||
hostConfig.RestartPolicy.Name = "unless-stopped"
|
||||
}
|
||||
|
||||
if len(volumes) > 0 && volumes[0] != "" {
|
||||
hostConfig.Binds = volumes
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user