This repository has been archived by the owner on Feb 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ashcrow/container-mgr
Code looks good. Testing of code on Atomic host works as expected. Issue has been defined due to starting of docker service on rhel but issue only occurs every now and then.
- Loading branch information
Showing
33 changed files
with
525 additions
and
72 deletions.
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
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,8 @@ | ||
commissaire.containermgr.kubernetes package | ||
=========================================== | ||
|
||
.. automodule:: commissaire.containermgr.kubernetes | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
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,15 @@ | ||
commissaire.containermgr package | ||
================================ | ||
|
||
.. automodule:: commissaire.containermgr | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Subpackages | ||
----------- | ||
|
||
.. toctree:: | ||
|
||
commissaire.containermgr.kubernetes | ||
|
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,7 @@ | ||
commissaire.handlers.models module | ||
================================== | ||
|
||
.. automodule:: commissaire.handlers.models | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,7 @@ | ||
commissaire.jobs.clusterexec module | ||
=================================== | ||
|
||
.. automodule:: commissaire.jobs.clusterexec | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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 |
---|---|---|
|
@@ -11,5 +11,6 @@ Submodules | |
|
||
.. toctree:: | ||
|
||
commissaire.jobs.clusterexec | ||
commissaire.jobs.investigator | ||
|
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,7 @@ | ||
commissaire.oscmd.redhat module | ||
=============================== | ||
|
||
.. automodule:: commissaire.oscmd.redhat | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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 |
---|---|---|
|
@@ -13,5 +13,6 @@ Submodules | |
|
||
commissaire.oscmd.atomic | ||
commissaire.oscmd.fedora | ||
commissaire.oscmd.redhat | ||
commissaire.oscmd.rhel | ||
|
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ bcrypt | |
python-etcd==0.4.2 | ||
setuptools | ||
ansible>=2.0.0.2 | ||
jinja2 | ||
jinja2 |
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,43 @@ | ||
# Copyright (C) 2016 Red Hat, Inc | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
The container manager package. | ||
""" | ||
|
||
import logging | ||
|
||
|
||
class ContainerManagerBase(object): # pragma: no cover | ||
""" | ||
Base class for all container managers. | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Creates a new instance of the ContainerManagerBase. | ||
""" | ||
self.logger = logging.getLogger('containermgr') | ||
|
||
def node_registered(self, name): | ||
""" | ||
Checks is a node was registered. | ||
:param name: The name of the node. | ||
:type name: str | ||
:returns: True if registered, otherwise False | ||
:rtype: bool | ||
""" | ||
raise NotImplementedError( | ||
'ContainerManagerBase().node_registered() must be overridden.') |
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,90 @@ | ||
# Copyright (C) 2016 Red Hat, Inc | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
The kubernetes container manager package. | ||
""" | ||
|
||
import requests | ||
|
||
from commissaire.containermgr import ContainerManagerBase | ||
|
||
|
||
class ContainerManager(ContainerManagerBase): | ||
""" | ||
Kubernetes container manager implementation. | ||
""" | ||
|
||
def __init__(self, connection_config): | ||
""" | ||
Creates an instance of the Kubernetes Container Manager. | ||
:param connection_config: External resource connection information. | ||
:type connection_config: dict | ||
""" | ||
ContainerManagerBase.__init__(self) | ||
self.host = connection_config['kubernetes']['uri'].hostname | ||
self.port = connection_config['kubernetes']['uri'].port | ||
self.con = requests.Session() | ||
token = connection_config['kubernetes']['token'] | ||
self.con.headers["Authorization"] = "Bearer {0}".format(token) | ||
# TODO: Verify TLS!!! | ||
self.con.verify = False | ||
self.base_uri = 'http://{0}:{1}/api/v1'.format( | ||
self.host, self.port) | ||
print('Kubernetes Container Manager: {0}'.format( | ||
self.__dict__)) | ||
|
||
def _get(self, part, *args, **kwargs): | ||
""" | ||
Get information from the Kubernetes apiserver. | ||
:param part: The URI part. EG: /nodes | ||
:type part: sdtr | ||
:param args: All other non-keyword arguments. | ||
:type args: tuple | ||
:param kwargs: All other keyword arguments. | ||
:type kwargs: dict | ||
:returns: requests.Response | ||
""" | ||
# Fix part if it doesn't start with a slash | ||
if not part.startswith('/'): | ||
part = '/{0}'.format(part) | ||
|
||
self.logger.debug('Executing GET for {0}'.format(part)) | ||
resp = self.con.get( | ||
'{0}{1}'.format(self.base_uri, part), *args, **kwargs) | ||
self.logger.debug('Response for {0}. Status: {1}'.format( | ||
part, resp.status_code)) | ||
return resp | ||
|
||
def node_registered(self, name): | ||
""" | ||
Checks is a node was registered. | ||
:param name: The name of the node. | ||
:type name: str | ||
:returns: True if registered, otherwise False | ||
:rtype: bool | ||
""" | ||
part = '/nodes/{0}'.format(name) | ||
resp = self._get(part) | ||
# TODO: Stronger checking would be better | ||
if resp.status_code == 200: | ||
return True | ||
return False | ||
|
||
|
||
#: Friendly name for the class | ||
KubeContainerManager = ContainerManager |
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,19 @@ | ||
apiVersion: v1 | ||
clusters: | ||
api-version: v1 | ||
insecure-skip-tls-verify: true | ||
server: http://{{ kubernetes_api_server_host }}:{{ kubernetes_api_server_port }} | ||
name: cluster | ||
contexts: | ||
- context: | ||
cluster: cluster | ||
namespace: default | ||
user: commissairenode | ||
name: context | ||
kind: Config | ||
preferences: | ||
colors: false | ||
users: | ||
- name: commissairenode | ||
user: | ||
token: {{ kubernetes_bearer_token }} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
KUBELET_ADDRESS="--address={{ bootstrap_ip }}" | ||
KUBELET_ADDRESS="--address=0.0.0.0" | ||
KUBELET_HOSTNAME="--hostname_override={{ bootstrap_ip }}" | ||
KUBELET_API_SERVER="--api_servers=http://{{ kubernetes_api_server_host }}:{{ kubernetes_api_server_port }}" |
Oops, something went wrong.