Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-node Prototype #2539

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b208463
Rough in basic node commands: add, start, remove, list, ssh
pbitty Jan 8, 2018
bb9ded2
Add gostregen
pbitty Jan 11, 2018
ae5c71f
WIP: Add node join logic
pbitty Jan 11, 2018
d423e82
Add Pod CIDR option (hard-coded for now)
pbitty Jan 14, 2018
f86f741
Fix node remove command
pbitty Jan 14, 2018
2f4c36c
Merge remote-tracking branch 'upstream/master' into multi-node-poc
pbitty Jan 14, 2018
e9862e1
Enable multi-node networking:
pbitty Jan 18, 2018
61a8dd2
Add node_name to node start cmd
pbitty Jan 18, 2018
779f4e0
Add hello service and daemonset
pbitty Jan 18, 2018
917fc0b
Fix failing tests by adding machineName arg to various functions
pbitty Jan 20, 2018
4bec3cc
Add notes
pbitty Feb 7, 2018
824b0c9
Move node commands to individual files
pbitty Feb 7, 2018
f4de014
Create base types
pbitty Feb 7, 2018
aed7c84
Refactor functions to include machine name
pbitty Feb 7, 2018
834ffcc
Refactor kubeadm bootstrapper to not need libmachine.API
pbitty Feb 7, 2018
274adb6
Refactor cluster.Config struct
pbitty Feb 7, 2018
540cef4
Add image loading log message
pbitty Feb 7, 2018
7bb4707
Add Node implementation
pbitty Feb 7, 2018
f6b3254
typo fix
pbitty Feb 8, 2018
b27c722
Spacing cleanup
pbitty Feb 8, 2018
3e52108
Migrate bootstrap tasks into new bootstrapper
pbitty Feb 8, 2018
1e82a22
Add details to list command
pbitty Feb 8, 2018
e5e1c91
Put node commands in constructor functions
pbitty Feb 9, 2018
190f9e0
Use sequence-numbered nodes
pbitty Feb 9, 2018
ba0a056
Move bootstrap CommandRunner code to own package
pbitty Feb 9, 2018
c706e3f
Improve node list output
pbitty Feb 9, 2018
cc46239
Allow starting arbitrary set of nodes
pbitty Feb 9, 2018
8abdbf9
Create new Bootstrapper interface
pbitty Feb 9, 2018
ac385b8
Fix node code
pbitty Feb 9, 2018
9f1df32
Update machineName schema
pbitty Feb 9, 2018
5d084b0
Add demo directory
pbitty Feb 9, 2018
5539bc7
List nodes throughout demo
pbitty Feb 9, 2018
b49a122
node start command cleanup
pbitty Feb 9, 2018
266c128
Allow all nodes to be started with one command
pbitty Feb 10, 2018
bb8f0fe
Hide load images error, since it is ignored anyway
pbitty Feb 10, 2018
08d420f
Add demo code
pbitty Feb 10, 2018
f23ae36
Add PoC notes
pbitty Feb 10, 2018
a584b69
Tweak demo
pbitty Feb 10, 2018
1b87e55
Add design concerns to doc
pbitty Feb 11, 2018
ec28c4b
Rename doc
pbitty Feb 11, 2018
ca131c7
Move demo and docs
pbitty Feb 11, 2018
65d1bf7
Run gofmt
pbitty Feb 11, 2018
c987973
Add Motivation section to doc
pbitty Feb 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ ifeq ($(IN_DOCKER),1)
$(MAKE) minikube_iso
else
docker run --rm --workdir /mnt --volume $(CURDIR):/mnt $(ISO_DOCKER_EXTRA_ARGS) \
--user $(shell id -u):$(shell id -g) --env HOME=/tmp --env IN_DOCKER=1 \
--env HOME=/tmp --env IN_DOCKER=1 \
$(ISO_BUILD_IMAGE) /usr/bin/make out/minikube.iso
endif

Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ associated files.`,
}
defer api.Close()

if err = cluster.DeleteHost(api); err != nil {
if err = cluster.DeleteHost(pkg_config.GetMachineName(), api); err != nil {
fmt.Println("Errors occurred deleting machine: ", err)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func generateUsageHint(userShell string) string {

func shellCfgSet(api libmachine.API) (*ShellConfig, error) {

envMap, err := cluster.GetHostDockerEnv(api)
envMap, err := cluster.GetHostDockerEnv(config.GetMachineName(), api)
if err != nil {
return nil, err
}
Expand Down
57 changes: 57 additions & 0 deletions cmd/minikube/cmd/node/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package node

import (
"fmt"
"os"

"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"k8s.io/minikube/cmd/minikube/profile"
cmdutil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube"
cfg "k8s.io/minikube/pkg/minikube/config"
)

func NewCmdAdd() *cobra.Command {
return &cobra.Command{
Use: "add <node_name>",
Short: "Adds a node to the cluster",
Long: "Adds a node tot the cluster",
sharifelgamal marked this conversation as resolved.
Show resolved Hide resolved
Run: add,
}
}

func add(cmd *cobra.Command, args []string) {
// TODO Make clusterName into `--cluster=` flag
clusterName := viper.GetString(cfg.MachineProfile)

nodeName := ""
if len(args) > 0 {
nodeName = args[0]
}

cfg, err := profile.LoadConfigFromFile(clusterName)
if err != nil {
glog.Errorln("Error loading profile config: ", err)
cmdutil.MaybeReportErrorAndExit(err)
}

if nodeName == "" {
nodeName = fmt.Sprintf("node-%d", len(cfg.Nodes)+1)
}

node := minikube.NodeConfig{
Name: nodeName,
}

cfg.Nodes = append(cfg.Nodes, node)

if err := profile.SaveConfig(clusterName, cfg); err != nil {
glog.Errorln("Error saving profile cluster configuration: ", err)
os.Exit(1)
}

fmt.Println("Added node: ", node.Name)
}
68 changes: 68 additions & 0 deletions cmd/minikube/cmd/node/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package node

import (
"fmt"
"os"

"github.com/golang/glog"
"github.com/spf13/cobra"

"k8s.io/minikube/cmd/minikube/profile"
cmdutil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/node"
)

func NewCmdList() *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "Lists all nodes",
Long: "Lists all nodes",
Run: list,
}
}

func list(cmd *cobra.Command, args []string) {
configs, err := profile.LoadClusterConfigs()
if err != nil {
glog.Errorln("Error loading cluster configs: ", err)
cmdutil.MaybeReportErrorAndExit(err)
}

api, err := machine.NewAPIClient()
if err != nil {
glog.Errorf("Error getting client: %s\n", err)
os.Exit(1)
}
defer api.Close()

fmt.Printf("%-20s %-20s %-16s %-20s\n", "CLUSTER", "NODE", "IP", "STATUS")

nodesFound := false
for _, c := range configs {
for _, nc := range c.Nodes {
nodesFound = true
n := node.NewNode(nc, c.MachineConfig, c.ClusterName, api)
status, err := n.Status()
if err != nil {
status = minikube.NodeStatus("Error: " + err.Error())
}

ip := ""
if status == minikube.StatusRunning {
ip, err = n.IP()
if err != nil {
glog.Errorf("Error getting IP address for node %s: %s", nc.Name, err)
cmdutil.MaybeReportErrorAndExit(err)
}
}

fmt.Printf("%-20s %-20s %-16s %-20s\n", c.ClusterName, nc.Name, ip, status)
}
}

if !nodesFound {
fmt.Println("No nodes found.")
}
}
50 changes: 50 additions & 0 deletions cmd/minikube/cmd/node/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package node

import (
"fmt"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"k8s.io/minikube/cmd/minikube/profile"
"k8s.io/minikube/pkg/minikube"
)

const internalErrorCode = -1

func NewCmdNode() *cobra.Command {
cmd := &cobra.Command{
Use: "node SUBCOMMAND [flags]",
Short: "Control a minikube cluster's nodes",
Long: `Control a cluster's nodes using subcommands like "minikube node add <node_name>"`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
cmd.AddCommand(NewCmdAdd())
cmd.AddCommand(NewCmdList())
cmd.AddCommand(NewCmdRemove())
cmd.AddCommand(NewCmdSsh())
cmd.AddCommand(NewCmdStart())
return cmd
}

