-
Notifications
You must be signed in to change notification settings - Fork 186
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
Add support for generating files from command output #223
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ Both are identical multi-arch images built for `amd64`, `arm64`, `arm/v7`, `ppc6 | |
- Update/Delete on change of configmap or secret | ||
- Enforce unique filenames | ||
|
||
# Usage | ||
# Usage | ||
|
||
Example for a simple deployment can be found in [`example.yaml`](./example.yaml). Depending on the cluster setup you have to grant yourself admin rights first: | ||
```shell | ||
|
@@ -48,6 +48,7 @@ metadata: | |
``` | ||
|
||
If the filename ends with `.url` suffix, the content will be processed as a URL which the target file contents will be downloaded from. | ||
If the filename ends with `.command` suffix, the content will be processed as a shell command which will be executed. Stdout of the command will be stored in the file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a small example (as yaml block) showing the 3 different variants here? |
||
|
||
## Configuration Environment Variables | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,19 @@ data: | |
# base64 encoded: my super cool \n multiline \ secret | ||
secret.world: bXkgc3VwZXIgY29vbAptdWx0aWxpbmUKc2VjcmV0 | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: output-of-command | ||
labels: | ||
findme: "yup" | ||
data: | ||
rand.sh: | | ||
#!/bin/sh | ||
dd if=/dev/random bs=4 count=1 | hexdump -v -e '/1 "%02X"' | ||
random.txt.command: '/tmp/rand.sh' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this example is only reliable if the key-values of a configmap are actually sorted when accessed through the python client. Otherwise occasionally the command is executed before the shell script is stored. Could you double check this? |
||
hostname.txt.command: '/bin/hostname' | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
|
@@ -97,4 +110,3 @@ subjects: | |
- kind: ServiceAccount | ||
name: sample-acc | ||
namespace: default | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,15 +43,18 @@ def signal_handler(signum, frame): | |
signal.signal(signal.SIGTERM, signal_handler) | ||
|
||
|
||
def _get_file_data_and_name(full_filename, content, enable_5xx, content_type=CONTENT_TYPE_TEXT): | ||
def _get_file_data_and_name(full_filename, content, enable_5xx, content_type=CONTENT_TYPE_TEXT, remove=False): | ||
if content_type == CONTENT_TYPE_BASE64_BINARY: | ||
file_data = base64.b64decode(content) | ||
else: | ||
file_data = content | ||
|
||
if full_filename.endswith(".url"): | ||
if full_filename.endswith(".url") and not remove: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this change breaks removal as the returned filename would still contain the suffix |
||
filename = full_filename[:-4] | ||
file_data = request(file_data, "GET", enable_5xx).text | ||
elif full_filename.endswith(".command") and not remove: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment above |
||
filename = full_filename[:-8] | ||
file_data = execute(file_data).stdout | ||
else: | ||
filename = full_filename | ||
|
||
|
@@ -187,7 +190,8 @@ def _update_file(data_key, data_content, dest_folder, metadata, resource, | |
filename, file_data = _get_file_data_and_name(data_key, | ||
data_content, | ||
enable_5xx, | ||
content_type) | ||
content_type, | ||
remove) | ||
if unique_filenames: | ||
filename = unique_filename(filename=filename, | ||
namespace=metadata.namespace, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the example script this assertions is likely to fail (as the script generates random hex text, doesn't it?)