<commit_before># Kubernetes environment generator

Makes [docker env files](https://docs.docker.com/compose/env-file/) 
compatible with kubernetes by; generating a _create configmap_ command 
with kubernetes compatible keys, and generating a _environment snippet_ 
to paste into deployment yaml that links environment variables back to 
configmap. 

Reason for this:

1. Using create configmap with --from-file option nests data which can't be mapped to env deployment file
1. [Environment Variable names](https://google.github.io/styleguide/shell.xml?showone=Constants_and_Environment_Variable_Names#Constants_and_Environment_Variable_Names) are not allowed as root configmap keys

## Usage

Execute the following to generate both configmap command and environment snippet:

`k8s-env-gen.sh configmap-name my.env`

This will convert environment keys into kubernetes compatible format, 
generate create configmap command, and map keys back to original 
environment name in snippet.

### Example

```sh
$ k8s-env-gen.sh my-config my.env
```

```sh
kubectl create configmap my-config --from-literal=db-driver=com.mysql.jdbc.Driver --from-literal=db-pool-maxsize=15 --from-literal=db-pool-minsize=10
```

```yaml
        env:
          - name: DB_DRIVER
            valueFrom:
              configMapKeyRef:
                name: my-config
                key: db-driver
          - name: DB_POOL_MAXSIZE<commit_msg>Tweak readme<commit_after># Kubernetes environment generator

Makes [docker env files](https://docs.docker.com/compose/env-file/) 
compatible with kubernetes by: 

1. generating a _create configmap_ command with kubernetes compatible keys
1. generating a _environment snippet_ to paste into deployment yaml that links environment variables back to configmap 

Reason for this:

* [Environment Variable names](https://google.github.io/styleguide/shell.xml?showone=Constants_and_Environment_Variable_Names#Constants_and_Environment_Variable_Names) are not allowed as root configmap keys
* Using create configmap with --from-file option nests data which can't be mapped to env deployment file

## Usage

Execute the following to generate both configmap command and environment snippet:

`./k8s-env-gen.sh configmap-name my.env`

This will convert environment keys into kubernetes compatible format, 
generate create configmap command, and map keys back to original 
environment name in snippet.

### Example

```sh
$ cat my.env 
DB_DRIVER=com.mysql.jdbc.Driver
DB_POOL_MAXSIZE=15
DB_POOL_MINSIZE=10
```

```sh
$ ./k8s-env-gen.sh my-config my.env
```

```sh
kubectl create configmap my-config --from-literal=db-driver=com.mysql.jdbc.Driver --from-literal=db-pool-maxsize=15 --from-literal=db-pool-minsize=10
```

```yaml
        env:
          - name: DB_DRIVER
            valueFrom:
              configMapKeyRef:
                name: my-config
                key: db-driver
          - name: DB_POOL_MAXSIZE
{'fraction_non_alphanumeric': 0.0842177336528586, 'fraction_numerical': 0.006846970215679562, 'mean_word_length': 3.7823240589198037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4274818', 'n_tokens_mistral': 870, 'n_tokens_neox': 819, 'n_words': 269}