-
Notifications
You must be signed in to change notification settings - Fork 5k
Add CommandRunner interface #1844
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1844 +/- ##
==========================================
- Coverage 32.7% 32.02% -0.69%
==========================================
Files 66 66
Lines 4112 3966 -146
==========================================
- Hits 1345 1270 -75
+ Misses 2572 2528 -44
+ Partials 195 168 -27
Continue to review full report at Codecov.
|
return errors.Wrap(err, "Error getting ip from driver") | ||
} | ||
glog.Infoln("Setting up certificates for IP: %s", ipStr) | ||
ip := net.ParseIP(k8s.NodeIP) |
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.
Why did this change?
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.
A little duplication here,
We already call host.GetIP() in start.go https://github.com/kubernetes/minikube/blob/master/cmd/minikube/cmd/start.go#L143-L147
and populate the KubernetesConfig with that value
https://github.com/kubernetes/minikube/blob/master/cmd/minikube/cmd/start.go#L179
pkg/minikube/cluster/cluster.go
Outdated
@@ -232,6 +232,7 @@ func UpdateCluster(cmd bootstrapper.CommandRunner, config KubernetesConfig) erro | |||
} | |||
|
|||
for _, f := range copyableFiles { | |||
// fmt.Println(f.GetAssetName()) |
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.
Remove?
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.
done
@@ -103,3 +103,11 @@ func (f *FakeCommandRunner) GetFileToContents(fpath string) (string, error) { | |||
func (f *FakeCommandRunner) SetFileToContents(fileToContents map[string]string) { | |||
f.fileToContents.Store(fileToContents) | |||
} | |||
|
|||
func (f *FakeCommandRunner) DumpMaps(w io.Writer) { |
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.
Unused?
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.
I just added this as a nice debugging function for the fake runner, since I didn't want to actually make cmdMap and fileMap public, but it might be helpful to dump their contents on test failures.
49942a4
to
7d8fe62
Compare
|
||
func TestDisableUnknownAddon(t *testing.T) { | ||
if err := Set("InvalidAddon", "false"); err == nil { | ||
t.Fatalf("Disable did not return error for unknown addon") | ||
} | ||
} | ||
|
||
func TestDisableValidAddonLocal(t *testing.T) { |
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.
Are these addon tests reimplemented somewhere else?
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.
No, a pretty big part of theses tests were checking if the file itself was transferred, which should be covered by the SSHRunner tests.
There's probably a bit of coverage that got lost about writing the config and making sure that the addon gets configured properly.
d9f2acf
to
644b88e
Compare
|
||
// Copy copies a file and its permissions | ||
func (*ExecRunner) Copy(f assets.CopyableFile) error { | ||
if err := os.MkdirAll(f.GetTargetDir(), os.ModePerm); err != nil { |
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.
What happens here if the directory already exists?
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.
No errror, it behaviors like mkdir -p
https://golang.org/pkg/os/#MkdirAll
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
// | ||
// It implements the CommandRunner interface and is used for testing. | ||
type FakeCommandRunner struct { | ||
commandToOutput atomic.Value |
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.
You might be able to use sync.Map instead?
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.
nice. that simplifies things a lot. done
cmd/minikube/cmd/config/util.go
Outdated
return err | ||
if enable { | ||
for _, addon := range addon.Assets { | ||
cmd.Copy(addon) |
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.
Do we need to check for errors here?
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.
yes, done
cmd/minikube/cmd/config/util.go
Outdated
if err = os.Remove(filepath.Join(f.GetTargetDir(), f.GetTargetName())); err != nil { | ||
return err | ||
for _, addon := range addon.Assets { | ||
cmd.Remove(addon) |
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.
Same
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.
done
@@ -62,7 +62,15 @@ var statusCmd = &cobra.Command{ | |||
cs := state.None.String() | |||
ks := state.None.String() | |||
if ms == state.Running.String() { | |||
cs, err = cluster.GetLocalkubeStatus(api) | |||
h, err := api.Load(config.GetMachineName()) |
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 is weird, but it looks like the permissions of this file changed to 755?
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.
Permissions of what file?
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.
Change the file permissions back.
cs, err = cluster.GetLocalkubeStatus(api) | ||
h, err := api.Load(config.GetMachineName()) | ||
if err != nil { | ||
glog.Exitln("Error getting host") |
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.
Should these be MaybeReportErrorandExit'ing?
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.
done
Two implementations, SSHRunner and ExecRunner allow commands to be run either through SSH or os.Exec respectively. This allows the cluster bootstrappers to be unaware of how they are actually executing the commands they need. Copy and Remove functions provide a nice convenience function for running commands that copy and remove files respectively.
@@ -192,21 +192,26 @@ func runStart(cmd *cobra.Command, args []string) { | |||
glog.Errorln("Error saving profile cluster configuration: ", err) | |||
} | |||
|
|||
cmdRunner, err := machine.GetCommandRunner(host) | |||
if err != nil { | |||
glog.Errorln("Error getting command runner interface") |
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.
add maybeReportErrorAndExit
for _, f := range copyableFiles { | ||
if err := sshutil.TransferFile(f, client); err != nil { | ||
// fmt.Println(f.GetAssetName()) |
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.
nit: remove comment
LGTM |
Two implementations, SSHRunner and ExecRunner allow commands to be run
either through SSH or os.Exec respectively. This allows the cluster
bootstrappers to be unaware of how they are actually executing the
commands they need. Copy and Remove functions provide nice
convenience functions for running commands that copy and remove files
respectively.