Skip to content

Commit 3321fe9

Browse files
authored
Add support to parse Helm Template artifacts in CRD yaml (#11)
Signed-off-by: Joshua Packer <[email protected]>
1 parent 3cd1877 commit 3321fe9

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

cmd/gen-api-docs.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,27 @@ def parse_go_file(file_path, go_files, parsed_types=None):
120120

121121
def parse_crd_file(file_path):
122122
with open(file_path, 'r') as f:
123-
try:
124-
crd = yaml.safe_load(f)
125-
except yaml.YAMLError as e:
126-
print(f"Error parsing YAML file {file_path}: {e}")
127-
return None
123+
content = f.read()
124+
125+
# Filter out Helm template syntax before parsing YAML
126+
# Remove Helm template blocks like {{- if .Values.manageCRDs }}, {{ .Values.something }}, etc.
127+
import re
128+
# Remove Helm template conditionals and loops
129+
content = re.sub(r'\{\{-?\s*if\s+[^}]+\s*-?\}\}', '', content)
130+
content = re.sub(r'\{\{-?\s*else\s*-?\}\}', '', content)
131+
content = re.sub(r'\{\{-?\s*end\s*-?\}\}', '', content)
132+
content = re.sub(r'\{\{-?\s*range\s+[^}]+\s*-?\}\}', '', content)
133+
content = re.sub(r'\{\{-?\s*with\s+[^}]+\s*-?\}\}', '', content)
134+
# Remove Helm template variables like {{ .Values.something }}
135+
content = re.sub(r'\{\{-?[^}]+-?\}\}', '', content)
136+
# Remove lines that are only whitespace after template removal
137+
content = '\n'.join(line for line in content.split('\n') if line.strip())
138+
139+
try:
140+
crd = yaml.safe_load(content)
141+
except yaml.YAMLError as e:
142+
print(f"Error parsing YAML file {file_path}: {e}")
143+
return None
128144
if not crd or crd.get('kind') != 'CustomResourceDefinition':
129145
return None
130146

0 commit comments

Comments
 (0)