-
Notifications
You must be signed in to change notification settings - Fork 132
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
Configurable grid subnet, supernet #1323
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c91875f
server: grid subnet, supernet; host node overlay_ip
963617b
cli: use grid subnet, supernet, node overlay_ip
4b24993
agent: add IPAddr helpers
803f6a3
agent: use grid subnet, supernet; host node overlay_ip
66e528b
kontena grid create --subnet= --supernet=
089a8af
agent: only migrate overlay_cidr for 0.16 containers that do not have…
c34df48
agent: refactor etcd launcher specs to use context node_info
0195cde
docs update for grid subnet, supernet
cc60f79
Document grid subnet options
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class IPAddr | ||
# @return [Number] CIDR prefix length suffix | ||
def prefixlen | ||
@mask_addr.to_s(2).count('1') | ||
end | ||
|
||
# @return [String] The address + netmask in W.X.Y.Z/P format | ||
# | ||
# For a host address, this will include the /32 suffix | ||
def to_cidr | ||
"#{to_s}/#{prefixlen}" | ||
end | ||
|
||
def hostmask | ||
case @family | ||
when Socket::AF_INET | ||
(IN4MASK ^ @mask_addr) | ||
when Socket::AF_INET6 | ||
(IN6MASK ^ @mask_addr) | ||
else | ||
raise AddressFamilyError, "unsupported address family" | ||
end | ||
end | ||
|
||
# @return [IPAddr) last address in subnet] | ||
def last | ||
self | hostmask | ||
end | ||
|
||
# @return [IPAddr] ith address in subnet | ||
def [](i) | ||
raise ArgumentError, "IP #{i} outside of subnet #{inspect}" if i > hostmask | ||
|
||
self | i | ||
end | ||
|
||
# Split subnet into lower and upper subnets | ||
# @return [IPAddr, IPAddr] two sub-subnets | ||
def split | ||
high_bit = hostmask + 1 >> 1 | ||
splitlen = prefixlen + 1 | ||
|
||
return [ | ||
mask(splitlen), | ||
mask(splitlen) | high_bit, | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
describe IPAddr do | ||
describe '#prefixlen' do | ||
it 'has a prefix length' do | ||
expect(IPAddr.new('0.0.0.0/0').prefixlen).to eq 0 | ||
expect(IPAddr.new('10.80.0.0/12').prefixlen).to eq 12 | ||
expect(IPAddr.new('10.80.0.0/24').prefixlen).to eq 24 | ||
expect(IPAddr.new('10.80.0.1/24').prefixlen).to eq 24 | ||
expect(IPAddr.new('10.80.1.1/32').prefixlen).to eq 32 | ||
end | ||
end | ||
|
||
describe 'last' do | ||
it 'returns the correct IPAddr' do | ||
expect(IPAddr.new('10.81.0.0/16').last.to_s).to eq '10.81.255.255' | ||
end | ||
end | ||
|
||
describe '#[]' do | ||
context "for 10.81.0.0/16" do | ||
subject do | ||
IPAddr.new('10.81.0.0/16') | ||
end | ||
|
||
it 'returns the correct IP' do | ||
expect(subject[0].to_s).to eq '10.81.0.0' | ||
expect(subject[1].to_s).to eq '10.81.0.1' | ||
expect(subject[2].to_s).to eq '10.81.0.2' | ||
expect(subject[255].to_s).to eq '10.81.0.255' | ||
expect(subject[256].to_s).to eq '10.81.1.0' | ||
expect(subject[257].to_s).to eq '10.81.1.1' | ||
expect(subject[256 * 256 - 1].to_s).to eq '10.81.255.255' | ||
end | ||
|
||
it 'raises on invalid offset' do | ||
expect{subject[256 * 256]}.to raise_error(ArgumentError) | ||
expect{subject[256 * 256 + 1]}.to raise_error(ArgumentError) | ||
end | ||
end | ||
end | ||
|
||
describe '#split' do | ||
context "for 10.81.0.0/16" do | ||
subject do | ||
IPAddr.new('10.81.0.0/16') | ||
end | ||
|
||
it "splits in twain" do | ||
expect(subject.split.map{|i| i.to_cidr}).to eq ['10.81.0.0/17', '10.81.128.0/17'] | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're doing IPAddr patching in many places now, maybe it's time to roll these as a separate gem? (not maybe part of this PR, but overall)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the stdlib
IPAddr
is really inadequate. I figure these should be replaced with theipaddress
gem.The worst part is the crazy-looking
IPAddr
operations on the server, likeThis would be make somewhat more sense with the agent IPAddr patching (
IPAddr.new(self.grid.subnet)[self.node_number]
), but the way the kontena repo is structured, there's no easy way to share code between across all three sub-components...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I fix all the server and agent stuff to start using
ipaddress
in this PR, or later?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do it later as separate exercise.