This is a simple tool to compare Kubernetes YAML manifests and identify differences in the resources.
I have chosen to keep everything in a single file for simplicity's sake. Given the relatively small scope of the project, this approach helps maintain readability and keeps things easy to follow. Splitting the code into multiple files would add unnecessary complexity without a significant benefit at this stage. The main focus is clarity and ease of understanding rather than over-engineering the structure.
- Compares Kubernetes manifests in YAML format.
- Outputs differences in
added
,removed
, andchanged
sections. - Supports running tests using
pytest
. - Includes linting, formatting, and code organization with
black
,ruff
, andisort
. - Docker support for running the tool inside a container.
You can install the necessary dependencies using Poetry:
poetry install
To activate the Poetry shell (virtual environment):
poetry shell
# or
make shell
# or
make venv
Variable | Description | Default Value | Possible Values | Type |
---|---|---|---|---|
LOG_FORMAT |
Specifies the format of log output | text |
text , json |
String |
LOG_LEVEL |
Sets the logging level for the application | INFO |
DEBUG , INFO , WARNING , ERROR |
String |
To run the tool and compare two YAML files:
poetry run python diff_k8s_manifests.py <file_current.yaml> <file_desired.yaml>
You can also run the tool using Docker.
-
Build the Docker image:
make docker_build # or docker build -t diff_k8s_manifests .
-
Run the Docker container:
make docker_run # or docker run --rm diff_k8s_manifests
-
Clean up the Docker image:
make docker_clean # or docker rmi diff_k8s_manifests
You can run tests using pytest
:
make test
# or
poetry run pytest -vvvs
# or
poetry run pytest -vvvs tests/
We use black
, ruff
, and isort
to ensure code quality.
-
To format the code with
black
:make format # or poetry run black .
-
To organize imports with
isort
:make organize # or poetry run isort .
-
To lint the code with
ruff
:make lint # or poetry run ruff check .
-
To run all checks (formatting, organizing, and linting):
make all_checks
To clean up compiled Python files and other temporary files:
make clean
# or
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
rm -rf .pytest_cache
rm -rf .ruff_cache
-
Add CI/CD: Implement a continuous integration and continuous delivery pipeline to automatically test and deploy the project.
-
Add Kubernetes Object Validation: Introduce validation to ensure that the
kind
andapiVersion
fields are handled correctly and that the system can recognize and validate Kubernetes objects based on their type. -
Enhance Test Coverage: Improve the test suite by adding more scenarios to ensure all possible edge cases are covered.
-
Improve Logging and Error Handling: Refine the logging system and add more granular error handling to better trace issues during execution.
-
Documentation Expansion: Provide more detailed documentation around the usage, edge cases, and common pitfalls of the project.