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 all 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
3 changes: 1 addition & 2 deletions cmd/minikube/cmd/config/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/cluster"
pkg_config "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
Expand Down Expand Up @@ -69,7 +68,7 @@ var addonsOpenCmd = &cobra.Command{
defer api.Close()

profileName := viper.GetString(pkg_config.MachineProfile)
if !cluster.IsHostRunning(api, profileName) {
if !machine.IsHostRunning(api, profileName) {
os.Exit(1)
}
addon, ok := assets.Addons[addonName] // validate addon input
Expand Down
7 changes: 3 additions & 4 deletions cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"strconv"
"strings"

"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
Expand Down Expand Up @@ -76,7 +75,7 @@ var printProfilesTable = func() {
defer api.Close()

for _, p := range validProfiles {
p.Status, err = cluster.GetHostStatus(api, p.Name)
p.Status, err = machine.GetHostStatus(api, p.Name)
if err != nil {
glog.Warningf("error getting host status for %s: %v", p.Name, err)
}
Expand All @@ -85,7 +84,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 Expand Up @@ -118,7 +117,7 @@ var printProfilesJSON = func() {

validProfiles, invalidProfiles, err := config.ListProfiles()
for _, v := range validProfiles {
status, err := cluster.GetHostStatus(api, v.Name)
status, err := machine.GetHostStatus(api, v.Name)
if err != nil {
glog.Warningf("error getting host status for %s: %v", v.Name, err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/minikube/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/spf13/viper"
pkgaddons "k8s.io/minikube/pkg/addons"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/cluster"
pkg_config "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
Expand Down Expand Up @@ -102,7 +101,7 @@ var dashboardCmd = &cobra.Command{
exit.WithCodeT(exit.NoInput, "kubectl not found in PATH, but is required for the dashboard. Installation guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
}

if !cluster.IsHostRunning(api, profileName) {
if !machine.IsHostRunning(api, profileName) {
os.Exit(1)
}

Expand Down
14 changes: 6 additions & 8 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 Down Expand Up @@ -92,10 +93,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 +190,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 All @@ -208,7 +206,7 @@ func deleteProfile(profile *pkg_config.Profile) error {
out.T(out.FailureType, "Failed to kill mount process: {{.error}}", out.V{"error": err})
}

if err = cluster.DeleteHost(api, profile.Name); err != nil {
if err = machine.DeleteHost(api, profile.Name); err != nil {
switch errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist:
glog.Infof("%s cluster does not exist. Proceeding ahead with cleanup.", profile.Name)
Expand Down Expand Up @@ -276,12 +274,12 @@ 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 := cluster.Bootstrapper(api, bsName)
if err != nil {
return DeletionError{Err: fmt.Errorf("unable to get bootstrapper: %v", err), Errtype: Fatal}
}

host, err := cluster.CheckIfHostExistsAndLoad(api, profile)
host, err := machine.CheckIfHostExistsAndLoad(api, profile)
if err != nil {
exit.WithError("Error getting host", err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/minikube/cmd/docker-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
Expand Down Expand Up @@ -149,15 +148,15 @@ var dockerEnvCmd = &cobra.Command{
if err != nil {
exit.WithError("Error getting config", err)
}
host, err := cluster.CheckIfHostExistsAndLoad(api, cc.Name)
host, err := machine.CheckIfHostExistsAndLoad(api, cc.Name)
if err != nil {
exit.WithError("Error getting host", err)
}
if host.Driver.DriverName() == driver.None {
exit.UsageT(`'none' driver does not support 'minikube docker-env' command`)
}

hostSt, err := cluster.GetHostStatus(api, cc.Name)
hostSt, err := machine.GetHostStatus(api, cc.Name)
if err != nil {
exit.WithError("Error getting host status", err)
}
Expand Down
13 changes: 2 additions & 11 deletions cmd/minikube/cmd/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"syscall"

"github.com/golang/glog"
Expand All @@ -29,6 +28,7 @@ import (
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ minikube kubectl -- get pods --namespace kube-system`,
version = cc.KubernetesConfig.KubernetesVersion
}

path, err := cacheKubectlBinary(version)
path, err := node.CacheKubectlBinary(version)
if err != nil {
out.ErrLn("Error caching kubectl: %v", err)
}
Expand All @@ -82,12 +82,3 @@ minikube kubectl -- get pods --namespace kube-system`,
}
},
}

func cacheKubectlBinary(k8sVerison string) (string, error) {
binary := "kubectl"
if runtime.GOOS == "windows" {
binary = "kubectl.exe"
}

return machine.CacheBinary(binary, k8sVerison, runtime.GOOS, runtime.GOARCH)
}
3 changes: 2 additions & 1 deletion cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/exit"
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 := cluster.Bootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
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)
}
Loading