Skip to content

Commit b3193dc

Browse files
committed
add heplers.tpl to prompt
1 parent c7fc020 commit b3193dc

9 files changed

Lines changed: 81 additions & 109 deletions

File tree

119 Bytes
Binary file not shown.
Lines changed: 59 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,70 @@
11
import os
2-
import yaml
32

4-
# Define directory and file structure
5-
project_name = 'MyHelm'
6-
base_path = os.path.join('app', 'media', project_name)
3+
# Define project structure
4+
project_name = 'app/media/MyHelm'
5+
directories = ['charts/', 'templates/']
6+
templates_dir = 'templates/web'
7+
files = ['Chart.yaml', 'values.yaml']
8+
template_subdirectories = ['web']
9+
template_files = ['service.yaml', 'helpers.tpl']
710

8-
directories = [
9-
os.path.join(base_path, 'charts'),
10-
os.path.join(base_path, 'templates', 'web')
11-
]
11+
# Chart.yaml content
12+
chart_yaml_content = """apiVersion: v2
13+
name: my-helm-chart
14+
description: A Helm chart for Kubernetes
15+
version: 0.1.0
16+
"""
1217

13-
files = {
14-
'Chart.yaml': {
15-
'apiVersion': 'v2',
16-
'name': project_name,
17-
'description': 'A Helm chart for Kubernetes',
18-
'version': '0.1.0',
19-
'appVersion': '1.0.0'
20-
},
21-
'values.yaml': {
22-
'web': {
23-
'image': {
24-
'repository': 'nginx',
25-
'tag': 'latest'
26-
},
27-
'service': {
28-
'enabled': True,
29-
'port': 80
30-
},
31-
'replicaCount': 1,
32-
'persistence': {
33-
'enabled': True,
34-
'size': '1Gi',
35-
'accessModes': ['ReadWriteOnce']
36-
},
37-
'env': [{
38-
'name': 'ENV1',
39-
'value': 'Hi'
40-
}],
41-
'ingress': {
42-
'enabled': False,
43-
'host': 'www.example.com'
44-
}
45-
}
46-
}
47-
}
18+
# values.yaml content
19+
values_yaml_content = """web:
20+
image: nginx
21+
replicas: 1
22+
service:
23+
targetPort: 80
24+
persistence:
25+
enabled: true
26+
size: 1Gi
27+
accessModes:
28+
- ReadWriteOnce
29+
env:
30+
- name: ENV1
31+
value: Hi
32+
ingress:
33+
enabled: false
34+
host: www.example.com
35+
"""
4836

49-
# Create directories
37+
# Create project structure
38+
os.makedirs(project_name, exist_ok=True)
5039
for directory in directories:
51-
os.makedirs(directory, exist_ok=True)
40+
os.makedirs(os.path.join(project_name, directory), exist_ok=True)
5241

53-
# Create files with initial content
54-
for filename, content in files.items():
55-
with open(os.path.join(base_path, filename), 'w') as file:
56-
yaml.dump(content, file)
42+
# Create templates/web directory
43+
os.makedirs(os.path.join(project_name, templates_dir), exist_ok=True)
5744

58-
# Create service.yaml template
59-
service_yaml_content = """apiVersion: v1
60-
kind: Service
61-
metadata:
62-
name: {{ include "{project_name}.fullname" . }}
63-
spec:
64-
type: ClusterIP
65-
ports:
66-
- port: {{ .Values.web.service.port }}
67-
selector:
68-
app: {{ include "{project_name}.name" . }}
69-
"""
45+
# Create files
46+
with open(os.path.join(project_name, 'Chart.yaml'), 'w') as chart_file:
47+
chart_file.write(chart_yaml_content)
7048

71-
with open(os.path.join(base_path, 'templates', 'web', 'service.yaml'), 'w') as service_file:
72-
service_file.write(service_yaml_content.format(project_name=project_name))
49+
with open(os.path.join(project_name, 'values.yaml'), 'w') as values_file:
50+
values_file.write(values_yaml_content)
7351

