Skip to content

Commit

Permalink
buildchain/salt: use Renderer
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
slaperche-scality committed Dec 16, 2019
1 parent 2e41926 commit fc8a11e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 43 deletions.
56 changes: 27 additions & 29 deletions buildchain/buildchain/salt_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


import abc
import base64
import importlib
from pathlib import Path
import sys
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down
14 changes: 0 additions & 14 deletions salt/metalk8s/addons/dex/deployed/theme-configmap.sls.in

This file was deleted.

0 comments on commit fc8a11e

Please sign in to comment.