[feature] creating-api-service

* cleaning deps
This commit is contained in:
gardlt 2017-04-18 10:16:07 -05:00
parent fb26d4ea2c
commit 3b09981597
7 changed files with 49 additions and 31 deletions

View File

@ -1,9 +1,11 @@
from supermutes.dot import dotify
from chartbuilder import ChartBuilder
from tiller import Tiller
from logutil import LOG
import yaml
import difflib
import yaml
from supermutes.dot import dotify
from handlers.chartbuilder import ChartBuilder
from handlers.tiller import Tiller
from logutil import LOG
class Armada(object):
'''
@ -16,19 +18,15 @@ class Armada(object):
Initialize the Armada Engine and establish
a connection to Tiller
'''
self.args = args
# internalize config
self.config = yaml.load(open(args.config).read())
self.tiller = Tiller()
def find_release_chart(self, known_releases, name):
'''
Find a release given a list of known_releases and a release name
'''
for chart_name, version, chart, values in known_releases:
for chart_name, _, chart, values in known_releases:
if chart_name == name:
return chart, values
@ -114,6 +112,7 @@ class Armada(object):
LOG.debug("Cleaning up chart source in %s",
chartbuilder.source_directory)
chartbuilder.source_cleanup()
if self.args.enable_chart_cleanup:

View File

View File

@ -1,14 +1,15 @@
import os
import yaml
from hapi.chart.template_pb2 import Template
from hapi.chart.chart_pb2 import Chart
from hapi.chart.metadata_pb2 import Metadata
from hapi.chart.config_pb2 import Config
from logutil import LOG
from supermutes.dot import dotify
import shutil
import tempfile
import pygit2
import os
import yaml
from armada.logutil import LOG
from armada.utils.git import git_clone, source_cleanup
class ChartBuilder(object):
'''
@ -50,9 +51,6 @@ class ChartBuilder(object):
'''
if self.chart.source.type == 'git':
tmpdir = tempfile.mkdtemp(prefix='armada', dir='/tmp')
self._source_tmp_dir = tmpdir
if self.parent:
LOG.info("Cloning %s/%s as dependency for %s",
self.chart.source.location,
@ -64,11 +62,10 @@ class ChartBuilder(object):
self.chart.source.subpath,
self.chart.release_name)
pygit2.clone_repository(self.chart.source.location, tmpdir,
checkout_branch=self.chart.
source.reference)
self._source_tmp_dir = git_clone(self.chart.source.location,
self.chart.source.reference)
return os.path.join(tmpdir, self.chart.source.subpath)
return os.path.join(self._source_tmp_dir, self.chart.source.subpath)
else:
LOG.exception("Unknown source type %s for chart %s",
@ -79,7 +76,7 @@ class ChartBuilder(object):
'''
Cleanup source
'''
shutil.rmtree(self._source_tmp_dir)
source_cleanup(self._source_tmp_dir)
def get_metadata(self):
'''

View File

@ -1,6 +1,7 @@
from kubernetes import client, config
from kubernetes.client.rest import ApiException
from logutil import LOG
from armada.logutil import LOG
class K8s(object):
'''
@ -40,5 +41,5 @@ class K8s(object):
This will return a list of objects req namespace
'''
res = self.client.list_namespaced_pod(namespace)
return res
return self.client.list_namespaced_pod(namespace)

View File

@ -1,10 +1,10 @@
import grpc
from hapi.services.tiller_pb2 import ReleaseServiceStub, ListReleasesRequest, \
InstallReleaseRequest, UpdateReleaseRequest, UninstallReleaseRequest
from hapi.chart.config_pb2 import Config
import grpc
from k8s import K8s
from logutil import LOG
from armada.handlers.k8s import K8s
from armada.logutil import LOG
TILLER_PORT = 44134
TILLER_VERSION = b'2.1.3'
@ -202,7 +202,7 @@ class Tiller(object):
self.timeout,
metadata=self.metadata)
def chart_cleanup(self, prefix, charts, known_releases):
def chart_cleanup(self, prefix, charts):
'''
:params charts - list of yaml charts
:params known_release - list of releases in tiller
@ -210,6 +210,9 @@ class Tiller(object):
:result - will remove any chart that is not present in yaml
'''
def release_prefix(prefix, chart):
'''
how to attach prefix to chart
'''
return "{}-{}".format(prefix, chart["chart"]["release_name"])
valid_charts = [release_prefix(prefix, chart) for chart in charts]

0
armada/utils/__init__.py Normal file
View File

18
armada/utils/git.py Normal file
View File

@ -0,0 +1,18 @@
import pygit2
import tempfile
import shutil
def git_clone(repo_url, branch='master'):
'''
clones repo to a /tmp/ dir
'''
_tmp_dir = tempfile.mkdtemp(prefix='armada', dir='/tmp')
pygit2.clone_repository(repo_url, _tmp_dir, checkout_branch=branch)
return _tmp_dir
def source_cleanup(target_dir):
'''
Clean up source
'''
shutil.rmtree(target_dir)