Skip to content

Commit

Permalink
v0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DaemonDude23 committed Jun 11, 2021
1 parent 093869a commit 34fad17
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
"python.testing.unittestEnabled": false,
"python.testing.promptToConfigure": false
}
24 changes: 22 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

- [Changelog](#changelog)
- [v0.8.0](#v080)
- [v0.7.0](#v070)
- [v0.7.0](#v070-1)
- [v0.6.0](#v060)
- [v0.5.2](#v052)
- [v0.5.1](#v051)
- [v0.5.0](#v050)
Expand All @@ -11,12 +12,31 @@

---

## [v0.8.0](https://github.com/chicken231/helmizer/releases/tag/v0.8.0)

June 10 2021

**Enhancements:**

- Added configuration support for:
- [`components`](https://kubectl.docs.kubernetes.io/guides/config_management/components/)
- [`crds`](https://kubectl.docs.kubernetes.io/references/kustomize/crds/)
- [`namePrefix`](https://kubectl.docs.kubernetes.io/references/kustomize/nameprefix/)
- [`nameSuffix`](https://kubectl.docs.kubernetes.io/references/kustomize/namesuffix/)
- Added argument `--skip-commands` to not run the `commandSequence` and just generate the `kustomization.yaml`.
- Added more debug statements.

**Bugfixes:**

- Made argument `--dry-run` do what it says it'll do.
- Fixed `latest` tag with build script.

## [v0.7.0](https://github.com/chicken231/helmizer/releases/tag/v0.7.0)

- Catch when no `helmizer` config detected, giving a user-friendly message.
- Added `helmizer.ignore` section to helmizer config. Define path(s) to files to not ignore when constructing the final kustomization.

## [v0.7.0](https://github.com/chicken231/helmizer/releases/tag/v0.7.0)
## [v0.6.0](https://github.com/chicken231/helmizer/releases/tag/v0.6.0)

- Reduce arguments to 1 positional argument pointing to helmizer config file.
- Fix issues with arguments referencing paths.
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ helmizer:
ignore:
- sealed-secrets/templates/helmizer.yaml
kustomize:
commonAnnotations: {}
commonLabels: {}
components: []
crds: []
namePrefix: []
nameSuffix: []
namespace: sealed-secrets
resources:
- sealed-secrets/templates/
patchesStrategicMerge:
- extra/
commonAnnotations: {}
commonLabels: {}
resources:
- sealed-secrets/templates/
```
### Examples
Expand All @@ -102,7 +106,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/chicken231/helmizer.git -b v0.7.0
git clone https://github.com/chicken231/helmizer.git -b v0.8.0
cd helmizer
```

Expand Down Expand Up @@ -184,7 +188,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/chicken231/helmizer/helmizer:v0.7.0 /usr/src/app/helmizer.py \
docker.pkg.github.com/chicken231/helmizer/helmizer:v0.8.0 /usr/src/app/helmizer.py \
./resources/ > ./examples/resources/kustomization.yaml
```

Expand All @@ -194,20 +198,20 @@ docker run --name helmizer \

- [commonAnnotations](https://kubectl.docs.kubernetes.io/references/kustomize/commonannotations/)
- [commonLabels](https://kubectl.docs.kubernetes.io/references/kustomize/commonlabels/)
- [components](https://kubectl.docs.kubernetes.io/guides/config_management/components/)
- [crds](https://kubectl.docs.kubernetes.io/references/kustomize/crds/)
- [namePrefix](https://kubectl.docs.kubernetes.io/references/kustomize/nameprefix/)
- [namespace](https://kubectl.docs.kubernetes.io/references/kustomize/namespace/)
- [nameSuffix](https://kubectl.docs.kubernetes.io/references/kustomize/namesuffix/)
- [patchStrategicMerge](https://kubectl.docs.kubernetes.io/references/kustomize/patchesstrategicmerge/)
- [resources](https://kubectl.docs.kubernetes.io/references/kustomize/resource/)

### Unsupported (Currently)

- [~~bases~~](https://kubectl.docs.kubernetes.io/references/kustomize/bases/)
- [components](https://kubectl.docs.kubernetes.io/references/kustomize/components/)
- [configMapGenerator](https://kubectl.docs.kubernetes.io/references/kustomize/configmapgenerator/)
- [crds](https://kubectl.docs.kubernetes.io/references/kustomize/crds/)
- [generatorOptions](https://kubectl.docs.kubernetes.io/references/kustomize/generatoroptions/)
- [images](https://kubectl.docs.kubernetes.io/references/kustomize/images/)
- [namePrefix](https://kubectl.docs.kubernetes.io/references/kustomize/nameprefix/)
- [nameSuffix](https://kubectl.docs.kubernetes.io/references/kustomize/namesuffix/)
- [patches](https://kubectl.docs.kubernetes.io/references/kustomize/patches/)
- [patchesJson6902](https://kubectl.docs.kubernetes.io/references/kustomize/patchesjson6902/)
- [replicas](https://kubectl.docs.kubernetes.io/references/kustomize/replicas/)
Expand Down
9 changes: 6 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
set -e

TAG="${1}"
REGISTRY_URL="docker.pkg.github.com/chicken231/helmizer/helmizer"


if [ $# -eq 0 ]; then
echo "error: Tag required. Exiting"
Expand All @@ -12,15 +15,15 @@ DOCKER_CREATE_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
printf "\n * Docker container label (timestamp): %s" "$DOCKER_CREATE_DATE"

docker build \
-t docker.pkg.github.com/chicken231/helmizer/helmizer:${TAG} \
-t docker.pkg.github.com/chicken231/helmizer/helmizer:latest . \
-t ${REGISTRY_URL}:${TAG} \
-t ${REGISTRY_URL}:latest . \
--label "org.opencontainers.image.created=$DOCKER_CREATE_DATE" \
--label "org.label-schema.build-date=$DOCKER_CREATE_DATE" \

echo "Push to container registry?"
select yn in "Yes" "No"; do
case $yn in
Yes ) docker push docker.pkg.github.com/chicken231/helmizer/helmizer:${TAG}; exit;;
Yes ) docker push ${REGISTRY_URL}:${TAG}; docker push ${REGISTRY_URL}:latest; exit;;
No ) echo "No further action being taken"; exit;;
esac
done
3 changes: 3 additions & 0 deletions docs/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [~~Linux~~](#linux)
- [~~Flatpak~~](#flatpak)
- [Prep release](#prep-release)
- [Update version nunmber](#update-version-nunmber)

## ~~PyInstaller~~

Expand Down Expand Up @@ -54,6 +55,8 @@ flatpak run org.chicken231.Helmizer

## Prep release

### Update version nunmber

```bash
find . -type f -exec sed -i 's!v0.0.0!v0.0.1!g' '{}' \;
```
107 changes: 78 additions & 29 deletions src/helmizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ def __init__(self, helmizer_config, arguments):
if dict_get_common_labels:
self.yaml['commonLabels'] = dict_get_common_labels

# crds
list_crds = self.get_files(arguments, 'crds')
if list_crds:
self.yaml['crds'] = list_crds

# components
list_components = self.get_files(arguments, 'components')
if list_components:
self.yaml['components'] = list_components

# namePrefix
str_name_prefix = self.get_name_prefix()
if str_name_prefix:
self.yaml['namePrefix'] = str_name_prefix

# nameSuffix
str_name_suffix = self.get_name_suffix()
if str_name_suffix:
self.yaml['nameSuffix'] = str_name_suffix

# patchesStrategicMerge
list_patches_strategic_merge = self.get_files(arguments, 'patchesStrategicMerge')
if list_patches_strategic_merge:
Expand Down Expand Up @@ -72,29 +92,33 @@ def print_kustomization(self):


def write_kustomization(self, arguments):
# identify kustomization file's parent directory
str_kustomization_directory = path.dirname(path.abspath(path.normpath(arguments.helmizer_config)))

# identify kustomization file name
str_kustomization_file_name = str()
try:
str_kustomization_file_name = self.helmizer_config['helmizer']['kustomization-file-name'].get(str)
except KeyError:
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
if self.helmizer_config['helmizer']['dry-run'].get(bool) or arguments.dry_run:
logging.debug('Performing dry-run, not writing to a file system')
else:
# identify kustomization file's parent directory
str_kustomization_directory = path.dirname(path.abspath(path.normpath(arguments.helmizer_config)))

# identify kustomization file name
str_kustomization_file_name = str()
try:
str_kustomization_file_name = self.helmizer_config['helmizer']['kustomization-file-name'].get(str)
except KeyError:
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')
self.sort_keys()
self.print_kustomization()
self.write_kustomization(arguments)
Expand Down Expand Up @@ -147,6 +171,30 @@ def get_common_labels(self):
return dict_common_labels


def get_name_prefix(self):
str_name_prefix = str()
try:
if len(self.helmizer_config['kustomize']['namePrefix'].get(str)) > 0:
str_name_prefix = self.helmizer_config['kustomize']['namePrefix'].get(str)
logging.debug(f'namespace: {str_name_prefix}')
except TypeError:
pass
finally:
return str_name_prefix


def get_name_suffix(self):
str_name_suffix = str()
try:
if len(self.helmizer_config['kustomize']['nameSuffix'].get(str)) > 0:
str_name_suffix = self.helmizer_config['kustomize']['nameSuffix'].get(str)
logging.debug(f'namespace: {str_name_suffix}')
except TypeError:
pass
finally:
return str_name_suffix


def get_files(self, arguments, key):
list_target_paths = list()
list_final_target_paths = list()
Expand Down Expand Up @@ -183,6 +231,7 @@ def get_files(self, arguments, key):
# remove any ignored files
try:
for ignore in self.helmizer_config['helmizer']['ignore'].get(list):
logging.debug(f'Removing ignored file from final list: {ignore}')
list_final_target_paths.remove(ignore)
except ValueError:
pass
Expand Down Expand Up @@ -238,21 +287,20 @@ def init_arg_parser():
args = parser.add_argument_group()
args.add_argument('--debug', dest='debug', action='store_true', help='enable debug logging', default=False)
args.add_argument('--dry-run', dest='dry_run', action='store_true', help='do not write to a file system', default=False)
args.add_argument('--skip-commands', dest='skip_commands', action='store_true',
help='skip executing commandSequence, just generate kustomization file', default=False)
args.add_argument('--quiet', '-q', dest='quiet', action='store_true', help='quiet output from subprocesses',
default=False)
args.add_argument('--version', action='version', version='v0.7.0')
default=False)
args.add_argument('--version', action='version', version='v0.8.0')
args.add_argument('helmizer_config', action='store', type=str, help='path to helmizer config file')
arguments = parser.parse_args()

if arguments.quiet:
logging.basicConfig(level=logging.INFO, datefmt=None, stream=None,
format='[%(asctime)s %(levelname)s] %(message)s')
logging.basicConfig(level=logging.INFO, datefmt=None, stream=None, format='[%(asctime)s %(levelname)s] %(message)s')
if arguments.debug:
logging.basicConfig(level=logging.DEBUG, datefmt=None, stream=stdout,
format='[%(asctime)s %(levelname)s] %(message)s')
logging.basicConfig(level=logging.DEBUG, datefmt=None, stream=stdout, format='[%(asctime)s %(levelname)s] %(message)s')
else:
logging.basicConfig(level=logging.INFO, datefmt=None, stream=stdout,
format='[%(asctime)s %(levelname)s] %(message)s')
logging.basicConfig(level=logging.INFO, datefmt=None, stream=stdout, format='[%(asctime)s %(levelname)s] %(message)s')

return arguments
except argparse.ArgumentError as e:
Expand Down Expand Up @@ -291,7 +339,8 @@ def init_helmizer_config(arguments):
def main():
arguments = init_arg_parser()
helmizer_config = init_helmizer_config(arguments)
run_subprocess(helmizer_config, arguments)
if not arguments.skip_commands:
run_subprocess(helmizer_config, arguments)
kustomization = Kustomization(helmizer_config, arguments)
kustomization.render_template(arguments)

Expand Down

0 comments on commit 34fad17

Please sign in to comment.