Skip to content

Commit

Permalink
Use hostname for finding a node when setting labels (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakolehm committed May 16, 2018
1 parent b5067c0 commit 5796695
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions lib/pharos/phases/label_node.rb
Expand Up @@ -39,12 +39,11 @@ def patch_node(node)
end

def find_node
internal_ip = @host.peer_address
node = nil
retries = 0
while node.nil? && retries < 10
node = kube.get_nodes.find { |n|
n.status.addresses.any? { |a| a.type == 'InternalIP' && a.address == internal_ip }
n.metadata.name == @host.hostname
}
unless node
retries += 1
Expand Down
16 changes: 7 additions & 9 deletions spec/pharos/phases/label_node_spec.rb
Expand Up @@ -16,26 +16,24 @@
allow(subject).to receive(:sleep)
end

it 'finds node via address' do
it 'finds node via hostname' do
host.hostname = 'host-01'
allow(kube).to receive(:get_nodes).and_return([
Kubeclient::Resource.new({
status: {
addresses: [
{ type: 'InternalIP', address: host.address }
]
metadata: {
name: host.hostname
}
})
])
expect(subject.find_node).not_to be_nil
end

it 'returns nil if node not found' do
host.hostname = 'host-01'
allow(kube).to receive(:get_nodes).and_return([
Kubeclient::Resource.new({
status: {
addresses: [
{ type: 'InternalIP', address: 'a.b.c.d' }
]
metadata: {
name: 'host-09'
}
})
])
Expand Down

0 comments on commit 5796695

Please sign in to comment.