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 23, 2017
1 parent f6971ac commit 515977b
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 89 deletions.
185 changes: 100 additions & 85 deletions armada/handlers/armada.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,27 @@ 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")
if not self.tiller.tiller_status():
raise Exception("Tiller Services is not Available")

if not lint.valid_manifest(self.config):
raise Exception("Invalid Armada Manifest")
if not lint.valid_manifest(self.config):
raise Exception("Invalid Armada Manifest")

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 @@ -108,84 +111,94 @@ 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

# 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')
sequence = entry.get('sequenced', False)
chart_group = entry.get('chart_group', [])

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

# 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))

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

chartbuilder.source_cleanup()
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))
if sequence:
LOG.info(" Let Wait until the chart is in ready state")

# 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))
if sequence:
LOG.info(" Let Wait until the chart is in ready state")

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

chartbuilder.source_cleanup()

# if requested, wait for chart deployment
if self.wait:
Expand Down Expand Up @@ -245,6 +258,8 @@ def wait_for_deployment(self):
elif (pod.status.phase == RUN_STATUS or
pod.status.phase == SUCCESS_STATUS):
pods.remove(pod)

pods = self.tiller.k8s.get_all_pods().items
except:
timer.cancel()
pass
Expand Down
22 changes: 18 additions & 4 deletions armada/utils/lint.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# Copyright 2017 The Armada Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARMADA_DEFINITION = 'armada'
RELEASE_PREFIX = 'release_prefix'
CHARTS_DEFINITION = 'charts'


def valid_manifest(config):
if not (isinstance(config.get(ARMADA_DEFINITION, None), dict)):
if not isinstance(config.get(ARMADA_DEFINITION, None), dict):
raise Exception("Did not declare armada object")

armada_config = config.get('armada')
Expand All @@ -16,8 +29,9 @@ def valid_manifest(config):
if not isinstance(armada_config.get(CHARTS_DEFINITION), list):
raise Exception('Check yaml invalid chart definition must be array')

for chart in armada_config.get('charts', []):
if not isinstance(chart.get('chart').get('name'), basestring):
raise Exception('Chart name needs to be a string')
for group in armada_config.get('charts'):
for chart in group.get('chart_group'):
if not isinstance(chart.get('chart').get('name'), basestring):
raise Exception('Chart name needs to be a string')

return True
25 changes: 25 additions & 0 deletions examples/hello-world.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
armada:
release_prefix: stable

charts:
- chart: &hello-world
name: hello-world
release_name: blog
namespace: blog
install:
no_hooks: false
upgrade:
no_hooks: false
pre:
delete: []
create: []
post:
delete: []
create: []
values: {}
source:
type: git
location: https://github.com/gardlt/hello-world-chart
subpath: .
reference: master
dependencies: []
Loading

0 comments on commit 515977b

Please sign in to comment.