Kubernetes container handler #68
Kubernetes container handler #68
Conversation
1886cb0
to
5a89921
Compare
@mbarnes this PR ready to have it's spelling mistakes found. 😆 |
I see one already. 😉 |
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.
Looks good, just a few nits, some of which are deferrable.
if not part.startswith('/'): | ||
self.logger.debug( | ||
'Part given without starting slash. Adding...') | ||
part = '/{}'.format(part) |
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.
nit: This could just be part = '/' + part
. Optional; not gonna block over it.
:returns: requests.Response | ||
""" | ||
part = self._fix_part(part) | ||
payload = json.dumps(payload) |
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.
nit: Type-flipping is kinda sneaky; I'd prefer a different name, like payload_str
.
@@ -93,6 +93,22 @@ def check_config(cls, config): | |||
'Server URL scheme must be "https" when using client ' | |||
'side certificates (got "{}")'.format(url.scheme)) | |||
|
|||
def _fix_part(self, part): | |||
""" | |||
Fixes part if it doesn't start with a slash. |
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.
Clearer wording: Ensures the URI part starts with a slash.
:returns: requests.Response | ||
""" | ||
part = self._fix_part(part) | ||
payload = json.dumps(payload) |
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.
nit: Type-flipping is kinda sneaky; I'd prefer a different name, like payload_str
.
self.logger.error( | ||
'Non-created response when trying to register the node {}.' | ||
'Status: {}, Data: {}'.format(name, resp.status_code, resp.text)) | ||
return False |
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.
Not a blocker, but eating the status code here might bite you later. Maybe return it instead of a bool, or better raise an exception with the code embedded if it's not 2xx? I seem to recall doing something like that in the past.
I'm okay with calling it tech debt for now.
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'll look at doing the raise
pattern.
self.logger.error( | ||
'Unexpected response when trying to remove the node {}.' | ||
'Status: {}, Data: {}'.format(name, resp.status_code, resp.text)) | ||
return False |
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.
See my other comment about eating the status code.
if raw: | ||
data = data['status'] | ||
return data | ||
return False |
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.
See my other comment about eating the status code.
Also, None
seems like a better fallback value than False
.
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.
👍
Also included _post which is used by register_node.
Also added _delete which is used by remove_node.
9b6f572
to
2b7ca59
Compare
⬆️ |
@@ -225,10 +226,12 @@ def register_node(self, name): | |||
resp = self._post(part, payload) | |||
if resp.status_code == 201: | |||
return True |
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.
Not to be overly nit-picky, but you could eliminate the return value since it will never return False
. It either works or throws an exception.
:rtype: bool | ||
:raises: commissaire.containermgr.ContainerManagerError | ||
""" | ||
part = '/nodes/{}'.format(name) | ||
|
||
resp = self._delete(part) | ||
if resp.status_code == 200: | ||
return True |
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.
See other return value comment.
:rtype: bool | ||
:raises: commissaire.containermgr.ContainerManagerError | ||
""" | ||
part = '/nodes/{0}'.format(name) | ||
resp = self._get(part) | ||
# TODO: Stronger checking would be better | ||
if resp.status_code == 200: | ||
return True |
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.
See other return value comment.
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.
Are you saying something like:
if resp.status_code != 200:
raise ....
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.
Yeah, or maybe raise on anything outside the 2xx range.
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.
👍
⬆️ |
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.
Fixup looks good but there's a couple other places where this can be done (see below).
Grrr... can't seem to link to specific lines. They're in |
@mbarnes ok I'll update them with the same patterns. |
⬆️ |
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.
Nice! Looks good.
Retooling the old Kubernetes container manager code for the new service.