-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
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 8db7f59
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal 317dd41
moving node package around
sharifelgamal ae8309f
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal 593d3fc
moving packages around
sharifelgamal a539efc
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal 3cbe879
node add works
sharifelgamal dc0be4a
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal 8d365fc
shuffling stuff around for import purposes
sharifelgamal eded9a1
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal f6f8b50
fill in cmd code
sharifelgamal 60c8cfb
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal e1fc3ce
let's rearrange some stuff
sharifelgamal 69aa54f
begin start refactor
sharifelgamal f2ebbb9
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal b6a429d
hey did you want more files? good
sharifelgamal 744efaa
REFACTOR COMPLETE?
sharifelgamal 8de1f8b
revert changelog change
sharifelgamal adc1a56
search and replace cleanup
sharifelgamal 9830d91
linting nonsense
sharifelgamal b427dc5
fixed commands, they mostly work now
sharifelgamal 8c55c9c
holy crap cyclical import hell sucks
sharifelgamal 2785d29
Merge branch 'master' of github.com:kubernetes/minikube into node-pkg
sharifelgamal c1a3e43
fix unit tests and fix merge conflicts
sharifelgamal 6d8a112
don\'t return that the machine doesn\'t exist if the k8s is stopped
sharifelgamal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.