2017-11-28 11:26:15 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2018-03-06 00:52:43 +00:00
|
|
|
"github.com/rancher/types/apis/management.cattle.io/v3"
|
2017-11-28 11:26:15 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2018-05-15 17:35:52 +00:00
|
|
|
var commonFlags = []cli.Flag{
|
2018-03-06 00:52:43 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "ssh-agent-auth",
|
|
|
|
Usage: "Use SSH Agent Auth defined by SSH_AUTH_SOCK",
|
|
|
|
},
|
2018-05-15 17:35:52 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "ignore-docker-version",
|
|
|
|
Usage: "Disable Docker version check",
|
|
|
|
},
|
2018-03-06 00:52:43 +00:00
|
|
|
}
|
|
|
|
|
2017-12-16 03:38:15 +00:00
|
|
|
func resolveClusterFile(ctx *cli.Context) (string, string, error) {
|
2017-11-28 11:26:15 +00:00
|
|
|
clusterFile := ctx.String("config")
|
|
|
|
fp, err := filepath.Abs(clusterFile)
|
|
|
|
if err != nil {
|
2017-12-16 03:38:15 +00:00
|
|
|
return "", "", fmt.Errorf("failed to lookup current directory name: %v", err)
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
file, err := os.Open(fp)
|
|
|
|
if err != nil {
|
2017-12-16 03:38:15 +00:00
|
|
|
return "", "", fmt.Errorf("Can not find cluster configuration file: %v", err)
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
buf, err := ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
2017-12-16 03:38:15 +00:00
|
|
|
return "", "", fmt.Errorf("failed to read file: %v", err)
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
|
|
|
clusterFileBuff := string(buf)
|
2017-12-16 03:38:15 +00:00
|
|
|
return clusterFileBuff, clusterFile, nil
|
2017-11-28 11:26:15 +00:00
|
|
|
}
|
2018-03-06 00:52:43 +00:00
|
|
|
|
|
|
|
func setOptionsFromCLI(c *cli.Context, rkeConfig *v3.RancherKubernetesEngineConfig) (*v3.RancherKubernetesEngineConfig, error) {
|
|
|
|
// If true... override the file.. else let file value go through
|
|
|
|
if c.Bool("ssh-agent-auth") {
|
|
|
|
rkeConfig.SSHAgentAuth = c.Bool("ssh-agent-auth")
|
|
|
|
}
|
2018-05-15 17:35:52 +00:00
|
|
|
|
|
|
|
if c.Bool("ignore-docker-version") {
|
|
|
|
rkeConfig.IgnoreDockerVersion = c.Bool("ignore-docker-version")
|
|
|
|
}
|
|
|
|
|
2018-03-06 00:52:43 +00:00
|
|
|
return rkeConfig, nil
|
|
|
|
}
|