1
0
mirror of https://github.com/rancher/rke.git synced 2025-04-29 03:53:30 +00:00
rke/cmd/common.go

55 lines
1.3 KiB
Go
Raw Normal View History

package cmd
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/urfave/cli"
)
2018-05-15 17:35:52 +00:00
var commonFlags = []cli.Flag{
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",
},
}
2017-12-16 03:38:15 +00:00
func resolveClusterFile(ctx *cli.Context) (string, string, error) {
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)
}
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)
}
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)
}
clusterFileBuff := string(buf)
2017-12-16 03:38:15 +00:00
return clusterFileBuff, clusterFile, nil
}
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")
}
return rkeConfig, nil
}