Move more code into the local host implementation.
parent
2ab1566282
commit
5b5442be11
|
|
@ -57,7 +57,7 @@ var addonsOpenCmd = &cobra.Command{
|
|||
}
|
||||
addonName := args[0]
|
||||
//TODO(r2d4): config should not reference API, pull this out
|
||||
api, err := machine.NewAPIClient(GetClientType())
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
"k8s.io/minikube/pkg/minikube/assets"
|
||||
"k8s.io/minikube/pkg/minikube/cluster"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
|
|
@ -82,13 +81,6 @@ func SetBool(m config.MinikubeConfig, name string, val string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func GetClientType() machine.ClientType {
|
||||
if viper.GetBool(useVendoredDriver) {
|
||||
return machine.ClientTypeLocal
|
||||
}
|
||||
return machine.ClientTypeRPC
|
||||
}
|
||||
|
||||
func EnableOrDisableAddon(name string, val string) error {
|
||||
|
||||
enable, err := strconv.ParseBool(val)
|
||||
|
|
@ -97,7 +89,7 @@ func EnableOrDisableAddon(name string, val string) error {
|
|||
}
|
||||
|
||||
//TODO(r2d4): config package should not reference API, pull this out
|
||||
api, err := machine.NewAPIClient(GetClientType())
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ var dashboardCmd = &cobra.Command{
|
|||
Short: "Opens/displays the kubernetes dashboard URL for your local cluster",
|
||||
Long: `Opens/displays the kubernetes dashboard URL for your local cluster`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ var deleteCmd = &cobra.Command{
|
|||
associated files.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("Deleting local Kubernetes cluster...")
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ var dockerEnvCmd = &cobra.Command{
|
|||
Long: `sets up docker env variables; similar to '$(docker-machine env)'`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ var ipCmd = &cobra.Command{
|
|||
Short: "Retrieve the IP address of the running cluster.",
|
||||
Long: `Retrieves the IP address of the running cluster, and writes it to STDOUT.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ var logsCmd = &cobra.Command{
|
|||
Short: "Gets the logs of the running localkube instance, used for debugging minikube, not user code",
|
||||
Long: `Gets the logs of the running localkube instance, used for debugging minikube, not user code.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ var mountCmd = &cobra.Command{
|
|||
if glog.V(1) {
|
||||
debugVal = 1 // ufs.StartServer takes int debug param
|
||||
}
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -95,9 +95,6 @@ Please use --v=3 to show libmachine logs, and --v=7 for debug level libmachine l
|
|||
`)
|
||||
}
|
||||
|
||||
//TODO(r2d4): config should not reference API
|
||||
clientType = configCmd.GetClientType()
|
||||
|
||||
logDir := pflag.Lookup("log_dir")
|
||||
if !logDir.Changed {
|
||||
logDir.Value.Set(constants.MakeMiniPath("logs"))
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ var serviceCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
svc := args[0]
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ var serviceListCmd = &cobra.Command{
|
|||
Short: "Lists the URLs for the services in your local cluster",
|
||||
Long: `Lists the URLs for the services in your local cluster`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ var sshCmd = &cobra.Command{
|
|||
Short: "Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'",
|
||||
Long: "Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ assumes you have already installed one of the VM drivers: virtualbox/vmwarefusio
|
|||
}
|
||||
|
||||
func runStart(cmd *cobra.Command, args []string) {
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ var statusCmd = &cobra.Command{
|
|||
Short: "Gets the status of a local kubernetes cluster",
|
||||
Long: `Gets the status of a local kubernetes cluster.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ var stopCmd = &cobra.Command{
|
|||
itself, leaving all files intact. The cluster can be started again with the "start" command.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("Stopping local Kubernetes cluster...")
|
||||
api, err := machine.NewAPIClient(clientType)
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -58,9 +58,10 @@ type localClientFactory struct{}
|
|||
|
||||
func (*localClientFactory) NewClient(storePath, certsDir string) libmachine.API {
|
||||
return &LocalClient{
|
||||
certsDir: certsDir,
|
||||
storePath: storePath,
|
||||
Filestore: persist.NewFilestore(storePath, certsDir, certsDir),
|
||||
certsDir: certsDir,
|
||||
storePath: storePath,
|
||||
Filestore: persist.NewFilestore(storePath, certsDir, certsDir),
|
||||
legacyClient: (&rpcClientFactory{}).NewClient(storePath, certsDir),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,30 +73,18 @@ func (*rpcClientFactory) NewClient(storePath, certsDir string) libmachine.API {
|
|||
return c
|
||||
}
|
||||
|
||||
var clientFactories = map[ClientType]clientFactory{
|
||||
// ClientTypeNative: &nativeClientFactory{},
|
||||
ClientTypeLocal: &localClientFactory{},
|
||||
ClientTypeRPC: &rpcClientFactory{},
|
||||
}
|
||||
|
||||
const (
|
||||
ClientTypeLocal ClientType = iota
|
||||
ClientTypeRPC
|
||||
|
||||
// ClientTypeNative
|
||||
)
|
||||
|
||||
// Gets a new client depending on the clientType specified
|
||||
// defaults to the libmachine client
|
||||
func NewAPIClient(clientType ClientType) (libmachine.API, error) {
|
||||
func NewAPIClient() (libmachine.API, error) {
|
||||
storePath := constants.GetMinipath()
|
||||
certsDir := constants.MakeMiniPath("certs")
|
||||
newClientFactory, ok := clientFactories[clientType]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("No implementation for API client type %d", clientType)
|
||||
}
|
||||
|
||||
return newClientFactory.NewClient(storePath, certsDir), nil
|
||||
return &LocalClient{
|
||||
certsDir: certsDir,
|
||||
storePath: storePath,
|
||||
Filestore: persist.NewFilestore(storePath, certsDir, certsDir),
|
||||
legacyClient: (&rpcClientFactory{}).NewClient(storePath, certsDir),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getDriver(driverName string, rawDriver []byte) (drivers.Driver, error) {
|
||||
|
|
@ -131,9 +120,15 @@ type LocalClient struct {
|
|||
certsDir string
|
||||
storePath string
|
||||
*persist.Filestore
|
||||
legacyClient libmachine.API
|
||||
}
|
||||
|
||||
func (api *LocalClient) NewHost(driverName string, rawDriver []byte) (*host.Host, error) {
|
||||
// If not should get Driver, use legacy
|
||||
if _, ok := driverMap[driverName]; !ok {
|
||||
return api.legacyClient.NewHost(driverName, rawDriver)
|
||||
}
|
||||
|
||||
driver, err := getDriver(driverName, rawDriver)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error getting driver")
|
||||
|
|
@ -168,6 +163,11 @@ func (api *LocalClient) Load(name string) (*host.Host, error) {
|
|||
return nil, errors.Wrap(err, "Error loading host from store")
|
||||
}
|
||||
|
||||
// If not should get Driver, use legacy
|
||||
if _, ok := driverMap[h.DriverName]; !ok {
|
||||
return api.legacyClient.Load(name)
|
||||
}
|
||||
|
||||
h.Driver, err = getDriver(h.DriverName, h.RawDriver)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error loading driver from host")
|
||||
|
|
@ -176,9 +176,19 @@ func (api *LocalClient) Load(name string) (*host.Host, error) {
|
|||
return h, nil
|
||||
}
|
||||
|
||||
func (api *LocalClient) Close() error { return nil }
|
||||
func (api *LocalClient) Close() error {
|
||||
if api.legacyClient != nil {
|
||||
return api.legacyClient.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalClient) Create(h *host.Host) error {
|
||||
|
||||
if _, ok := driverMap[h.Driver.DriverName()]; !ok {
|
||||
return api.legacyClient.Create(h)
|
||||
}
|
||||
|
||||
steps := []struct {
|
||||
name string
|
||||
f func() error
|
||||
|
|
|
|||
Loading…
Reference in New Issue