Skip to content

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

Merged
merged 6 commits into from
Aug 24, 2017
Merged

Add CommandRunner interface #1844

merged 6 commits into from
Aug 24, 2017

Conversation

r2d4
Copy link
Contributor

@r2d4 r2d4 commented Aug 18, 2017

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 18, 2017
@codecov-io
Copy link

codecov-io commented Aug 19, 2017

Codecov Report

Merging #1844 into master will decrease coverage by 0.68%.
The diff coverage is 17.91%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pkg/minikube/sshutil/sshutil.go 54.28% <ø> (+8.92%) ⬆️
cmd/minikube/cmd/logs.go 12.5% <0%> (-6.25%) ⬇️
pkg/minikube/machine/client.go 44.66% <0%> (-2.52%) ⬇️
cmd/minikube/cmd/config/util.go 20.73% <0%> (+2.33%) ⬆️
cmd/minikube/cmd/status.go 7.93% <0%> (-1.33%) ⬇️
cmd/minikube/cmd/start.go 10.1% <0%> (-0.14%) ⬇️
pkg/minikube/cluster/cluster.go 40.94% <60%> (-2.3%) ⬇️
pkg/minikube/cluster/localkube_caching.go 43.13% <0%> (-11.77%) ⬇️
pkg/util/kubeconfig/config.go 47.61% <0%> (+0.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4e211c...cac45c3. Read the comment docs.

return errors.Wrap(err, "Error getting ip from driver")
}
glog.Infoln("Setting up certificates for IP: %s", ipStr)
ip := net.ParseIP(k8s.NodeIP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -232,6 +232,7 @@ func UpdateCluster(cmd bootstrapper.CommandRunner, config KubernetesConfig) erro
}

for _, f := range copyableFiles {
// fmt.Println(f.GetAssetName())
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove?

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused?

Copy link
Contributor Author

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.

@r2d4 r2d4 force-pushed the command-runner branch 2 times, most recently from 49942a4 to 7d8fe62 Compare August 21, 2017 05:11

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) {
Copy link
Contributor

@aaron-prindle aaron-prindle Aug 21, 2017

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?

Copy link
Contributor Author

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.

@r2d4 r2d4 force-pushed the command-runner branch 4 times, most recently from d9f2acf to 644b88e Compare August 23, 2017 00:13

// Copy copies a file and its permissions
func (*ExecRunner) Copy(f assets.CopyableFile) error {
if err := os.MkdirAll(f.GetTargetDir(), os.ModePerm); err != nil {
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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

return err
if enable {
for _, addon := range addon.Assets {
cmd.Copy(addon)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, done

if err = os.Remove(filepath.Join(f.GetTargetDir(), f.GetTargetName())); err != nil {
return err
for _, addon := range addon.Assets {
cmd.Remove(addon)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

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())
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Permissions of what file?

Copy link
Contributor Author

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")
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

r2d4 added 6 commits August 23, 2017 14:33
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")
Copy link
Contributor Author

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())
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove comment

@aaron-prindle
Copy link
Contributor

LGTM

@r2d4 r2d4 merged commit 3a0d03f into kubernetes:master Aug 24, 2017
@r2d4 r2d4 deleted the command-runner branch August 24, 2017 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants