diff --git a/CHANGELOG.md b/CHANGELOG.md index 61e8da4..1cd9f78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog - [Changelog](#changelog) + - [v0.9.1](#v091) - [v0.9.0](#v090) - [v0.8.0](#v080) - [v0.7.0](#v070) @@ -13,6 +14,15 @@ --- +## [v0.9.1](https://github.com/DaemonDude23/helmizer/releases/tag/v0.9.1) + +November 11 2021 + +**Bugfixes** + +- Fixed `kustomization.yaml` not being written to disk... wtf? +- Fixed config property `sort-keys` being unenforced. + ## [v0.9.0](https://github.com/DaemonDude23/helmizer/releases/tag/v0.9.0) November 7 2021 diff --git a/README.md b/README.md index 52e596a..6220414 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ The `sealed-secrets` **Helm** chart is used for examples for its small scope. For local installation/use of the raw script, I use a local virtual environment to isolate dependencies: ```bash -git clone https://github.com/DaemonDude23/helmizer.git -b v0.9.0 +git clone https://github.com/DaemonDude23/helmizer.git -b v0.9.1 cd helmizer ``` @@ -189,7 +189,7 @@ In this example (*Nix OS), we're redirecting program output to the (e.g. `kustom docker run --name helmizer \ --rm \ -v "$PWD"/examples:/tmp/helmizer -w /tmp/helmizer \ - docker.pkg.github.com/DaemonDude23/helmizer/helmizer:v0.9.0 /usr/src/app/helmizer.py \ + docker.pkg.github.com/DaemonDude23/helmizer/helmizer:v0.9.1 /usr/src/app/helmizer.py \ ./resources/ > ./examples/resources/kustomization.yaml ``` diff --git a/examples/generatorOptions/kustomization.yaml b/examples/generatorOptions/kustomization.yaml index e910664..4548f70 100644 --- a/examples/generatorOptions/kustomization.yaml +++ b/examples/generatorOptions/kustomization.yaml @@ -5,4 +5,3 @@ generatorOptions: labels: kustomize.generated.resources: bla-bla kind: Kustomization -namespace: default diff --git a/src/helmizer.py b/src/helmizer.py index 68b3750..4b42ec2 100755 --- a/src/helmizer.py +++ b/src/helmizer.py @@ -68,12 +68,14 @@ def __init__(self, helmizer_config, arguments): pass def sort_keys(self): - try: - self.helmizer_config["helmizer"]["sort-keys"].get(bool) - for array in ["crds", "components", "patchesStrategicMerge", "resources"]: - self.yaml[array].sort() - except KeyError: - pass + self.helmizer_config["helmizer"]["sort-keys"].get(bool) + for key in ["crds", "components", "patchesStrategicMerge", "resources"]: + try: + self.yaml[key].sort() + except KeyError: + pass + logging.debug("keys sorted") + def print_kustomization(self): try: @@ -83,29 +85,35 @@ def print_kustomization(self): def write_kustomization(self, arguments): try: - if self.helmizer_config["helmizer"]["dry-run"].get(bool) or arguments.dry_run: + if arguments.dry_run: + logging.debug("Performing dry-run, not writing to a file system") + return 0 + elif self.helmizer_config["helmizer"]["dry-run"].get(bool): logging.debug("Performing dry-run, not writing to a file system") + return 0 except NotFoundError: - # identify kustomization file's parent directory - str_kustomization_directory = path.dirname(path.abspath(path.normpath(arguments.helmizer_config))) + pass - # identify kustomization file name - str_kustomization_file_name = str() - try: - str_kustomization_file_name = self.helmizer_config["helmizer"]["kustomization-file-name"].get(str) - except NotFoundError: - str_kustomization_file_name = "kustomization.yaml" + # identify kustomization file's parent directory + str_kustomization_directory = path.dirname(path.abspath(path.normpath(arguments.helmizer_config))) - # write to file - try: - kustomization_file_path = path.normpath(f"{str_kustomization_directory}/{str_kustomization_file_name}") - with open(kustomization_file_path, "w") as file: - file.write(yaml.dump(self.yaml)) - logging.debug(f"Successfully wrote to file: {path.abspath(kustomization_file_path)}") - except IsADirectoryError as e: - raise e - except TypeError: - pass + # identify kustomization file name + str_kustomization_file_name = str() + try: + str_kustomization_file_name = self.helmizer_config["helmizer"]["kustomization-file-name"].get(str) + except NotFoundError: + str_kustomization_file_name = "kustomization.yaml" + + # write to file + try: + kustomization_file_path = path.normpath(f"{str_kustomization_directory}/{str_kustomization_file_name}") + with open(kustomization_file_path, "w") as file: + file.write(yaml.dump(self.yaml)) + logging.debug(f"Successfully wrote to file: {path.abspath(kustomization_file_path)}") + except IsADirectoryError as e: + raise e + except TypeError: + pass def render_template(self, arguments): logging.debug("Rendering template") @@ -318,7 +326,7 @@ def init_arg_parser(): help="quiet output from subprocesses", default=False, ) - args.add_argument("--version", "-v", action="version", version="v0.9.0") + args.add_argument("--version", "-v", action="version", version="v0.9.1") args.add_argument( "helmizer_config", action="store",