74-
# Create secret.yaml template if environment variables exist
75-
if files['values.yaml']['web'].get('env'):
76-
secret_yaml_content = """apiVersion: v1
77-
kind: Secret
78-
metadata:
79-
name: {{ include "{project_name}.fullname" . }}-env
80-
type: Opaque
81-
data:
82-
ENV1: {{ .Values.web.env[0].value | b64enc | quote }}
83-
"""
52+
# Create template files and directories
53+
for template in template_subdirectories:
54+
template_path = os.path.join(project_name, 'templates', template)
55+
os.makedirs(template_path, exist_ok=True)
56+
for template_file in template_files:
57+
with open(os.path.join(template_path, template_file), 'w') as file:
58+
file.write(f"# {template_file} for {template}\n")
59+
60+
# Create secret.yaml if env variable is considered
61+
with open(os.path.join(template_path, 'secret.yaml'), 'w') as secret_file:
62+
secret_file.write("# secret.yaml for environment variables\n")
8463

85-
with open(os.path.join(base_path, 'templates', 'web', 'secret.yaml'), 'w') as secret_file:
86-
secret_file.write(secret_yaml_content.format(project_name=project_name))
64+
# Create helpers.tpl
65+
with open(os.path.join(template_path, 'helpers.tpl'), 'w') as helpers_file:
66+
helpers_file.write(f"""{{- define "{template}.labels" -}}
67+
name: {{ .Release.Name }}
68+
{{- end -}}
69+
// Add additional helper functions if needed
70+
""")

app/media/MyHelm/Chart.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apiVersion: v2
2-
appVersion: 1.0.0
2+
name: my-helm-chart
33
description: A Helm chart for Kubernetes
4-
name: MyHelm
54
version: 0.1.0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{- define "web.labels" -}
2+
name: { .Release.Name }
3+
{- end -}
4+
// Add additional helper functions if needed
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
apiVersion: v1
2-
kind: Secret
3-
metadata:
4-
name: { include "MyHelm.fullname" . }-env
5-
type: Opaque
6-
data:
7-
ENV1: { .Values.web.env[0].value | b64enc | quote }
1+
# secret.yaml for environment variables
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
apiVersion: v1
2-
kind: Service
3-
metadata:
4-
name: { include "MyHelm.fullname" . }
5-
spec:
6-
type: ClusterIP
7-
ports:
8-
- port: { .Values.web.service.port }
9-
selector:
10-
app: { include "MyHelm.name" . }
1+
# service.yaml for web

app/media/MyHelm/values.yaml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
web:
2+
image: nginx
3+
replicas: 1
4+
service:
5+
targetPort: 80
6+
persistence:
7+
enabled: true
8+
size: 1Gi
9+
accessModes:
10+
- ReadWriteOnce
211
env:
3-
- name: ENV1
4-
value: Hi
5-
image:
6-
repository: nginx
7-
tag: latest
12+
- name: ENV1
13+
value: Hi
814
ingress:
915
enabled: false
1016
host: www.example.com
11-
persistence:
12-
accessModes:
13-
- ReadWriteOnce
14-
enabled: true
15-
size: 1Gi
16-
replicaCount: 1
17-
service:
18-
enabled: true
19-
port: 80
0 Bytes
Binary file not shown.

app/prompt_generators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ def helm_template_generator(input : HelmTemplateGeneration) -> str:
8888
if environment variable is considered for pod, then create secret.yaml in the related template.
8989
9090
please set a something default in chart.yaml and values.yaml based on the requirement.
91+
please generate helpers.tpl for each template and initialize resources and set a label for reach resource.
9192
9293
just Generate a python code without any additional notes or ```python3 entry
9394
"""
94-
return prompt
95+
return prompt
96+
97+

0 commit comments

Comments
 (0)