From 88fcaedb61d448a81d43d32fb1485404dc789845 Mon Sep 17 00:00:00 2001 From: Jugwan Eom Date: Tue, 7 Nov 2023 06:34:18 +0000 Subject: [PATCH 1/2] fix crds generation --- helm2yaml/applib/helm.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/helm2yaml/applib/helm.py b/helm2yaml/applib/helm.py index ccae74a..d218840 100755 --- a/helm2yaml/applib/helm.py +++ b/helm2yaml/applib/helm.py @@ -107,6 +107,14 @@ def toSeperatedResources(self, targetdir='/output', verbose=False, local_reposit os.system(splitcmd) os.system('rm {0}{1}'.format(target,genfile)) + isCrd=self.name.endswith('-crds') + if isCrd: + for entry in os.scandir(target): + if entry.is_file(): + splitcmd = "awk '{f=\""+target+"/"+entry.name+"-\" NR; print $0 > f}' RS='' "+target+"/"+entry.name + os.system(splitcmd) + os.system('rm {0}{1}'.format(target,entry.name)) + # Rename yaml to "KIND_RESOURCENAME.yaml" if verbose > 0: print('(DEBUG) rename resource yaml files') From a8310527e5e09e3d0c5ac0af315cfc79b1d12364 Mon Sep 17 00:00:00 2001 From: sungil Date: Thu, 23 Nov 2023 15:17:54 +0000 Subject: [PATCH 2/2] bugfix: do not drop crd during redering --- helm2yaml/applib/helm.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/helm2yaml/applib/helm.py b/helm2yaml/applib/helm.py index d218840..93f743d 100755 --- a/helm2yaml/applib/helm.py +++ b/helm2yaml/applib/helm.py @@ -127,7 +127,18 @@ def toSeperatedResources(self, targetdir='/output', verbose=False, local_reposit if(local_repository!=None): self.__replaceImages(parsed, local_repository) - + except yaml.constructor.ConstructorError as exc: + # Very very tricky logic to avoid a exception on some crds (alertmanagerconfigs.monitoring.coreos.com) + lines = open(entry, 'r').readlines() + rkind=rname='' + for line in lines: + if 'kind: ' in line: + rkind=line.split('kind: ')[-1].strip() + if 'name: ' in line: + rname=line.split('name: ')[-1].strip() + os.rename(entry, target+'/'+ '{}_{}.yaml'.format(rkind, rname)) + break + continue except yaml.YAMLError as exc: print('(WARN)',exc,":::", parsed) except TypeError as exc: @@ -143,7 +154,7 @@ def toSeperatedResources(self, targetdir='/output', verbose=False, local_reposit os.remove(entry) else: os.rename(entry, target+'/'+refinedname) - else: + elif os.path.exists(entry): os.remove(entry) def get_image_list(self, verbose=False):