Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

106 - Binary data support #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions compiled/echo-server/manifests/echo-server-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apiVersion: v1
binaryData:
binary.dat: ?{base64:eyJkYXRhIjogIlFVRkJRVUZCUVVFPSIsICJlbmNvZGluZyI6ICJiYXNlNjQiLCAidHlwZSI6ICJiYXNlNjQifQ==:embedded}
data:
echo-service.conf: '# A configuration file

Expand Down
2 changes: 2 additions & 0 deletions compiled/tutorial/manifests/echo-server-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apiVersion: v1
binaryData:
binary.dat: ?{base64:eyJkYXRhIjogIlFVRkJRVUZCUVVFPSIsICJlbmNvZGluZyI6ICJiYXNlNjQiLCAidHlwZSI6ICJiYXNlNjQifQ==:embedded}
data:
echo-service.conf: '# A configuration file

Expand Down
4 changes: 4 additions & 0 deletions components/generators/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def body(self):
super().body()
self.add_namespace(inv.parameters.namespace)
config = self.kwargs.config

component = self.kwargs.component
self.add_labels(component.globals.config_maps.labels)

Expand All @@ -141,6 +142,9 @@ def body(self):
if "template" in config_spec:
self.root.data[key] = j2(config_spec.template, config_spec.get('values', {}))

for key, spec in config.binary_data.items():
if "value" in spec:
self.root.binaryData[key] = spec.get('value')

class Secret(k8s.Base):
def new(self):
Expand Down
28 changes: 28 additions & 0 deletions components/generators/manifests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,34 @@ metadata:
namespace: tutorial
```

### Binary files in config maps

While `data` is the most commonly used directive, `config maps` also support the `binary_data` keyword to allow for binary files to be embedded.
Please note that only the `value` directive is supported, and it should be used with a pre-encoded value (either from a reference file, or a base64 encoded string)

```yaml
config_maps:
config:
binary_data:
binary.dat:
value: ?{base64:encoded_binary_file}
```

This will create a ConfigMap resource with a binary file, taken from the specified base64 encoded reference.

```yaml
cat compiled/tutorial/manifests/echo-server-config.yml
apiVersion: v1
binaryData:
binary.dat: ?{base64:eyJkYXRhIjogIlFVR.......}
kind: ConfigMap
metadata:
labels:
name: echo-server
name: echo-server
namespace: tutorial
```

### Mounting a config map
Note that in the previous example the config map is not mounted, because the `mount` directive is missing.

Expand Down
3 changes: 3 additions & 0 deletions inventory/classes/components/echo-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ parameters:
config:
mount: /opt/echo-service/echo-service.conf
subPath: echo-service.conf
binary_data:
binary.dat:
value: ?{base64:binary_file}
data:
echo-service.conf:
template: "components/echo-server/echo-server.conf.j2"
Expand Down
3 changes: 3 additions & 0 deletions refs/binary_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data: QUFBQUFBQUE=
encoding: base64
type: base64