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

Commit

Permalink
Merge pull request #24 from ashcrow/container-mgr
Browse files Browse the repository at this point in the history
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
cooktheryan committed Feb 10, 2016
2 parents b2d4972 + a168447 commit 950921a
Show file tree
Hide file tree
Showing 33 changed files with 525 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ RUN dnf remove -y gcc git redhat-rpm-config libffi-devel && dnf clean all

EXPOSE 8000
WORKDIR /commissaire
CMD . /environment/bin/activate && python src/commissaire/script.py ${ETCD}
CMD . /environment/bin/activate && python src/commissaire/script.py -e ${ETCD} -k ${KUBE}
5 changes: 5 additions & 0 deletions conf/logger.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"level": "DEBUG",
"propagate": false
},
"containermgr": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": false
},
"investigator": {
"handlers": ["console"],
"level": "DEBUG",
Expand Down
8 changes: 8 additions & 0 deletions doc/apidoc/commissaire.containermgr.kubernetes.rst
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:

15 changes: 15 additions & 0 deletions doc/apidoc/commissaire.containermgr.rst
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

7 changes: 7 additions & 0 deletions doc/apidoc/commissaire.handlers.models.rst
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:
1 change: 1 addition & 0 deletions doc/apidoc/commissaire.handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Submodules

commissaire.handlers.clusters
commissaire.handlers.hosts
commissaire.handlers.models
commissaire.handlers.status

7 changes: 7 additions & 0 deletions doc/apidoc/commissaire.jobs.clusterexec.rst
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:
1 change: 1 addition & 0 deletions doc/apidoc/commissaire.jobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Submodules

.. toctree::

commissaire.jobs.clusterexec
commissaire.jobs.investigator

7 changes: 7 additions & 0 deletions doc/apidoc/commissaire.oscmd.redhat.rst
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:
1 change: 1 addition & 0 deletions doc/apidoc/commissaire.oscmd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Submodules

commissaire.oscmd.atomic
commissaire.oscmd.fedora
commissaire.oscmd.redhat
commissaire.oscmd.rhel

1 change: 1 addition & 0 deletions doc/apidoc/commissaire.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Subpackages

commissaire.authentication
commissaire.compat
commissaire.containermgr
commissaire.handlers
commissaire.jobs
commissaire.oscmd
Expand Down
2 changes: 1 addition & 1 deletion doc/endpoints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ Retrieve a the status of the system.
"in_use": int, // Amount of the pool in use
"errors": [string,...], // Errors from the pool
}
}
},
}
.. note::
Expand Down
58 changes: 40 additions & 18 deletions doc/gettingstarted.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
Getting Started
===============

Installation
------------

Development/Manual
~~~~~~~~~~~~~~~~~~
Development/Manual Installation
--------------------------------
To test out the current development code you will need the following installed:

* Python2.6
* virtualenv
* etcd2 (running)
* Kubernetes Cluster with a bearer token for access (running)
* (Optional) docker (running)

Set up virtualenv
`````````````````
~~~~~~~~~~~~~~~~~

.. code-block:: shell
Expand All @@ -25,7 +23,7 @@ Set up virtualenv
...
(Optional): Run Unittests
`````````````````````````
~~~~~~~~~~~~~~~~~~~~~~~~~
From the repo root...

.. code-block:: shell
Expand All @@ -35,15 +33,20 @@ From the repo root...
(virtualenv)$ python setup.py nosetests
Adding a Host Manually
``````````````````````
~~~~~~~~~~~~~~~~~~~~~~

.. todo::

Remove this once container registration work is merged.

Verify that etcd is running then execute...

.. code-block:: shell
(virtualenv)$ etcdctl set /commissaire/hosts/10.0.0.1 '{"address": "10.0.0.1","status": "available","os": "atomic","cpus": 2,"memory": 11989228,"space": 487652,"last_check": "2015-12-17T15:48:18.710454","ssh_priv_key": "dGVzdAo=", "cluster": "default"}'
(Optional): Put Configs in Etcd
```````````````````````````````
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commissaire will default back to the local files but using Etcd is where configuration should be stored.

.. code-block:: shell
Expand All @@ -53,23 +56,42 @@ commissaire will default back to the local files but using Etcd is where configu
(virtualenv)$ cat conf/logger.json | etcdctl set '/commissaire/config/logger'
...
Running the service
```````````````````
From the repo root...
Set The Kubernetes Bearer Token
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You'll also need to set the kubernetes bearer token.

.. note:: There is no default bearer token!

.. code-block:: shell
(virtualenv)$ PYTHONPATH=`pwd`/src python src/commissaire/script.py http://127.0.0.1:2379 &
...
Building and Running commissaire in a container
```````````````````````````````````````````````
(virtualenv)$ etcdctl set '/commissaire/config/kubetoken' $KUBERNETES_ACCESS_TOKEN
(Optional): Build Docker Container
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From the repo root build the image...

.. code-block:: shell
docker build --tag commissaire .
...
To run the image specify the ETCD variable pointing towards the running etcd service.
Running the service
~~~~~~~~~~~~~~~~~~~

From Source
```````````
From the repo root...

.. code-block:: shell
docker run -d -e ETCD=http://192.168.1.100:2379 commissaire
(virtualenv)$ PYTHONPATH=`pwd`/src python src/commissaire/script.py -e http://127.0.0.1:2379 -k http://127.0.0.1:8080 &
...
Via Docker
``````````
To run the image specify the ETCD and KUBE variables pointing towards the specific services.

.. code-block:: shell
docker run -d -e ETCD=http://127.0.0.1:2379 -e KUBE=http://127.0.0.1:8080 commissaire
...
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ bcrypt
python-etcd==0.4.2
setuptools
ansible>=2.0.0.2
jinja2
jinja2
43 changes: 43 additions & 0 deletions src/commissaire/containermgr/__init__.py
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.')
90 changes: 90 additions & 0 deletions src/commissaire/containermgr/kubernetes/__init__.py
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
19 changes: 19 additions & 0 deletions src/commissaire/data/templates/kubeconfig
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 }}
2 changes: 1 addition & 1 deletion src/commissaire/data/templates/kubelet
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 }}"

0 comments on commit 950921a

Please sign in to comment.