From 9fabf9a94d7c5efd70bcb7d06d02cbf328fdb436 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Sat, 13 Apr 2019 05:06:27 +0200 Subject: [PATCH] Make sure no end-of-document marker (`...`) is written Technically it's correct to add an end-of-document mark to the output. However, `kubectl` and `Flux` (before https://github.com/weaveworks/flux/pull/1931 ) choke on it. This change makes sure we always use `---` markers to separate documents and that we never add `...`. --- kubeyaml.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kubeyaml.py b/kubeyaml.py index 343303f..e90435e 100644 --- a/kubeyaml.py +++ b/kubeyaml.py @@ -39,6 +39,7 @@ def note(s): def yaml(): y = YAML() y.explicit_start = True + y.explicit_end = False y.preserve_quotes = True return y @@ -46,12 +47,23 @@ def bail(reason): sys.stderr.write(reason); sys.stderr.write('\n') sys.exit(2) +class AlwaysFalse(object): + def __init__(self): + pass + + def __get__(self, instance, owner): + return False + + def __set__(self, instance, value): + pass + def apply_to_yaml(fn, infile, outfile): # fn :: iterator a -> iterator b y = yaml() + # Hack to make sure no end-of-document ("...") is ever added + y.Emitter.open_ended = AlwaysFalse() docs = y.load_all(infile) - for doc in fn(docs): - y.dump(doc, outfile) + y.dump_all(fn(docs), outfile) def update_image(args, docs): """Update the manifest specified by args, in the stream of docs"""