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

Fix cyclomatic complexity in cmd/controller/main.go #177

Closed
EricFortin opened this issue Apr 14, 2018 · 3 comments
Closed

Fix cyclomatic complexity in cmd/controller/main.go #177

EricFortin opened this issue Apr 14, 2018 · 3 comments
Labels
good first issue These are great first issues. If you are looking for a place to start, start here! kind/cleanup Refactoring code, fixing up documentation, etc
Milestone

Comments

@EricFortin
Copy link
Collaborator

Remove the // nolint comment.

The main function has a cyclomatic complexity greater than 10. Refactor the function to lower it.

@EricFortin EricFortin added good first issue These are great first issues. If you are looking for a place to start, start here! kind/cleanup Refactoring code, fixing up documentation, etc labels Apr 14, 2018
@enocom enocom self-assigned this May 16, 2018
@enocom
Copy link
Contributor

enocom commented May 16, 2018

There's a consistent pattern in main.go where we start a goroutine and call Run on something, reporting an error if the call fails.

With some small refactoring, we could do this:

var rs []runner = []runner{                                                                                                                
    wh, gsController, gsSetController, fleetController, faController, health,                                                              
}                                                                                                                                          
for _, r := range rs {                                                                                                                     
    go func() {
        if err := r.Run(stop); err != nil {
            logger.Fatalf("component %s failed to start with error: %s", r, err)
        }
    }()                                                                                                                         
}                                                                                                                                          
<-stop                                                                                                                                     
logger.Info("Shut down agones controllers")

Alternatively, if that seems too fancy, we could also simple extract a named function for each started goroutine.

Thoughts?

@markmandel
Copy link
Member

I've actually often wondered if each Controller should/could implement an interface, and if there was value in that - sounds like there might be. I'm definitely not adverse to this approach.

This kinda starts us down an opinionated framework for controllers path - which is not the end of the world.

@enocom
Copy link
Contributor

enocom commented May 17, 2018

I'll put together the PR with that pattern and we can revisit the question of making controllers implement a common interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue These are great first issues. If you are looking for a place to start, start here! kind/cleanup Refactoring code, fixing up documentation, etc
Projects
None yet
Development

No branches or pull requests

3 participants