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

Refactor and increase test coverage for creating nodegroups #3728

Merged
merged 12 commits into from
May 27, 2021

Conversation

nikimanoledaki
Copy link
Contributor

@nikimanoledaki nikimanoledaki commented May 18, 2021

Description

Closes #3699

Related to #2931

Adds unit test for pkg/actions/nodegroup.create to increase test coverage. Tests failures as well as successfully creating managed nodes, creating unmanaged nodes, and creating nodes with or without all of the CreateOpts.

New Interfaces

  • The interface KubeProvider has some functions from the ClusterProvider struct that did not previously belong to any interface and were therefore hard to mock.
  • The interface NodeGroupInitialiser has functions from the NodeGroupService struct.
  • The interface NodegroupFilter has functions from the struct NodeGroupFilter (StackLister had to be exported in order to be able to mock it).
  • Mocks were generated for these new interfaces with Counterfeiter and used in the unit tests.

Refactoring the main Create function

  • Adds 2 setter funcs for NodeManager to mock out 2 of its fields without having to change the code in all the other packages where NodeManager is used.
  • Moved part of the Create func to a new func UpdateAuthConfigMap that is now part of the KubeProvider interface.
  • Splits part of the Create function to a new func nodeCreationTasks so this reduces it from ~200 to ~120 LOC.

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the userdocs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes
  • (Core team) Added labels for change area (e.g. area/nodegroup) and kind (e.g. kind/improvement)

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@nikimanoledaki nikimanoledaki changed the title Refactor and increase test coverage for nodegroup creation Refactor and increase test coverage for creating nodegroups May 19, 2021
@nikimanoledaki nikimanoledaki marked this pull request as ready for review May 19, 2021 14:04
@nikimanoledaki nikimanoledaki requested a review from cPu1 May 20, 2021 15:26
@nikimanoledaki
Copy link
Contributor Author

@aclevername I implemented your review feedback and then manually created a nodegroup to test the changes - no regression!

@@ -18,6 +18,8 @@ type Manager struct {
cfg *api.ClusterConfig
clientSet *kubernetes.Clientset
wait WaitFunc
init eks.NodeGroupInitialiser
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like init is a bit vague, but not sure on a better name 🤷‍♂️

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 initialiser, while verbose, would be clearer. init as we know it in Go does shorthand initialise, but it may be helpful to clarify that we don't mean that kind of init.

Copy link
Contributor

@aclevername aclevername left a comment

Choose a reason for hiding this comment

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

LGTM! Big PR so worth waiting for 2 accepting reviews before merging IMO 😄

Copy link
Contributor

@Callisto13 Callisto13 left a comment

Choose a reason for hiding this comment

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

Great work 🎉

I just have a couple of comments on really superficial things.

pkg/ctl/cmdutils/filter/nodegroup_filter.go Outdated Show resolved Hide resolved
pkg/eks/api.go Outdated Show resolved Hide resolved
pkg/eks/nodegroup_service.go Outdated Show resolved Hide resolved
pkg/actions/nodegroup/create_test.go Outdated Show resolved Hide resolved
pkg/actions/nodegroup/create_test.go Outdated Show resolved Hide resolved
pkg/ctl/cmdutils/filter/nodegroup_filter.go Outdated Show resolved Hide resolved
pkg/actions/nodegroup/create.go Show resolved Hide resolved
pkg/ctl/cmdutils/filter/nodegroup_filter.go Outdated Show resolved Hide resolved
Remove KubeProvider from v1alpha5 types

Generate KubeProvider mocks to be used by Nodegroup unit tests

* Abstracts some of ClusterProvider's functions into a KubeProvider interface in pkg/eks/kubeprovider.go
* Generates mocks for KubeProvider in pkg/eks/fakes
* Passes KubeProvider to the ClusterProvider struct
* Mocks calls to KubeProvider's functions in pkg/actions/nodegroups/create.go and pkg/actions/nodegroups/create_test.go
* Test for failing to load VPC from config
* Test when cluster does not support managed nodes
* Test for when cluster is not compatible with ng config
* Test for when existing local ng stacks in config file fail to be listed
* Unit test ng creation when failing to validate legacy subnets for ng

* Transcribe go pkg tests to ginkgo tests

* Test whether ng uses IRSA, test that stack manager does tasks

* Test evaluates whether aws-node uses IRSA
* Test checks if stack manager fails to do ng tasks

* Test ng is created without errors - happy path

* Test ng creation with dry run option

* Test creating ng will all options

* Unit test creating managed nodegroups

* Refactored WaitForNodes from ClusterProvider to nodeGroupService
* Refactor WaitTimeout to KubeProvider
* Refactor UpdateAuthConfigMap to nodeGroupService
nikimanoledaki and others added 5 commits May 27, 2021 16:01
* Move ValidateExistingNodeGroupsForCompatibility to nodegroup initialiser interface
* Move DoAllNodegroupStackTasks to nodegroup initialiser interface
* Get rid of counterfeiter warning when generating mocks
* Update doc comments
* Rename unit test names to more descriptive names

Co-authored-by: Claudia <claudiaberesford@gmail.com>
Copy link
Contributor

@Callisto13 Callisto13 left a comment

Choose a reason for hiding this comment

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

:shipit:

@nikimanoledaki nikimanoledaki merged commit 516eabd into main May 27, 2021
@nikimanoledaki nikimanoledaki deleted the test-ng branch May 27, 2021 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor ClusterProvider to improve mocking in Nodegroup unit tests
4 participants