fix: Align template file naming with Helm CLI

Armada has previously name template files relative to the
`templates` dir, whereas the Helm CLI names them relative
to the chart root. This causes `include`s of these templates
to fail.

This change fixes this, for armada/Chart/v2 docs only, since it
is a breaking change, as some charts may have already aligned
with the existing Armada behavior, and even if they didn't,
changing the template names causes a chart to need to upgrade
even with no other changes, so that should be an explicit
decision.

Change-Id: I243073ca4c2e1edbcb0d8f649475f568fc7c818f
This commit is contained in:
Sean Eagan 2019-09-09 11:48:05 -05:00
parent cb0d90839a
commit 75a849ba93
3 changed files with 37 additions and 10 deletions

View File

@ -25,6 +25,7 @@ from oslo_log import log as logging
import yaml
from armada.exceptions import chartbuilder_exceptions
from armada.handlers.schema import get_schema_info
from armada import const
LOG = logging.getLogger(__name__)
@ -51,18 +52,31 @@ class ChartBuilder(object):
source_dir = chart_data.get('source_dir')
source_directory = os.path.join(*source_dir)
dependencies = chart_data.get('dependencies')
# TODO: Remove when v1 doc support is removed.
schema_info = get_schema_info(chart['schema'])
if schema_info.version < 2:
fix_tpl_name = False
else:
fix_tpl_name = True
if dependencies is not None:
dependency_builders = []
for chart_dep in dependencies:
builder = ChartBuilder.from_chart_doc(chart_dep)
dependency_builders.append(builder)
return cls(name, source_directory, dependency_builders)
return cls(
name,
source_directory,
dependency_builders,
fix_tpl_name=fix_tpl_name)
return cls.from_source(name, source_directory)
return cls.from_source(
name, source_directory, fix_tpl_name=fix_tpl_name)
@classmethod
def from_source(cls, name, source_directory):
def from_source(cls, name, source_directory, fix_tpl_name=False):
'''
Returns a ChartBuilder, which gets it dependencies from within the Helm
chart itself.
@ -84,12 +98,15 @@ class ChartBuilder(object):
if re.match(r'^[._]', f.name):
continue
builder = ChartBuilder.from_source(f.name, f.path)
builder = ChartBuilder.from_source(
f.name, f.path, fix_tpl_name=fix_tpl_name)
dependency_builders.append(builder)
return cls(name, source_directory, dependency_builders)
def __init__(self, name, source_directory, dependency_builders):
def __init__(
self, name, source_directory, dependency_builders,
fix_tpl_name=False):
'''
:param name: A name to use for the chart.
:param source_directory: The source directory of the Helm chart.
@ -99,6 +116,7 @@ class ChartBuilder(object):
self.name = name
self.source_directory = source_directory
self.dependency_builders = dependency_builders
self.fix_tpl_name = fix_tpl_name
# cache for generated protoc chart object
self._helm_chart = None
@ -248,17 +266,16 @@ class ChartBuilder(object):
'''
chart_name = self.name
templates = []
if not os.path.exists(os.path.join(self.source_directory,
'templates')):
tpl_dir = os.path.join(self.source_directory, 'templates')
if not os.path.exists(tpl_dir):
LOG.warn(
"Chart %s has no templates directory. "
"No templates will be deployed", chart_name)
for root, _, files in os.walk(os.path.join(self.source_directory,
'templates'), topdown=True):
for root, _, files in os.walk(tpl_dir, topdown=True):
for tpl_file in files:
tname = os.path.relpath(
os.path.join(root, tpl_file),
os.path.join(self.source_directory, 'templates'))
self.source_directory if self.fix_tpl_name else tpl_dir)
if self.ignore_file(tname):
LOG.debug('Ignoring file %s', tname)
continue

View File

@ -60,6 +60,7 @@ class BaseChartBuilderTestCase(testtools.TestCase):
"""
chart_stream = """
schema: armada/Chart/v1
metadata:
name: test
data:
@ -90,6 +91,7 @@ class BaseChartBuilderTestCase(testtools.TestCase):
"""
dependency_chart_stream = """
schema: armada/Chart/v1
metadata:
name: dep
data:
@ -127,6 +129,7 @@ class BaseChartBuilderTestCase(testtools.TestCase):
def _get_test_chart(self, chart_dir):
return {
'schema': 'armada/Chart/v1',
'metadata': {
'name': 'test'
},

View File

@ -56,6 +56,13 @@ Chart
| now optional, deafults to no | |
| subpath. | |
+--------------------------------+------------------------------------------------------------+
| Template naming for template | Be aware that upgrading a release with v2, which was |
| files (not `define`s) aligned | previously deployed with v1, will cause Armada to see a |
| with Helm CLI. | diff in the template names, even if there are no other |
| | changes. Also if a chart was relying on Armada's |
| | misaligned template naming, such as via ``include`` |
| | argument, that argument will need to be updated. |
+--------------------------------+------------------------------------------------------------+
| ``wait`` improvements | See `Wait Improvements`_. |
+--------------------------------+------------------------------------------------------------+