Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Kubernetes container handler #68

Merged
merged 22 commits into from Dec 8, 2016

Conversation

ashcrow
Copy link
Collaborator

@ashcrow ashcrow commented Dec 6, 2016

Retooling the old Kubernetes container manager code for the new service.

@ashcrow
Copy link
Collaborator Author

ashcrow commented Dec 6, 2016

@ashcrow ashcrow force-pushed the kubernetes-container-handler branch from 1886cb0 to 5a89921 Compare December 7, 2016 19:28
@ashcrow ashcrow changed the title WIP: Kubernetes container handler Kubernetes container handler Dec 7, 2016
@ashcrow ashcrow removed the WIP label Dec 7, 2016
@ashcrow
Copy link
Collaborator Author

ashcrow commented Dec 7, 2016

@mbarnes this PR ready to have it's spelling mistakes found. 😆

@mbarnes
Copy link
Contributor

mbarnes commented Dec 7, 2016

@mbarnes this PR ready to have it's spelling mistakes found. 😆

I see one already. 😉

@mbarnes mbarnes self-assigned this Dec 7, 2016
Copy link
Contributor

@mbarnes mbarnes left a 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)
Copy link
Contributor

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)
Copy link
Contributor

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.
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Collaborator Author

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@ashcrow ashcrow force-pushed the kubernetes-container-handler branch from 9b6f572 to 2b7ca59 Compare December 7, 2016 23:04
@ashcrow
Copy link
Collaborator Author

ashcrow commented Dec 7, 2016

⬆️

@@ -225,10 +226,12 @@ def register_node(self, name):
resp = self._post(part, payload)
if resp.status_code == 201:
return True
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Collaborator Author

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 ....

Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@ashcrow
Copy link
Collaborator Author

ashcrow commented Dec 8, 2016

⬆️

Copy link
Contributor

@mbarnes mbarnes left a 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).

@mbarnes
Copy link
Contributor

mbarnes commented Dec 8, 2016

Grrr... can't seem to link to specific lines.

They're in register_node() and remove_node().

@ashcrow
Copy link
Collaborator Author

ashcrow commented Dec 8, 2016

@mbarnes ok I'll update them with the same patterns.

@ashcrow
Copy link
Collaborator Author

ashcrow commented Dec 8, 2016

⬆️

Copy link
Contributor

@mbarnes mbarnes left a comment

Choose a reason for hiding this comment

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

Nice! Looks good.

@mbarnes mbarnes merged commit 84ca57b into projectatomic:master Dec 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants