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

Default Address Pool Code Refactor #2732

Merged
merged 1 commit into from
Sep 10, 2018
Merged

Conversation

selansen
Copy link
Contributor

We have two params that have been passed around as part of swarm init
config. As part of refactoring the code, we created NetworkConfig struct
and added address pool and subnet mask length as part of the new struct
Older PR review comment has been addressed in this commit.
Signed-off-by: selansen elango.siva@docker.com

- What I did

- How I did it

- How to test it

- Description for the changelog

@selansen selansen force-pushed the default_addr_pool branch 3 times, most recently from 11174f0 to 3ef05f3 Compare August 29, 2018 16:55
@codecov
Copy link

codecov bot commented Aug 29, 2018

Codecov Report

Merging #2732 into master will increase coverage by 0.03%.
The diff coverage is 51.51%.

@@            Coverage Diff             @@
##           master    #2732      +/-   ##
==========================================
+ Coverage   61.77%   61.81%   +0.03%     
==========================================
  Files         134      134              
  Lines       21888    21832      -56     
==========================================
- Hits        13522    13495      -27     
+ Misses       6903     6881      -22     
+ Partials     1463     1456       -7

@selansen selansen force-pushed the default_addr_pool branch 2 times, most recently from d434ab0 to de69ddc Compare August 30, 2018 19:19
@@ -67,8 +67,26 @@ type networkContext struct {
somethingWasDeallocated bool
}

// NetworkConfig is used to store network related cluster config in the Manager.
type NetworkConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have two definitions of this?

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 had faced cyclic import issue again so I ended up using similar struct in cnmnetworkallocator

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. We can create a new file for the config and add the struct there. Duplicate definitions is not great for maintainability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

again...we need to create new package for this I guess. looks like placing new file in existing package will lead into same issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to find a way to solve this. As I said, having two definitions is not maintainable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not just put it in package cnallocator and use it from there?

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 thought we are trying to put in a logical place. Let me see if I can move around.

func (a *Allocator) doNetworkInit(ctx context.Context) (err error) {
na, err := cnmallocator.New(a.pluginGetter, a.defaultAddrPool, a.subnetSize)
var netConfig *cnmallocator.NetworkConfig
if a.networkConfig != nil && a.networkConfig.DefaultAddrPool != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

is the a.networkConfig.DefaultAddrPool != nil check needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was one CI test case was failing due to segment fault . Hence added extra check

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Do we know why? Is the assignment below doing a dereference?

Copy link
Contributor Author

@selansen selansen Aug 31, 2018

Choose a reason for hiding this comment

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

I saw illegal memory access info and segmentation fault. So i added this extra check. dont remember full details now. I can go back to old code and get full details if you want.

if newCluster.DefaultAddressPool == nil {
// This is just for CLI display. Set the inbuilt default pool for
// user reference.
newCluster.DefaultAddressPool = []string{"10.0.0.0/8"}
Copy link
Contributor

Choose a reason for hiding this comment

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

lets define constants for these defaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. will do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@anshulpundir I can't make slice as constant (go doesnt allow it). But created as regular variable.
I made subnetsize as constant variable. Hope this is fine with you.

manager/manager.go Show resolved Hide resolved

// SubnetSize specifies the subnet size of the networks created from
// the default subnet pool
SubnetSize uint32
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason to use int32 instead of int?

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 value can never be negative . hence I use uint32. We use uint32 even in storing it in cluster object.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it. I was also wondering if there is a motivation to use uint32? If not, maybe just use uint?

Copy link
Contributor Author

@selansen selansen Aug 31, 2018

Choose a reason for hiding this comment

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

Yes. int and uint are 64-bit on 64-bit architecture and 32 bit on 32-bit architecture. Hence I wanted to use unit32.

@selansen selansen force-pushed the default_addr_pool branch 2 times, most recently from 9f4bf58 to eb9ac0b Compare August 31, 2018 16:18
@selansen selansen force-pushed the default_addr_pool branch 2 times, most recently from a6d8e98 to 7574634 Compare September 7, 2018 21:51
 We have two params that have been passed around as part of swarm init
config. As part of refactoring the code, we created NetworkConfig struct
and added address pool and subnet mask length as part of the new struct
Older PR review comment has been addressed in this commit.
Signed-off-by: selansen <elango.siva@docker.com>
@dperny
Copy link
Collaborator

dperny commented Sep 10, 2018

I like that we've factored two fields into 1 config object. However, I don't like that it requires us to import github.com/docker/swarmkit/manager/allocator/cnmallocator everywhere. I think that breaks the separation of concerns, and will make moving to the new allocator more difficult.

This is not a blocker, though. If you think that's the best solution, feel free to disagree, and I'll LGTM.

@selansen
Copy link
Contributor Author

I tried to move around many places and everywhere I had circle import error.
If you think this will affect our new allocator, I can create separate package like Anshul’s alternate suggestion only for this struct. but that doesn't seem to be good design approach ( having one just for a one object) so I told him lets not do it. Any other idea ?

@dperny
Copy link
Collaborator

dperny commented Sep 10, 2018

Nah, this is fine.

@dperny dperny merged commit d7d23d7 into moby:master Sep 10, 2018
tiborvass pushed a commit to tiborvass/docker that referenced this pull request Sep 22, 2018
This also brings in these PRs from swarmkit:
- moby/swarmkit#2691
- moby/swarmkit#2744
- moby/swarmkit#2732
- moby/swarmkit#2729
- moby/swarmkit#2748

Signed-off-by: Tibor Vass <tibor@docker.com>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Sep 22, 2018
This also brings in these PRs from swarmkit:
- moby/swarmkit#2691
- moby/swarmkit#2744
- moby/swarmkit#2732
- moby/swarmkit#2729
- moby/swarmkit#2748

Signed-off-by: Tibor Vass <tibor@docker.com>
Upstream-commit: cce1763d57b5c8fc446b0863517bb5313e7e53be
Component: engine
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