The production system silently used an incorrect AWS region (eu-west-1 instead of the configured eu-north-1) due to hardcoded fallbacks in Python code. Additionally, the absence of the DOMAIN environment variable export caused empty string injection in Kubernetes ConfigMaps, leading to silent failures in email services and inconsistent configurations.
Issue
- Incorrect AWS region usage: The system silently used a fallback AWS region (
eu-west-1) instead of the configured region (eu-north-1), causing email failures with no error messages. - Missing domain values: The
DOMAINenvironment variable was not exported, resulting in empty strings in Kubernetes ConfigMaps and broken configurations. - Inconsistent logging: Startup logs lacked critical configuration values, complicating debugging.
Culprit
- Hardcoded Fallbacks in Python: The code used unsafe hardcoded defaults in
os.getenv()calls, which silently overrode configured values.- Example:
AWS_REGION = os.getenv('AWS_REGION', 'eu-west-1')contradicted the expected.envconfiguration.
- Example:
- Missing Environment Exports: The
common.shscript failed to export critical variables likeDOMAIN, leading to unresolved placeholders in ConfigMaps. - Static ConfigMap Values: Kubernetes manifests hardcoded values instead of using environment variable substitution.
- Incomplete Logging: Startup logs omitted critical configuration values, hindering debugging efforts.
Solution
Fail-Fast Validation Pattern
- Strict validation: Implemented fail-fast checks to ensure required environment variables were present and valid.
- Clear error messages: Added explicit error handling to provide immediate feedback if critical variables were missing.
Complete Environment Export
- Updated
common.sh: Added exports for all required variables, includingDOMAIN, to ensure consistency across environments.
Template Substitution in ConfigMaps
- Dynamic configuration: Modified ConfigMaps to use environment variable substitution, ensuring values were resolved at deployment time.
Comprehensive Logging
- Enhanced startup logs: Added detailed logging of all critical configuration values to improve debugging and visibility.
Validation Script
- Pre-deployment checks: Introduced a validation script (
test-config.sh) to verify configuration consistency before deployment, ensuring all required variables were set and correctly applied.
Architecture Flow:
.envfile →common.sh(export) → Kubernetes manifests (template substitution) → Kubernetes cluster → Python application (validation and logging).
Key Outcomes
- Eliminated silent failures: Fail-fast validation ensures configuration errors are detected immediately during startup.
- Improved debugging: Comprehensive logging provides clear visibility into configuration values and potential issues.
- Consistent configurations: Template substitution and complete environment exports ensure uniform configurations across environments.
- Reduced debugging time: Clear error messages and detailed logging simplify troubleshooting processes.