From fc8a11e997ca2bffd328ccc14028c9e2b9380c08 Mon Sep 17 00:00:00 2001 From: Sylvain Laperche Date: Sun, 24 Nov 2019 14:36:33 +0100 Subject: [PATCH] buildchain/salt: use Renderer Use the brand new SaltState serializer to generate the Dex ConfigMap. Get rid of the now useless helper that were used to manually generate YAML-encoded strings. Closes: #2070 Signed-off-by: Sylvain Laperche --- buildchain/buildchain/salt_tree.py | 56 +++++++++---------- .../dex/deployed/theme-configmap.sls.in | 14 ----- 2 files changed, 27 insertions(+), 43 deletions(-) delete mode 100644 salt/metalk8s/addons/dex/deployed/theme-configmap.sls.in diff --git a/buildchain/buildchain/salt_tree.py b/buildchain/buildchain/salt_tree.py index 430f018fd2..b4bbd63a5b 100644 --- a/buildchain/buildchain/salt_tree.py +++ b/buildchain/buildchain/salt_tree.py @@ -29,7 +29,6 @@ import abc -import base64 import importlib from pathlib import Path import sys @@ -153,25 +152,6 @@ def _get_parts(self) -> Iterator[str]: return parts -def salt_embed_text(path: Path, indent: int) -> str: - """Return the content a text file in usable form by Salt.""" - data = ['|'] - with path.open(encoding='utf-8') as fp: - for line in fp: - data.append('{}{}'.format(' '*indent, line.rstrip())) - return '\n'.join(data) - - -def salt_embed_bytes(path: Path, indent: int) -> str: - """Return the content of a binary file in usable form by Salt.""" - data = ['|'] - bytestring = path.read_bytes() - b64data = base64.encodebytes(bytestring).decode('utf-8') - for line in b64data.split('\n'): - data.append('{}{}'.format(' '*indent, line.rstrip())) - return '\n'.join(data) - - PILLAR_FILES : Tuple[Union[Path, targets.AtomicTarget], ...] = ( Path('pillar/metalk8s/roles/bootstrap.sls'), Path('pillar/metalk8s/roles/ca.sls'), @@ -251,20 +231,38 @@ def salt_embed_bytes(path: Path, indent: int) -> str: Path('salt/metalk8s/addons/dex/deployed/namespace.sls'), Path('salt/metalk8s/addons/dex/deployed/tls-secret.sls'), Path('salt/metalk8s/addons/dex/deployed/clusterrolebinding.sls'), - targets.TemplateFile( + targets.SerializedData( task_name='theme-configmap.sls', - source=constants.ROOT.joinpath( - 'salt/metalk8s/addons/dex/deployed/theme-configmap.sls.in' - ), destination=constants.ISO_ROOT.joinpath( 'salt/metalk8s/addons/dex/deployed/theme-configmap.sls' ), - context={ - 'branding': salt_embed_bytes(SCALITY_LOGO, indent=4), - 'favicon': salt_embed_bytes(SCALITY_FAVICON, indent=4), - 'styles': salt_embed_text(LOGIN_STYLE, indent=4), - }, + data=targets.SaltState( + shebang='#!jinja | metalk8s_kubernetes', + imports=[], + content={ + 'apiVersion': 'v1', + 'kind': 'ConfigMap', + 'metadata': { + 'name': 'dex-login', + 'namespace': 'metalk8s-auth', + }, + 'data': { + 'styles.css': targets.YAMLDocument.text( + LOGIN_STYLE.read_text(encoding='utf-8') + ), + }, + 'binaryData': { + 'favicon.png': targets.YAMLDocument.bytestring( + SCALITY_FAVICON.read_bytes() + ), + 'logo.png': targets.YAMLDocument.bytestring( + SCALITY_LOGO.read_bytes() + ) + }, + }, + ), file_dep=[SCALITY_LOGO, SCALITY_FAVICON, LOGIN_STYLE], + renderer=targets.Renderer.SLS, ), Path('salt/metalk8s/addons/prometheus-operator/deployed/chart.sls'), Path('salt/metalk8s/addons/prometheus-operator/deployed/cleanup.sls'), diff --git a/salt/metalk8s/addons/dex/deployed/theme-configmap.sls.in b/salt/metalk8s/addons/dex/deployed/theme-configmap.sls.in deleted file mode 100644 index 104f7b107a..0000000000 --- a/salt/metalk8s/addons/dex/deployed/theme-configmap.sls.in +++ /dev/null @@ -1,14 +0,0 @@ -#!jinja | metalk8s_kubernetes - ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: dex-login - namespace: metalk8s-auth -data: - styles.css: @@styles -binaryData: - favicon.png: @@favicon - logo.png: @@branding -