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

Commit

Permalink
[feat] adding sequenced deployments
Browse files Browse the repository at this point in the history
* added new structure to the armada yaml
  • Loading branch information
gardlt committed Jun 30, 2017
1 parent 51358bd commit 55c3a0f
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 396 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ The installation is fairly straight forward:

Recomended Enviroment: Ubuntu 16.04

Installing Dependecies:
~~~~~~~~~~~~~~~~~~~~~~~
Installing Dependecies
~~~~~~~~~~~~~~~~~~~~~~

you can run:

Expand All @@ -72,8 +72,8 @@ you can run:

NOTE: If you want to use virtualenv please refer to `pygit2`_

Installing armada:
~~~~~~~~~~~~~~~~~~
Installing armada
~~~~~~~~~~~~~~~~~

``sudo pip install -e .``

Expand Down
197 changes: 104 additions & 93 deletions armada/handlers/armada.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ def find_release_chart(self, known_releases, name):
return chart, values

def pre_flight_checks(self):
for ch in self.config['armada']['charts']:
location = ch.get('chart').get('source').get('location')
ct_type = ch.get('chart').get('source').get('type')
for group in self.config.get('armada').get('charts'):
for ch in group.get('chart_group'):
location = ch.get('chart').get('source').get('location')
ct_type = ch.get('chart').get('source').get('type')

if ct_type == 'git' and not git.check_available_repo(location):
raise ValueError(str("Invalid Url Path: " + location))
if ct_type == 'git' and not git.check_available_repo(location):
raise ValueError(str("Invalid Url Path: " + location))

