Skip to content

Commit

Permalink
fix k8s plugin discovery to allow multiple addrs on an endpoint, bump…
Browse files Browse the repository at this point in the history
… version (#217)
  • Loading branch information
edaniszewski committed Oct 24, 2018
1 parent 955f789 commit 6650dbc
Show file tree
Hide file tree
Showing 6 changed files with 681 additions and 50 deletions.
2 changes: 1 addition & 1 deletion synse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

__title__ = 'synse'
__version__ = '2.2.0'
__version__ = '2.2.1'
__description__ = 'Synse Server'
__author__ = 'Vapor IO'
__author_email__ = 'vapor@vapor.io'
Expand Down
74 changes: 42 additions & 32 deletions synse/discovery/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,23 @@ def _register_from_endpoints(cfg):

# Now we parse out the endpoints to get the routing info to a plugin.
# There are some assumptions here:
# - There is only one Pod address for the endpoint (e.g. the first address
# in the addresses list that is for kind Pod is used)
# - The port must have the name 'http'
for endpoint in endpoints.items:
name = endpoint.metadata.name
logger.debug(_('Found endpoint with name: {}').format(name))

ip = None
port = None

for subset in endpoint.subsets:
ips = []
port = None

addresses = subset.addresses
if addresses is None:
if not addresses:
logger.debug(_('No addresses for subset of endpoint - skipping ({})').format(name))
continue

# Iterate over all of the addresses. If there are multiple instances of a plugin
# sitting behind a service, e.g. a DaemonSet or Deployment with replica count > 1,
# then we will want to reach all of the plugins.
for address in addresses:
ref = address.target_ref
if ref is None:
Expand All @@ -100,38 +101,47 @@ def _register_from_endpoints(cfg):
logger.debug(_('Address is not a pod address - skipping ({})').format(address))
continue

ip = address.ip
break
ips.append(address.ip)

# If we don't have the IP yet, there is no point in getting the port for
# If we don't have any IPs yet, there is no point in getting the port for
# for this subset, so just continue.
if not ip:
logger.debug(_('No ip found for endpoint, will not search for port'))
if not ips:
logger.debug(_('No ips found for endpoint, will not search for port'))
continue

# Parse the ports. If there is only one port, use that port. Otherwise, use the
# port named 'http'.
ports = subset.ports
if ports is None:
if not ports:
logger.debug(_('No ports for subset of endpoint - skipping ({})').format(name))
continue

for port in ports:
if port.name != 'http':
logger.debug(
_('skipping port (want name:http, but found name:{})')
.format(port.get('name'))
)
continue

port = port.port
break

if ip is not None and port is not None:
break

logger.debug(_('endpoint.name={}, ip={}, port={}').format(name, ip, port))
if ip is None or port is None:
logger.debug(_('No ip/port found for endpoint {} - skipping').format(name))
continue

found.append('{}:{}'.format(ip, port))
if len(ports) == 1:
port = ports[0].port
else:
# Search for a port with name 'http'
for p in ports:
if p.name != 'http':
logger.debug(
_('skipping port (want name:http, but found name:{})')
.format(p.name)
)
continue

port = p.port
break

# If we have addresses and we have a port, we can register those endpoints
# as plugins. Otherwise, we move on.
if ips and port is not None:
for ip in ips:
logger.debug(_('found plugin: endpoint.name={}, ip={}, port={}').format(
name, ip, port
))
found.append('{}:{}'.format(ip, port))

if not found:
logger.debug(
_('Did not find any plugins via kubernetes endpoints (labels={})').format(labels)
)
return found
42 changes: 25 additions & 17 deletions synse/locale/en_US/LC_MESSAGES/synse.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Synse Server VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-10-19 11:12-0400\n"
"POT-Creation-Date: 2018-10-24 11:18-0400\n"
"PO-Revision-Date: 2018-04-23 14:33-0400\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
Expand Down Expand Up @@ -325,40 +325,40 @@ msgstr ""
msgid "Using endpoint label selector: {}"
msgstr ""

#: synse/discovery/kubernetes.py:81
#: synse/discovery/kubernetes.py:79
msgid "Found endpoint with name: {}"
msgstr ""

#: synse/discovery/kubernetes.py:89
#: synse/discovery/kubernetes.py:87
msgid "No addresses for subset of endpoint - skipping ({})"
msgstr ""

#: synse/discovery/kubernetes.py:95
#: synse/discovery/kubernetes.py:96
msgid "Address has no target_ref - skipping ({})"
msgstr ""

#: synse/discovery/kubernetes.py:100
#: synse/discovery/kubernetes.py:101
msgid "Address is not a pod address - skipping ({})"
msgstr ""

#: synse/discovery/kubernetes.py:109
msgid "No ip found for endpoint, will not search for port"
msgid "No ips found for endpoint, will not search for port"
msgstr ""

#: synse/discovery/kubernetes.py:114
#: synse/discovery/kubernetes.py:116
msgid "No ports for subset of endpoint - skipping ({})"
msgstr ""

#: synse/discovery/kubernetes.py:120
#: synse/discovery/kubernetes.py:126
msgid "skipping port (want name:http, but found name:{})"
msgstr ""

#: synse/discovery/kubernetes.py:131
msgid "endpoint.name={}, ip={}, port={}"
#: synse/discovery/kubernetes.py:138
msgid "found plugin: endpoint.name={}, ip={}, port={}"
msgstr ""

#: synse/discovery/kubernetes.py:133
msgid "No ip/port found for endpoint {} - skipping"
#: synse/discovery/kubernetes.py:145
msgid "Did not find any plugins via kubernetes endpoints (labels={})"
msgstr ""

#: synse/proto/client.py:86
Expand Down Expand Up @@ -489,11 +489,7 @@ msgstr ""
msgid "Invalid data POSTed for write. Must contain \"action\" and/or \"raw\""
msgstr ""

#: synse/scheme/read.py:59
msgid "Formatting read response"
msgstr ""

#: synse/scheme/read.py:91
#: synse/scheme/read.py:90
msgid "Found unexpected reading type \"{}\" for device {}"
msgstr ""

Expand Down Expand Up @@ -716,3 +712,15 @@ msgstr ""
#~ msgid "Reading value for {} came back as empty/null"
#~ msgstr ""

#~ msgid "No ip found for endpoint, will not search for port"
#~ msgstr ""

#~ msgid "endpoint.name={}, ip={}, port={}"
#~ msgstr ""

#~ msgid "No ip/port found for endpoint {} - skipping"
#~ msgstr ""

#~ msgid "Formatting read response"
#~ msgstr ""

Empty file.

0 comments on commit 6650dbc

Please sign in to comment.