func getMachineName(clusterName string, node minikube.NodeConfig) string {
return fmt.Sprintf("%s-%s", clusterName, node.Name)
}

func getNode(clusterName, nodeName string) (minikube.NodeConfig, error) {
cfg, err := profile.LoadConfigFromFile(clusterName)
if err != nil && !os.IsNotExist(err) {
return minikube.NodeConfig{}, errors.Errorf("Error loading profile config: %s", err)
}

for _, node := range cfg.Nodes {
if node.Name == nodeName {
return node, nil
}
}

return minikube.NodeConfig{}, errors.Errorf("Node not found in cluster. cluster: %s node: %s", clusterName, nodeName)
}
77 changes: 77 additions & 0 deletions cmd/minikube/cmd/node/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package node

import (
"os"

"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"k8s.io/minikube/cmd/minikube/profile"
cmdutil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube/cluster"
cfg "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/machine"
)

func NewCmdRemove() *cobra.Command {
return &cobra.Command{
Use: "remove <node_name>",
Short: "Removes a node from the cluster",
Long: "Removes a node from the cluster",
Run: remove,
}
}

func remove(cmd *cobra.Command, args []string) {
clusterName := viper.GetString(cfg.MachineProfile)

if len(args) == 0 || args[0] == "" {
glog.Error("node_name is required.")
os.Exit(1)
}

nodeName := args[0]

cfg, err := profile.LoadConfigFromFile(clusterName)
if err != nil && !os.IsNotExist(err) {
glog.Errorln("Error loading profile config: ", err)
cmdutil.MaybeReportErrorAndExit(err)
}
api, err := machine.NewAPIClient()
if err != nil {
glog.Errorf("Error getting client: %s\n", err)
os.Exit(1)
}
defer api.Close()

for i, node := range cfg.Nodes {
if node.Name == nodeName {
machineName := getMachineName(clusterName, node)
exists, err := api.Exists(machineName)
if err != nil {
glog.Errorln("Error removing node: ", err)
os.Exit(1)
}

if exists {
if err := cluster.DeleteHost(machineName, api); err != nil {
glog.Errorln("Error removing node: ", err)
os.Exit(1)
}
}

cfg.Nodes = append(cfg.Nodes[:i], cfg.Nodes[i+1:]...)
break

} else if i == len(cfg.Nodes)-1 {
glog.Errorln("Node not found: ", nodeName)
os.Exit(1)
}
}

if err := profile.SaveConfig(clusterName, cfg); err != nil {
glog.Errorln("Error saving profile cluster configuration: ", err)
os.Exit(1)
}
}
65 changes: 65 additions & 0 deletions cmd/minikube/cmd/node/ssh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package node

