Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Initial wiring #3

Merged
merged 13 commits into from
Apr 9, 2019
Merged

Initial wiring #3

merged 13 commits into from
Apr 9, 2019

Conversation

rossf7
Copy link
Contributor

@rossf7 rossf7 commented Apr 9, 2019

Adds initial wiring based on what we do in devctl.

@rossf7 rossf7 self-assigned this Apr 9, 2019
@rossf7 rossf7 requested a review from a team April 9, 2019 09:54
@rossf7
Copy link
Contributor Author

rossf7 commented Apr 9, 2019

OK should be good now. This adds the wiring with the version command. Next PR will be to add a create cluster command based on the e2ekindprototype code.

cmd/runner.go Outdated
stderr io.Writer
}

func (r *runner) Run(cmd *cobra.Command, args []string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can have some RunE or RunError interface to do the logging and process termination in fewer places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense but where should it live? microkit?

Copy link
Contributor

Choose a reason for hiding this comment

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

So when this is the method which is called by cobra then it is done there. Good question what happens on error then, but there is something like RunE and I thought we should rather use this and do normal error handling 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.

Got it. Yes using RunE is nice and the error is passed to Execute when it's called. I renamed Run to RunWithError to align with mainWithError.

@xh3b4sd PTAL

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code is copied from devctl and I did it there for purpose. I think it's better when we handle all errors ourselves with this code

https://github.com/giantswarm/devctl/blob/master/cmd/runner.go#L30-L34

Otherwise there are ugly repeated error messages and usage messages in random places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you try using RunE? I did a basic test and the error was propagated to the Execute call.

Yes this is all based on what you created in devctl. I'd like both projects to be aligned. So if the existing approach is better I'm fine with using it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have a blurry memories but something was bad.

How about stack trace? Was it printed with RunE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. But yes the stack trace is preserved.

go run main.go version  
Git Commit:     n/a
Go Version:     go1.11.2
OS / Arch:      darwin / amd64
Source:         https://github.com/giantswarm/e2ectl
Error: my test error: invalid config error
Usage:
  e2ectl version [flags]

Flags:
  -h, --help   help for version

{"caller":"e2ectl/main.go:55","level":"error","message":"failed to execute root command","stack":"[{/Users/ross/Documents/giantswarm/src/e2ectl/cmd/version/runner.go:34: } {/Users/ross/Documents/giantswarm/src/e2ectl/cmd/version/runner.go:48: } {/Users/ross/Documents/giantswarm/src/e2ectl/cmd/version/runner.go:55: my test error} {invalid config error}]","time":"2019-04-09T13:53:07.853366+00:00"}
exit status 1

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay now I remember. The usage was an issue. I really dislike it. Let's say e2e-harness fails to setup a cluster and prints an error preceded with usage. That doesn't make sense because command was executed correctly. It just failed at runtime.

source = "https://github.com/giantswarm/e2ectl"
)

func main() {
Copy link
Contributor

Choose a reason for hiding this comment

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

mainError would also be good 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.

Good shout. Done.

err = rootCommand.Execute()
if err != nil {
logger.LogCtx(ctx, "level", "error", "message", "failed to execute root command", "stack", fmt.Sprintf("%#v", err))
os.Exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can return an error here now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is logging.

If I return an error we will panic with it. I'd rather use the logger unless we can't create it.

@rossf7
Copy link
Contributor Author

rossf7 commented Apr 9, 2019

Going with this. I think the main.go is good enough for now.

@rossf7 rossf7 merged commit 3f895e8 into master Apr 9, 2019
@rossf7 rossf7 deleted the initial-setup branch April 9, 2019 13:33
@rossf7
Copy link
Contributor Author

rossf7 commented Apr 9, 2019

Deploy step fails because Circle config uses a docker build and not machine so there is no jq :(

I'll sort that later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants