Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Properly support multi-document yaml files. #117

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/todocontroller/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: todo-controller-staging
annotations:
rules-k8s.bazel.io/foo: |
---
foo: bar
spec:
replicas: 1
template:
Expand Down
3 changes: 3 additions & 0 deletions k8s/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ par_binary(
srcs = ["reverser.py"],
main = "reverser.py",
visibility = ["//visibility:public"],
deps = [
"@yaml",
],
)
8 changes: 2 additions & 6 deletions k8s/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
'publishing them.'))

_THREADS = 32
_DOCUMENT_DELIMITER = '---\n'


def Resolve(input, string_to_digest):
Expand Down Expand Up @@ -79,7 +78,7 @@ def walk(o):
return walk_string(o)
return o

return yaml.dump(walk(yaml.load(input)))
return yaml.dump_all(map(walk, yaml.load_all(input)))


def StringToDigest(string, overrides, transport):
Expand Down Expand Up @@ -186,10 +185,7 @@ def _StringToDigest(t):
unseen_strings.remove(t)
return StringToDigest(t, overrides, transport)

content = _DOCUMENT_DELIMITER.join([
Resolve(x, _StringToDigest)
for x in inputs.split(_DOCUMENT_DELIMITER)
])
content = Resolve(inputs, _StringToDigest)

if len(unseen_strings) > 0:
print('The following image references were not found: [%s]' % "\n".join([
Expand Down
7 changes: 2 additions & 5 deletions k8s/reverser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from __future__ import print_function

import argparse

import yaml

parser = argparse.ArgumentParser(
description='Reverse a potential multi-document input.')
Expand All @@ -25,17 +25,14 @@
'--template', action='store',
help='The template file to resolve.')

_DOCUMENT_DELIMITER = '---\n'


def main():
args = parser.parse_args()

with open(args.template, 'r') as f:
inputs = f.read()

content = _DOCUMENT_DELIMITER.join(
reversed(inputs.split(_DOCUMENT_DELIMITER)))
content = yaml.dump_all(reversed([x for x in yaml.load_all(inputs)]))

print(content)

Expand Down