This script is designed to parametrize Helm chart values by reading configuration and secrets files from a specified directory. It encodes the content of these files if necessary and outputs them in a key-value format, suitable for use with Helm charts.
- Bash environment
- Perl installed (for inline editing of strings)
The script expects two primary arguments: an environment identifier and a configuration file path.
./helm_parametrize.sh [environment] -f [config_path][environment]: Environment identifier (e.g., "dev", "prod").-f [config_path]: Path to the configuration files. This is a required argument.
./helm_parametrize.sh dev -f /path/to/configHere's a detailed breakdown of the script:
-
Error Handling and Usage Message:
- Exits immediately if any command has a non-zero status.
- Prints a usage message and exits when invalid arguments are input or help is requested.
-
Parsing Arguments:
- Parses command-line options, ensuring the environment identifier and configuration file path are provided.
-
Validating Inputs:
- Checks if the environment identifier and configuration path are given and valid.
-
Processing Files:
- Processes files within the given directory, differentiating between configurations and secrets.
- Encodes secret files in base64. Replaces newlines with
\nin config files. - Outputs each file's content in the format
type.key=content.
-
Executing for Configs and Secrets:
- Iterates over two types: "configs" and "secrets", processing files accordingly.