if not self.tiller.tiller_status():
raise Exception("Tiller Services is not Available")
Expand All @@ -93,6 +94,8 @@ def sync(self):
Syncronize Helm with the Armada Config(s)
'''

# TODO: (gardlt) we need to break up this func into
# a more cleaner format
# extract known charts on tiller right now
if not self.skip_pre_flight:
LOG.info("Performing Pre-Flight Checks")
Expand All @@ -109,96 +112,104 @@ def sync(self):

for entry in self.config['armada']['charts']:

chart = dotify(entry['chart'])
values = entry.get('chart').get('values', {})
pre_actions = {}
post_actions = {}

if chart.release_name is None:
continue

# retrieve appropriate timeout value if 'wait' is specified
chart_timeout = None
if self.wait:
if self.timeout:
chart_timeout = self.timeout
elif getattr(chart, 'timeout', None):
chart_timeout = chart.timeout

# initialize helm chart and request a
# protoc helm chart object which will
# pull the sources down and walk the
# dependencies
chartbuilder = ChartBuilder(chart)
protoc_chart = chartbuilder.get_helm_chart()

# determine install or upgrade by examining known releases
LOG.debug("RELEASE: %s", chart.release_name)

if release_prefix(prefix, chart.release_name) in [x[0]
for x in
known_releases]:

# indicate to the end user what path we are taking
LOG.info("Upgrading release %s", chart.release_name)
# extract the installed chart and installed values from the
# latest release so we can compare to the intended state
installed_chart, installed_values = self.find_release_chart(
known_releases, release_prefix(prefix, chart.release_name))

LOG.info("Checking Pre/Post Actions")
upgrade = entry.get('chart', {}).get('upgrade', False)
if upgrade:
if not self.disable_update_pre and upgrade.get('pre',
False):
pre_actions = getattr(chart.upgrade, 'pre', {})

if not self.disable_update_post and upgrade.get('post',
False):
LOG.info("Checking Post Actions")
post_actions = getattr(chart.upgrade, 'post', {})

# show delta for both the chart templates and the chart values
# TODO(alanmeadows) account for .files differences
# once we support those

upgrade_diff = self.show_diff(chart, installed_chart,
installed_values,
chartbuilder.dump(), values)

if not upgrade_diff:
LOG.info("There are no updates found in this chart")
desc = entry.get('description', 'A Chart Group')
chart_group = entry.get('chart_group', [])

if entry.get('sequenced', False):
self.wait = True

LOG.info('Deploying: %s', desc)

for gchart in chart_group:
chart = dotify(gchart['chart'])
values = gchart.get('chart').get('values', {})
pre_actions = {}
post_actions = {}
LOG.info('%s', chart.release_name)

if chart.release_name is None:
continue

# do actual update
self.tiller.update_release(protoc_chart,
self.dry_run,
chart.release_name,
chart.namespace,
prefix, pre_actions,
post_actions,
disable_hooks=chart.
upgrade.no_hooks,
values=yaml.safe_dump(values),
wait=self.wait,
timeout=chart_timeout)

# process install
else:
LOG.info("Installing release %s", chart.release_name)
self.tiller.install_release(protoc_chart,
self.dry_run,
chart.release_name,
chart.namespace,
prefix,
values=yaml.safe_dump(values),
wait=self.wait,
timeout=chart_timeout)

LOG.debug("Cleaning up chart source in %s",
chartbuilder.source_directory)

chartbuilder.source_cleanup()
# retrieve appropriate timeout value if 'wait' is specified
chart_timeout = None
if self.wait:
if getattr(chart, 'timeout', None):
chart_timeout = chart.timeout
else:
chart_timeout = self.timeout

chartbuilder = ChartBuilder(chart)
protoc_chart = chartbuilder.get_helm_chart()

# determine install or upgrade by examining known releases
LOG.debug("RELEASE: %s", chart.release_name)
deployed_releases = [x[0] for x in known_releases]
prefix_chart = release_prefix(prefix, chart.release_name)

if prefix_chart in deployed_releases:

# indicate to the end user what path we are taking
LOG.info("Upgrading release %s", chart.release_name)
# extract the installed chart and installed values from the
# latest release so we can compare to the intended state
LOG.info("Checking Pre/Post Actions")
apply_chart, apply_values = self.find_release_chart(
known_releases, prefix_chart)

LOG.info("Checking Pre/Post Actions")
upgrade = gchart.get('chart', {}).get('upgrade', False)

if upgrade:
if not self.disable_update_pre and upgrade.get('pre',
False):
pre_actions = getattr(chart.upgrade, 'pre', {})

if not self.disable_update_post and upgrade.get('post',
False):
post_actions = getattr(chart.upgrade, 'post', {})

# show delta for both the chart templates and the chart
# values
# TODO(alanmeadows) account for .files differences
# once we support those

upgrade_diff = self.show_diff(chart, apply_chart,
apply_values,
chartbuilder.dump(), values)

if not upgrade_diff:
LOG.info("There are no updates found in this chart")
continue

# do actual update
self.tiller.update_release(protoc_chart,
self.dry_run,
chart.release_name,
chart.namespace,
prefix, pre_actions,
post_actions,
disable_hooks=chart.
upgrade.no_hooks,
values=yaml.safe_dump(values),
wait=self.wait,
timeout=chart_timeout)

# process install
else:
LOG.info("Installing release %s", chart.release_name)
self.tiller.install_release(protoc_chart,
self.dry_run,
chart.release_name,
chart.namespace,
prefix,
values=yaml.safe_dump(values),
wait=self.wait,
timeout=chart_timeout)

LOG.debug("Cleaning up chart source in %s",
chartbuilder.source_directory)

chartbuilder.source_cleanup()

if self.enable_chart_cleanup:
self.tiller.chart_cleanup(prefix, self.config['armada']['charts'])
Expand Down
60 changes: 30 additions & 30 deletions armada/tests/unit/handlers/test_armada.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,37 @@

class ArmadaTestCase(unittest.TestCase):
test_yaml = """
endpoints: &endpoints
hello-world:
this: is an example
armada:
release_prefix: armada
charts:
- chart:
name: test_chart_1
release_name: test_chart_1
namespace: test
values: {}
source:
type: null
location: null
subpath: null
reference: null
dependencies: []
timeout: 50
- description: this is a test
sequenced: False
chart_group:
- chart:
name: test_chart_1
release_name: test_chart_1
namespace: test
values: {}
source:
type: null
location: null
subpath: null
reference: null
dependencies: []
timeout: 50
- chart:
name: test_chart_2
release_name: test_chart_2
namespace: test
values: {}
source:
type: null
location: null
subpath: null
reference: null
dependencies: []
timeout: 5
- chart:
name: test_chart_2
release_name: test_chart_2
namespace: test
values: {}
source:
type: null
location: null
subpath: null
reference: null
dependencies: []
timeout: 5
"""

@mock.patch('armada.handlers.armada.ChartBuilder')
Expand All @@ -57,8 +56,9 @@ def test_install(self, mock_tiller, mock_chartbuilder):
armada.tiller = mock_tiller
armada.config = yaml.load(self.test_yaml)

chart_1 = armada.config['armada']['charts'][0]['chart']
chart_2 = armada.config['armada']['charts'][1]['chart']
charts = armada.config['armada']['charts'][0]['chart_group']
chart_1 = charts[0]['chart']
chart_2 = charts[1]['chart']

# mock irrelevant methods called by armada.sync()
mock_tiller.list_charts.return_value = []
Expand Down
40 changes: 22 additions & 18 deletions armada/tests/unit/utils/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ def test_lint_armada_yaml_pass(self):
armada:
release_prefix: armada-test
charts:
- chart:
name: chart
release_name: chart
namespace: chart
- chart_group:
- chart:
name: chart
release_name: chart
namespace: chart
""")
resp = lint.valid_manifest(config)
self.assertTrue(resp)
Expand All @@ -37,10 +38,11 @@ def test_lint_armada_keyword_removed(self):
armasda:
release_prefix: armada-test
charts:
- chart:
name: chart
release_name: chart
namespace: chart
- chart_group:
- chart:
name: chart
release_name: chart
namespace: chart
""")

with self.assertRaises(Exception):
Expand All @@ -51,24 +53,26 @@ def test_lint_prefix_keyword_removed(self):
armada:
release: armada-test
charts:
- chart:
name: chart
release_name: chart
namespace: chart
- chart_group:
- chart:
name: chart
release_name: chart
namespace: chart
""")

with self.assertRaises(Exception):
lint.valid_manifest(config)

def test_lint_armada_removed(self):
config = yaml.load("""
armasda:
sarmada:
release_prefix: armada-test
chart:
- chart:
name: chart
release_name: chart
namespace: chart
charts:
- chart_group:
- chart:
name: chart
release_name: chart
namespace: chart
""")

with self.assertRaises(Exception):
Expand Down
Loading

0 comments on commit 55c3a0f

Please sign in to comment.