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

Improve consistency of command functions #1124

Merged
merged 1 commit into from
Aug 9, 2019

Conversation

errordeveloper
Copy link
Contributor

@errordeveloper errordeveloper commented Aug 8, 2019

Description

A follow up to #1116.

Checklist

  • Code compiles correctly (i.e make build)
  • All unit tests passing (i.e. make test)

@errordeveloper errordeveloper force-pushed the defaulting-and-validation branch 2 times, most recently from 3c85303 to 1aa3879 Compare August 8, 2019 16:19
@errordeveloper errordeveloper changed the title Ensure all command functions perform defaulting and validation @errordeveloper Improve consistency of command function Aug 8, 2019
@errordeveloper errordeveloper changed the title @errordeveloper Improve consistency of command function Improve consistency of command function Aug 8, 2019
@errordeveloper errordeveloper force-pushed the defaulting-and-validation branch from 1aa3879 to 8c28025 Compare August 8, 2019 16:24
@errordeveloper errordeveloper changed the title Improve consistency of command function Improve consistency of command functions Aug 8, 2019
@errordeveloper errordeveloper force-pushed the defaulting-and-validation branch from 8c28025 to 876583b Compare August 8, 2019 16:24
@errordeveloper errordeveloper requested a review from rndstr August 8, 2019 16:31
Copy link
Contributor

@rndstr rndstr left a comment

Choose a reason for hiding this comment

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

there is a lot of repetition going on, could we possibly move these into functions?

  • eks.New() could be something like eks.NewWithRegion(…) (ctl, error)
  • for config defaults and validation could add cmdutils.ResourceCmd#GetDefaultedAndValidatedConfig(…) (cfg, error)

(i'm sure you'll come up with better names)

@errordeveloper errordeveloper force-pushed the defaulting-and-validation branch 2 times, most recently from ed31a03 to b9abc71 Compare August 9, 2019 08:23
@errordeveloper
Copy link
Contributor Author

@rndstr thanks, indeed this is getting a little mad. I've added a method that wraps it up.

- perform defaulting and validation in all commands
- check region is supported
@errordeveloper errordeveloper force-pushed the defaulting-and-validation branch from f4b3b5c to 3f90efe Compare August 9, 2019 09:01

if !ctl.IsSupportedRegion() {
return cmdutils.ErrUnsupportedRegion(rc.ProviderConfig)
ctl, err := rc.NewCtl()
Copy link
Contributor

Choose a reason for hiding this comment

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

If we pass a ClusterProvider as an argument to command handlers like doCreateCluster, instead of constructing it here, we can inject a ClusterProvider with fake AWS API clients for api.ClusterProvider. That'd let us unit-test command handlers.

Copy link
Contributor Author

@errordeveloper errordeveloper Aug 9, 2019

Choose a reason for hiding this comment

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

Indeed, but let's make that change separately. I'm just trying to take care of consistency here. I think that change will be easier to make now.

Actually, we could just make it happen inside of NewCtl, i.e. make it possible to set the provider implementation in ResourceCmd (which gets constructed before the handler function runs).

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to do it later in a separate PR.

api.SetNodeGroupDefaults(i, ng)
}

ctl := eks.New(rc.ProviderConfig, rc.ClusterConfig)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be something like:

if rc.MockProvider != nil {
  return rc.MockProvider, nil
}

ctl := eks.New(rc.ProviderConfig, rc.ClusterConfig)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But let's leave until next iteration, I also have a PR to rename rc to simply cmd, which I promised to Martina a long time ago.

@errordeveloper errordeveloper merged commit eb57480 into master Aug 9, 2019
@errordeveloper errordeveloper deleted the defaulting-and-validation branch August 9, 2019 09:21
torredil pushed a commit to torredil/eksctl that referenced this pull request May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants