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

Create the Node subcommands #6556

Merged
merged 25 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ad03309
Adding the initial node cmd and pkg files
sharifelgamal Jan 24, 2020
8db7f59
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal Jan 25, 2020
317dd41
moving node package around
sharifelgamal Jan 28, 2020
ae8309f
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal Jan 28, 2020
593d3fc
moving packages around
sharifelgamal Jan 29, 2020
a539efc
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal Jan 29, 2020
3cbe879
node add works
sharifelgamal Jan 30, 2020
dc0be4a
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal Feb 5, 2020
8d365fc
shuffling stuff around for import purposes
sharifelgamal Feb 6, 2020
eded9a1
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal Feb 6, 2020
f6f8b50
fill in cmd code
sharifelgamal Feb 6, 2020
60c8cfb
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal Feb 6, 2020
e1fc3ce
let's rearrange some stuff
sharifelgamal Feb 8, 2020
69aa54f
begin start refactor
sharifelgamal Feb 11, 2020
f2ebbb9
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal Feb 11, 2020
b6a429d
hey did you want more files? good
sharifelgamal Feb 11, 2020
744efaa
REFACTOR COMPLETE?
sharifelgamal Feb 12, 2020
8de1f8b
revert changelog change
sharifelgamal Feb 12, 2020
adc1a56
search and replace cleanup
sharifelgamal Feb 12, 2020
9830d91
linting nonsense
sharifelgamal Feb 12, 2020
b427dc5
fixed commands, they mostly work now
sharifelgamal Feb 12, 2020
8c55c9c
holy crap cyclical import hell sucks
sharifelgamal Feb 13, 2020
2785d29
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal Feb 13, 2020
c1a3e43
fix unit tests and fix merge conflicts
sharifelgamal Feb 13, 2020
6d8a112
don\'t return that the machine doesn\'t exist if the k8s is stopped
sharifelgamal Feb 13, 2020
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ Thank you to the contributors whose work made v1.1 into something we could all b
* Add port name to service struct used in minikube service [#4011](https://github.com/kubernetes/minikube/pull/4011)
* Update Hyper-V daemons [#4030](https://github.com/kubernetes/minikube/pull/4030)
* Avoid surfacing "error: no objects passed to apply" non-error from addon-manager [#4076](https://github.com/kubernetes/minikube/pull/4076)
* Don't cache images when --vmdriver=none [#4059](https://github.com/kubernetes/minikube/pull/4059)
* Don't cache images when --vm-driver=none [#4059](https://github.com/kubernetes/minikube/pull/4059)
* Enable CONFIG_NF_CONNTRACK_ZONES [#3755](https://github.com/kubernetes/minikube/pull/3755)
* Fixed status checking with non-default apiserver-port. [#4058](https://github.com/kubernetes/minikube/pull/4058)
* Escape systemd special chars in docker-env [#3997](https://github.com/kubernetes/minikube/pull/3997)
Expand Down
47 changes: 2 additions & 45 deletions cmd/minikube/cmd/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ package cmd
import (
"github.com/spf13/cobra"
cmdConfig "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/image"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/node"
)

// cacheImageConfigKey is the config field name used to store which images we have previously cached
Expand Down Expand Up @@ -77,54 +75,13 @@ var reloadCacheCmd = &cobra.Command{
Short: "reload cached images.",
Long: "reloads images previously added using the 'cache add' subcommand",
Run: func(cmd *cobra.Command, args []string) {
err := cacheAndLoadImagesInConfig()
err := node.CacheAndLoadImagesInConfig()
if err != nil {
exit.WithError("Failed to reload cached images", err)
}
},
}

func imagesInConfigFile() ([]string, error) {
configFile, err := config.ReadConfig(localpath.ConfigFile)
if err != nil {
return nil, err
}
if values, ok := configFile[cacheImageConfigKey]; ok {
var images []string
for key := range values.(map[string]interface{}) {
images = append(images, key)
}
return images, nil
}
return []string{}, nil
}

// saveImagesToTarFromConfig saves images to tar in cache which specified in config file.
// currently only used by download-only option
func saveImagesToTarFromConfig() error {
images, err := imagesInConfigFile()
if err != nil {
return err
}
if len(images) == 0 {
return nil
}
return image.SaveToDir(images, constants.ImageCacheDir)
}

// cacheAndLoadImagesInConfig loads the images currently in the config file
// called by 'start' and 'cache reload' commands.
func cacheAndLoadImagesInConfig() error {
images, err := imagesInConfigFile()
if err != nil {
return err
}
if len(images) == 0 {
return nil
}
return machine.CacheAndLoadImages(images)
}

func init() {
cacheCmd.AddCommand(addCacheCmd)
cacheCmd.AddCommand(deleteCacheCmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var printProfilesTable = func() {
glog.Errorf("%q has no control plane: %v", p.Name, err)
// Print the data we know about anyways
}
validData = append(validData, []string{p.Name, p.Config.VMDriver, p.Config.KubernetesConfig.ContainerRuntime, cp.IP, strconv.Itoa(cp.Port), p.Config.KubernetesConfig.KubernetesVersion, p.Status})
validData = append(validData, []string{p.Name, p.Config.Driver, p.Config.KubernetesConfig.ContainerRuntime, cp.IP, strconv.Itoa(cp.Port), p.Config.KubernetesConfig.KubernetesVersion, p.Status})
}

table.AppendBulk(validData)
Expand Down
11 changes: 5 additions & 6 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/spf13/viper"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
pkg_config "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
Expand All @@ -41,6 +42,7 @@ import (
"k8s.io/minikube/pkg/minikube/kubeconfig"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
)

Expand Down Expand Up @@ -92,10 +94,7 @@ func runDelete(cmd *cobra.Command, args []string) {
if len(args) > 0 {
exit.UsageT("Usage: minikube delete")
}
profileFlag, err := cmd.Flags().GetString("profile")
if err != nil {
exit.WithError("Could not get profile flag", err)
}
profileFlag := viper.GetString(config.MachineProfile)

validProfiles, invalidProfiles, err := pkg_config.ListProfiles()
profilesToDelete := append(validProfiles, invalidProfiles...)
Expand Down Expand Up @@ -192,7 +191,7 @@ func deleteProfile(profile *pkg_config.Profile) error {
return DeletionError{Err: delErr, Errtype: MissingProfile}
}

if err == nil && driver.BareMetal(cc.VMDriver) {
if err == nil && driver.BareMetal(cc.Driver) {
if err := uninstallKubernetes(api, profile.Name, cc.KubernetesConfig, viper.GetString(cmdcfg.Bootstrapper)); err != nil {
deletionError, ok := err.(DeletionError)
if ok {
Expand Down Expand Up @@ -276,7 +275,7 @@ func profileDeletionErr(profileName string, additionalInfo string) error {

func uninstallKubernetes(api libmachine.API, profile string, kc pkg_config.KubernetesConfig, bsName string) error {
out.T(out.Resetting, "Uninstalling Kubernetes {{.kubernetes_version}} using {{.bootstrapper_name}} ...", out.V{"kubernetes_version": kc.KubernetesVersion, "bootstrapper_name": bsName})
clusterBootstrapper, err := getClusterBootstrapper(api, bsName)
clusterBootstrapper, err := node.Bootstrapper(api, bsName)
if err != nil {
return DeletionError{Err: fmt.Errorf("unable to get bootstrapper: %v", err), Errtype: Fatal}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/logs"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/node"
)

const (
Expand Down Expand Up @@ -66,7 +67,7 @@ var logsCmd = &cobra.Command{
if err != nil {
exit.WithError("command runner", err)
}
bs, err := getClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
bs, err := node.Bootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This placement feels a bit weird: the bootstrapper is a cluster-property rather than a node property.

if err != nil {
exit.WithError("Error getting cluster bootstrapper", err)
}
Expand Down
33 changes: 33 additions & 0 deletions cmd/minikube/cmd/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/exit"
)

// nodeCmd represents the set of node subcommands
var nodeCmd = &cobra.Command{
Use: "node",
Short: "Node operations",
Long: "Operations on nodes",
Hidden: true, // This won't be fully functional and thus should not be documented yet
Run: func(cmd *cobra.Command, args []string) {
exit.UsageT("Usage: minikube node [add|start|stop|delete]")
},
}
77 changes: 77 additions & 0 deletions cmd/minikube/cmd/node_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
)

var (
nodeName string
cp bool
worker bool
)
var nodeAddCmd = &cobra.Command{
Use: "add",
Short: "Adds a node to the given cluster.",
Long: "Adds a node to the given cluster config, and starts it.",
Run: func(cmd *cobra.Command, args []string) {
profile := viper.GetString(config.MachineProfile)
mc, err := config.Load(profile)
if err != nil {
exit.WithError("Error getting config", err)
}
name := nodeName
if nodeName == "" {
name = profile + strconv.Itoa(len(mc.Nodes)+1)
}
out.T(out.Happy, "Adding node {{.name}} to cluster {{.cluster}}", out.V{"name": name, "cluster": profile})

n, err := node.Add(mc, name, cp, worker, "", profile)
if err != nil {
exit.WithError("Error adding node to cluster", err)
}

_, err = node.Start(mc, n, false, nil)
if err != nil {
exit.WithError("Error starting node", err)
}

out.T(out.Ready, "Successfully added {{.name}} to {{.cluster}}!", out.V{"name": name, "cluster": profile})
},
}

func init() {
nodeAddCmd.Flags().StringVar(&nodeName, "name", "", "The name of the node to add.")
nodeAddCmd.Flags().BoolVar(&cp, "control-plane", false, "If true, the node added will also be a control plane in addition to a worker.")
nodeAddCmd.Flags().BoolVar(&worker, "worker", true, "If true, the added node will be marked for work. Defaults to true.")
//We should figure out which of these flags to actually import
startCmd.Flags().Visit(
func(f *pflag.Flag) {
nodeAddCmd.Flags().AddFlag(f)
},
)
nodeCmd.AddCommand(nodeAddCmd)
}
58 changes: 58 additions & 0 deletions cmd/minikube/cmd/node_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
)

var nodeDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Deletes a node from a cluster.",
Long: "Deletes a node from a cluster.",
Run: func(cmd *cobra.Command, args []string) {

if len(args) == 0 {
exit.UsageT("Usage: minikube node delete [name]")
}
name := args[0]

profile := viper.GetString(config.MachineProfile)
out.T(out.DeletingHost, "Deleting node {{.name}} from cluster {{.cluster}}", out.V{"name": name, "cluster": profile})

cc, err := config.Load(profile)
if err != nil {
exit.WithError("loading config", err)
}

err = node.Delete(cc, name)
if err != nil {
out.FatalT("Failed to delete node {{.name}}", out.V{"name": name})
}

out.T(out.Deleted, "Node {{.name}} was successfully deleted.", out.V{"name": name})
},
}

func init() {
nodeCmd.AddCommand(nodeDeleteCmd)
}
75 changes: 75 additions & 0 deletions cmd/minikube/cmd/node_start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
)

var nodeStartCmd = &cobra.Command{
Use: "start",
Short: "Starts a node.",
Long: "Starts an existing stopped node in a cluster.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
exit.UsageT("Usage: minikube node start [name]")
}

name := args[0]

// Make sure it's not running
api, err := machine.NewAPIClient()
if err != nil {
exit.WithError("creating api client", err)
}

if cluster.IsHostRunning(api, name) {
out.T(out.Check, "{{.name}} is already running", out.V{"name": name})
os.Exit(0)
}

cc, err := config.Load(viper.GetString(config.MachineProfile))
if err != nil {
exit.WithError("loading config", err)
}

n, _, err := node.Retrieve(cc, name)
if err != nil {
exit.WithError("retrieving node", err)
}

// Start it up baby
_, err = node.Start(cc, n, false, nil)
if err != nil {
out.FatalT("Failed to start node {{.name}}", out.V{"name": name})
}
},
}

func init() {
nodeStartCmd.Flags().String("name", "", "The name of the node to start")
nodeCmd.AddCommand(nodeStartCmd)
}
Loading