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

View File

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