Skip to content

Commit 34fad17

Browse files
committed
v0.8.0
1 parent 093869a commit 34fad17

File tree

6 files changed

+125
-45
lines changed

6 files changed

+125
-45
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
],
1010
"python.testing.pytestEnabled": false,
1111
"python.testing.nosetestsEnabled": false,
12-
"python.testing.unittestEnabled": true
12+
"python.testing.unittestEnabled": false,
13+
"python.testing.promptToConfigure": false
1314
}

CHANGELOG.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

33
- [Changelog](#changelog)
4+
- [v0.8.0](#v080)
45
- [v0.7.0](#v070)
5-
- [v0.7.0](#v070-1)
6+
- [v0.6.0](#v060)
67
- [v0.5.2](#v052)
78
- [v0.5.1](#v051)
89
- [v0.5.0](#v050)
@@ -11,12 +12,31 @@
1112

1213
---
1314

15+
## [v0.8.0](https://github.com/chicken231/helmizer/releases/tag/v0.8.0)
16+
17+
June 10 2021
18+
19+
**Enhancements:**
20+
21+
- Added configuration support for:
22+
- [`components`](https://kubectl.docs.kubernetes.io/guides/config_management/components/)
23+
- [`crds`](https://kubectl.docs.kubernetes.io/references/kustomize/crds/)
24+
- [`namePrefix`](https://kubectl.docs.kubernetes.io/references/kustomize/nameprefix/)
25+
- [`nameSuffix`](https://kubectl.docs.kubernetes.io/references/kustomize/namesuffix/)
26+
- Added argument `--skip-commands` to not run the `commandSequence` and just generate the `kustomization.yaml`.
27+
- Added more debug statements.
28+
29+
**Bugfixes:**
30+
31+
- Made argument `--dry-run` do what it says it'll do.
32+
- Fixed `latest` tag with build script.
33+
1434
## [v0.7.0](https://github.com/chicken231/helmizer/releases/tag/v0.7.0)
1535

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

19-
## [v0.7.0](https://github.com/chicken231/helmizer/releases/tag/v0.7.0)
39+
## [v0.6.0](https://github.com/chicken231/helmizer/releases/tag/v0.6.0)
2040

2141
- Reduce arguments to 1 positional argument pointing to helmizer config file.
2242
- Fix issues with arguments referencing paths.

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ helmizer:
7878
ignore:
7979
- sealed-secrets/templates/helmizer.yaml
8080
kustomize:
81+
commonAnnotations: {}
82+
commonLabels: {}
83+
components: []
84+
crds: []
85+
namePrefix: []
86+
nameSuffix: []
8187
namespace: sealed-secrets
82-
resources:
83-
- sealed-secrets/templates/
8488
patchesStrategicMerge:
8589
- extra/
86-
commonAnnotations: {}
87-
commonLabels: {}
90+
resources:
91+
- sealed-secrets/templates/
8892
```
8993
9094
### Examples
@@ -102,7 +106,7 @@ The `sealed-secrets` **Helm** chart is used for examples for its small scope.
102106
For local installation/use of the raw script, I use a local virtual environment to isolate dependencies:
103107

104108
```bash
105-
git clone https://github.com/chicken231/helmizer.git -b v0.7.0
109+
git clone https://github.com/chicken231/helmizer.git -b v0.8.0
106110
cd helmizer
107111
```
108112

@@ -184,7 +188,7 @@ In this example (*Nix OS), we're redirecting program output to the (e.g. `kustom
184188
docker run --name helmizer \
185189
--rm \
186190
-v "$PWD"/examples:/tmp/helmizer -w /tmp/helmizer \
187-
docker.pkg.github.com/chicken231/helmizer/helmizer:v0.7.0 /usr/src/app/helmizer.py \
191+
docker.pkg.github.com/chicken231/helmizer/helmizer:v0.8.0 /usr/src/app/helmizer.py \
188192
./resources/ > ./examples/resources/kustomization.yaml
189193
```
190194

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

195199
- [commonAnnotations](https://kubectl.docs.kubernetes.io/references/kustomize/commonannotations/)
196200
- [commonLabels](https://kubectl.docs.kubernetes.io/references/kustomize/commonlabels/)
201+
- [components](https://kubectl.docs.kubernetes.io/guides/config_management/components/)
202+
- [crds](https://kubectl.docs.kubernetes.io/references/kustomize/crds/)
203+
- [namePrefix](https://kubectl.docs.kubernetes.io/references/kustomize/nameprefix/)
197204
- [namespace](https://kubectl.docs.kubernetes.io/references/kustomize/namespace/)
205+
- [nameSuffix](https://kubectl.docs.kubernetes.io/references/kustomize/namesuffix/)
198206
- [patchStrategicMerge](https://kubectl.docs.kubernetes.io/references/kustomize/patchesstrategicmerge/)
199207
- [resources](https://kubectl.docs.kubernetes.io/references/kustomize/resource/)
200208

201209
### Unsupported (Currently)
202210

203211
- [~~bases~~](https://kubectl.docs.kubernetes.io/references/kustomize/bases/)
204-
- [components](https://kubectl.docs.kubernetes.io/references/kustomize/components/)
205212
- [configMapGenerator](https://kubectl.docs.kubernetes.io/references/kustomize/configmapgenerator/)
206-
- [crds](https://kubectl.docs.kubernetes.io/references/kustomize/crds/)
207213
- [generatorOptions](https://kubectl.docs.kubernetes.io/references/kustomize/generatoroptions/)
208214
- [images](https://kubectl.docs.kubernetes.io/references/kustomize/images/)
209-
- [namePrefix](https://kubectl.docs.kubernetes.io/references/kustomize/nameprefix/)
210-
- [nameSuffix](https://kubectl.docs.kubernetes.io/references/kustomize/namesuffix/)
211215
- [patches](https://kubectl.docs.kubernetes.io/references/kustomize/patches/)
212216
- [patchesJson6902](https://kubectl.docs.kubernetes.io/references/kustomize/patchesjson6902/)
213217
- [replicas](https://kubectl.docs.kubernetes.io/references/kustomize/replicas/)

build.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
set -e
3+
34
TAG="${1}"
5+
REGISTRY_URL="docker.pkg.github.com/chicken231/helmizer/helmizer"
6+
47

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

1417
docker build \
15-
-t docker.pkg.github.com/chicken231/helmizer/helmizer:${TAG} \
16-
-t docker.pkg.github.com/chicken231/helmizer/helmizer:latest . \
18+
-t ${REGISTRY_URL}:${TAG} \
19+
-t ${REGISTRY_URL}:latest . \
1720
--label "org.opencontainers.image.created=$DOCKER_CREATE_DATE" \
1821
--label "org.label-schema.build-date=$DOCKER_CREATE_DATE" \
1922

2023
echo "Push to container registry?"
2124
select yn in "Yes" "No"; do
2225
case $yn in
23-
Yes ) docker push docker.pkg.github.com/chicken231/helmizer/helmizer:${TAG}; exit;;
26+
Yes ) docker push ${REGISTRY_URL}:${TAG}; docker push ${REGISTRY_URL}:latest; exit;;
2427
No ) echo "No further action being taken"; exit;;
2528
esac
2629
done

docs/developers.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [~~Linux~~](#linux)
66
- [~~Flatpak~~](#flatpak)
77
- [Prep release](#prep-release)
8+
- [Update version nunmber](#update-version-nunmber)
89

910
## ~~PyInstaller~~
1011

@@ -54,6 +55,8 @@ flatpak run org.chicken231.Helmizer
5455

5556
## Prep release
5657

58+
### Update version nunmber
59+
5760
```bash
5861
find . -type f -exec sed -i 's!v0.0.0!v0.0.1!g' '{}' \;
5962
```

src/helmizer.py

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ def __init__(self, helmizer_config, arguments):
4444
if dict_get_common_labels:
4545
self.yaml['commonLabels'] = dict_get_common_labels
4646

47+
# crds
48+
list_crds = self.get_files(arguments, 'crds')
49+
if list_crds:
50+
self.yaml['crds'] = list_crds
51+
52+
# components
53+
list_components = self.get_files(arguments, 'components')
54+
if list_components:
55+
self.yaml['components'] = list_components
56+
57+
# namePrefix
58+
str_name_prefix = self.get_name_prefix()
59+
if str_name_prefix:
60+
self.yaml['namePrefix'] = str_name_prefix
61+
62+
# nameSuffix
63+
str_name_suffix = self.get_name_suffix()
64+
if str_name_suffix:
65+
self.yaml['nameSuffix'] = str_name_suffix
66+
4767
# patchesStrategicMerge
4868
list_patches_strategic_merge = self.get_files(arguments, 'patchesStrategicMerge')
4969
if list_patches_strategic_merge:
@@ -72,29 +92,33 @@ def print_kustomization(self):
7292

7393

7494
def write_kustomization(self, arguments):
75-
# identify kustomization file's parent directory
76-
str_kustomization_directory = path.dirname(path.abspath(path.normpath(arguments.helmizer_config)))
77-
78-
# identify kustomization file name
79-
str_kustomization_file_name = str()
80-
try:
81-
str_kustomization_file_name = self.helmizer_config['helmizer']['kustomization-file-name'].get(str)
82-
except KeyError:
83-
str_kustomization_file_name = 'kustomization.yaml'
84-
85-
# write to file
86-
try:
87-
kustomization_file_path = path.normpath(f'{str_kustomization_directory}/{str_kustomization_file_name}')
88-
with open(kustomization_file_path, 'w') as file:
89-
file.write(yaml.dump(self.yaml))
90-
logging.debug(f'Successfully wrote to file: {path.abspath(kustomization_file_path)}')
91-
except IsADirectoryError as e:
92-
raise e
93-
except TypeError:
94-
pass
95+
if self.helmizer_config['helmizer']['dry-run'].get(bool) or arguments.dry_run:
96+
logging.debug('Performing dry-run, not writing to a file system')
97+
else:
98+
# identify kustomization file's parent directory
99+
str_kustomization_directory = path.dirname(path.abspath(path.normpath(arguments.helmizer_config)))
100+
101+
# identify kustomization file name
102+
str_kustomization_file_name = str()
103+
try:
104+
str_kustomization_file_name = self.helmizer_config['helmizer']['kustomization-file-name'].get(str)
105+
except KeyError:
106+
str_kustomization_file_name = 'kustomization.yaml'
107+
108+
# write to file
109+
try:
110+
kustomization_file_path = path.normpath(f'{str_kustomization_directory}/{str_kustomization_file_name}')
111+
with open(kustomization_file_path, 'w') as file:
112+
file.write(yaml.dump(self.yaml))
113+
logging.debug(f'Successfully wrote to file: {path.abspath(kustomization_file_path)}')
114+
except IsADirectoryError as e:
115+
raise e
116+
except TypeError:
117+
pass
95118

96119

97120
def render_template(self, arguments):
121+
logging.debug('Rendering template')
98122
self.sort_keys()
99123
self.print_kustomization()
100124
self.write_kustomization(arguments)
@@ -147,6 +171,30 @@ def get_common_labels(self):
147171
return dict_common_labels
148172

149173

174+
def get_name_prefix(self):
175+
str_name_prefix = str()
176+
try:
177+
if len(self.helmizer_config['kustomize']['namePrefix'].get(str)) > 0:
178+
str_name_prefix = self.helmizer_config['kustomize']['namePrefix'].get(str)
179+
logging.debug(f'namespace: {str_name_prefix}')
180+
except TypeError:
181+
pass
182+
finally:
183+
return str_name_prefix
184+
185+
186+
def get_name_suffix(self):
187+
str_name_suffix = str()
188+
try:
189+
if len(self.helmizer_config['kustomize']['nameSuffix'].get(str)) > 0:
190+
str_name_suffix = self.helmizer_config['kustomize']['nameSuffix'].get(str)
191+
logging.debug(f'namespace: {str_name_suffix}')
192+
except TypeError:
193+
pass
194+
finally:
195+
return str_name_suffix
196+
197+
150198
def get_files(self, arguments, key):
151199
list_target_paths = list()
152200
list_final_target_paths = list()
@@ -183,6 +231,7 @@ def get_files(self, arguments, key):
183231
# remove any ignored files
184232
try:
185233
for ignore in self.helmizer_config['helmizer']['ignore'].get(list):
234+
logging.debug(f'Removing ignored file from final list: {ignore}')
186235
list_final_target_paths.remove(ignore)
187236
except ValueError:
188237
pass
@@ -238,21 +287,20 @@ def init_arg_parser():
238287
args = parser.add_argument_group()
239288
args.add_argument('--debug', dest='debug', action='store_true', help='enable debug logging', default=False)
240289
args.add_argument('--dry-run', dest='dry_run', action='store_true', help='do not write to a file system', default=False)
290+
args.add_argument('--skip-commands', dest='skip_commands', action='store_true',
291+
help='skip executing commandSequence, just generate kustomization file', default=False)
241292
args.add_argument('--quiet', '-q', dest='quiet', action='store_true', help='quiet output from subprocesses',
242-
default=False)
243-
args.add_argument('--version', action='version', version='v0.7.0')
293+
default=False)
294+
args.add_argument('--version', action='version', version='v0.8.0')
244295
args.add_argument('helmizer_config', action='store', type=str, help='path to helmizer config file')
245296
arguments = parser.parse_args()
246297

247298
if arguments.quiet:
248-
logging.basicConfig(level=logging.INFO, datefmt=None, stream=None,
249-
format='[%(asctime)s %(levelname)s] %(message)s')
299+
logging.basicConfig(level=logging.INFO, datefmt=None, stream=None, format='[%(asctime)s %(levelname)s] %(message)s')
250300
if arguments.debug:
251-
logging.basicConfig(level=logging.DEBUG, datefmt=None, stream=stdout,
252-
format='[%(asctime)s %(levelname)s] %(message)s')
301+
logging.basicConfig(level=logging.DEBUG, datefmt=None, stream=stdout, format='[%(asctime)s %(levelname)s] %(message)s')
253302
else:
254-
logging.basicConfig(level=logging.INFO, datefmt=None, stream=stdout,
255-
format='[%(asctime)s %(levelname)s] %(message)s')
303+
logging.basicConfig(level=logging.INFO, datefmt=None, stream=stdout, format='[%(asctime)s %(levelname)s] %(message)s')
256304

257305
return arguments
258306
except argparse.ArgumentError as e:
@@ -291,7 +339,8 @@ def init_helmizer_config(arguments):
291339
def main():
292340
arguments = init_arg_parser()
293341
helmizer_config = init_helmizer_config(arguments)
294-
run_subprocess(helmizer_config, arguments)
342+
if not arguments.skip_commands:
343+
run_subprocess(helmizer_config, arguments)
295344
kustomization = Kustomization(helmizer_config, arguments)
296345
kustomization.render_template(arguments)
297346

0 commit comments

Comments
 (0)