Skip to content

Commit

Permalink
Merge pull request #13 from openinfradev/crd
Browse files Browse the repository at this point in the history
Crd 관련 이슈추가
  • Loading branch information
intelliguy authored Nov 24, 2023
2 parents 90e160f + a831052 commit dbf6f03
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions helm2yaml/applib/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -119,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:
Expand All @@ -135,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):
Expand Down

0 comments on commit dbf6f03

Please sign in to comment.