import (
"fmt"
"os"

"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"k8s.io/minikube/pkg/minikube/cluster"
cfg "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/machine"
)

func NewCmdSsh() *cobra.Command {
return &cobra.Command{
Use: "ssh",
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: ssh,
}
}

func ssh(cmd *cobra.Command, args []string) {
clusterName := viper.GetString(cfg.MachineProfile)

if len(args) == 0 || args[0] == "" {
glog.Error("node_name is required.")
os.Exit(1)
}

nodeName := args[0]
args = args[1:]

node, err := getNode(clusterName, nodeName)
if err != nil {
glog.Error("Error loading node: ", err)
os.Exit(1)
}

api, err := machine.NewAPIClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
os.Exit(1)
}
defer api.Close()

machineName := getMachineName(clusterName, node)
host, err := cluster.CheckIfApiExistsAndLoadByName(machineName, api)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting host: %s\n", err)
os.Exit(1)
}
if host.Driver.DriverName() == "none" {
fmt.Println(`'none' driver does not support 'minikube ssh' command`)
os.Exit(0)
}
err = cluster.CreateSSHShellByName(machineName, api, args)
if err != nil {
glog.Errorln(errors.Wrap(err, "Error attempting to ssh/run-ssh-command"))
os.Exit(1)
}
}
Loading