Fix to pass a manifest file to the armada server

This PS changes the 'apply' cli to generate documents object from
a manifest file and pass it to the armada server.

Change-Id: I19241e2aa0b2c82dfbc043ba8ad8e0482922ff5c
This commit is contained in:
DaeSeong Kim 2018-05-29 18:45:27 -07:00
parent f43cb33c81
commit caeb4b623a
2 changed files with 29 additions and 22 deletions

View File

@ -85,6 +85,9 @@ SHORT_DESC = "Command installs manifest charts."
@click.option('--enable-chart-cleanup',
help="Clean up unmanaged charts.",
is_flag=True)
@click.option('--use-doc-ref',
help="Use armada manifest file reference.",
is_flag=True)
@click.option('--set',
help=("Use to override Armada Manifest values. Accepts "
"overrides that adhere to the format "
@ -130,13 +133,13 @@ SHORT_DESC = "Command installs manifest charts."
is_flag=True)
@click.pass_context
def apply_create(ctx, locations, api, disable_update_post, disable_update_pre,
dry_run, enable_chart_cleanup, set, tiller_host, tiller_port,
tiller_namespace, timeout, values, wait, target_manifest,
debug):
dry_run, enable_chart_cleanup, use_doc_ref, set, tiller_host,
tiller_port, tiller_namespace, timeout, values, wait,
target_manifest, debug):
CONF.debug = debug
ApplyManifest(ctx, locations, api, disable_update_post, disable_update_pre,
dry_run, enable_chart_cleanup, set, tiller_host, tiller_port,
tiller_namespace, timeout, values, wait,
dry_run, enable_chart_cleanup, use_doc_ref, set, tiller_host,
tiller_port, tiller_namespace, timeout, values, wait,
target_manifest).safe_invoke()
@ -149,6 +152,7 @@ class ApplyManifest(CliAction):
disable_update_pre,
dry_run,
enable_chart_cleanup,
use_doc_ref,
set,
tiller_host,
tiller_port,
@ -166,6 +170,7 @@ class ApplyManifest(CliAction):
self.disable_update_pre = disable_update_pre
self.dry_run = dry_run
self.enable_chart_cleanup = enable_chart_cleanup
self.use_doc_ref = use_doc_ref
self.set = set
self.tiller_host = tiller_host
self.tiller_port = tiller_port
@ -190,19 +195,19 @@ class ApplyManifest(CliAction):
self.logger.info('Chart/values diff: %s', ch)
def invoke(self):
if not self.ctx.obj.get('api', False):
try:
doc_data = ReferenceResolver.resolve_reference(self.locations)
documents = list()
for d in doc_data:
documents.extend(list(yaml.safe_load_all(d.decode())))
except InvalidPathException as ex:
self.logger.error(str(ex))
return
except yaml.YAMLError as yex:
self.logger.error("Invalid YAML found: %s" % str(yex))
return
try:
doc_data = ReferenceResolver.resolve_reference(self.locations)
documents = list()
for d in doc_data:
documents.extend(list(yaml.safe_load_all(d.decode())))
except InvalidPathException as ex:
self.logger.error(str(ex))
return
except yaml.YAMLError as yex:
self.logger.error("Invalid YAML found: %s" % str(yex))
return
if not self.ctx.obj.get('api', False):
armada = Armada(
documents,
disable_update_pre=self.disable_update_pre,
@ -239,7 +244,10 @@ class ApplyManifest(CliAction):
}
client = self.ctx.obj.get('CLIENT')
resp = client.post_apply(
manifest_ref=self.locations, set=self.set, query=query)
if self.use_doc_ref:
resp = client.post_apply(
manifest_ref=self.locations, set=self.set, query=query)
else:
resp = client.post_apply(
manifest=documents, set=self.set, query=query)
self.output(resp.get('message'))

View File

@ -100,9 +100,8 @@ class ArmadaClient(object):
if manifest:
if values or set:
document = list(yaml.safe_load_all(manifest))
override = Override(
document, overrides=set, values=values).update_manifests()
manifest, overrides=set, values=values).update_manifests()
manifest = yaml.dump(override)
resp = self.session.post(
endpoint,