Skip to content

Commit c7fc020

Browse files
authored
feat: Merge pull request #22 from abolfazl8131/feature/ingress
add ingress
2 parents 715b3ba + 03a52a6 commit c7fc020

10 files changed

Lines changed: 97 additions & 111 deletions

File tree

-145 Bytes
Binary file not shown.
Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,86 @@
11
import os
2+
import yaml
23

3-
# Define the project structure
4-
project_name = "MyHelm"
5-
base_path = "app/media/"
6-
project_path = os.path.join(base_path, project_name)
4+
# Define directory and file structure
5+
project_name = 'MyHelm'
6+
base_path = os.path.join('app', 'media', project_name)
77

88
directories = [
9-
"charts",
10-
"templates/web"
9+
os.path.join(base_path, 'charts'),
10+
os.path.join(base_path, 'templates', 'web')
1111
]
1212

13-
files_and_contents = {
14-
"Chart.yaml": """apiVersion: v2
15-
name: MyHelm
16-
description: A Helm chart for Kubernetes
17-
version: 0.1.0
18-
""",
19-
"values.yaml": """web:
20-
image: nginx
21-
targetPort: 80
22-
replicas: 1
23-
persistence:
24-
size: 1Gi
25-
accessModes:
26-
- ReadWriteOnce
27-
env:
28-
- name: ENV1
29-
value: Hi
30-
ingress:
31-
enabled: true
32-
stateless: true
33-
""",
34-
"templates/web/service.yaml": """apiVersion: v1
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+
}
48+
49+
# Create directories
50+
for directory in directories:
51+
os.makedirs(directory, exist_ok=True)
52+
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)
57+
58+
# Create service.yaml template
59+
service_yaml_content = """apiVersion: v1
3560
kind: Service
3661
metadata:
37-
name: {{ .Release.Name }}-web
62+
name: {{ include "{project_name}.fullname" . }}
3863
spec:
3964
type: ClusterIP
4065
ports:
41-
- port: 80
42-
targetPort: {{ .Values.web.targetPort }}
43-
selector:
44-
app: {{ .Release.Name }}-web
45-
""",
46-
"templates/web/deployment.yaml": """apiVersion: apps/v1
47-
kind: Deployment
48-
metadata:
49-
name: {{ .Release.Name }}-web
50-
spec:
51-
replicas: {{ .Values.web.replicas }}
66+
- port: {{ .Values.web.service.port }}
5267
selector:
53-
matchLabels:
54-
app: {{ .Release.Name }}-web
55-
template:
56-
metadata:
57-
labels:
58-
app: {{ .Release.Name }}-web
59-
spec:
60-
containers:
61-
- name: web
62-
image: {{ .Values.web.image }}
63-
ports:
64-
- containerPort: {{ .Values.web.targetPort }}
65-
env:
66-
- name: {{ .Values.web.env[0].name }}
67-
value: {{ .Values.web.env[0].value }}
68-
""",
69-
"templates/web/secret.yaml": """apiVersion: v1
68+
app: {{ include "{project_name}.name" . }}
69+
"""
70+
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))
73+
74+
# Create secret.yaml template if environment variables exist
75+
if files['values.yaml']['web'].get('env'):
76+
secret_yaml_content = """apiVersion: v1
7077
kind: Secret
7178
metadata:
72-
name: {{ .Release.Name }}-web-secret
79+
name: {{ include "{project_name}.fullname" . }}-env
7380
type: Opaque
7481
data:
7582
ENV1: {{ .Values.web.env[0].value | b64enc | quote }}
7683
"""
77-
}
78-
79-
# Create directories and files
80-
os.makedirs(project_path, exist_ok=True)
81-
for directory in directories:
82-
os.makedirs(os.path.join(project_path, directory), exist_ok=True)
8384

84-
for file_path, content in files_and_contents.items():
85-
with open(os.path.join(project_path, file_path), 'w') as f:
86-
f.write(content)
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))

app/media/MyHelm/Chart.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apiVersion: v2
2-
name: MyHelm
2+
appVersion: 1.0.0
33
description: A Helm chart for Kubernetes
4+
name: MyHelm
45
version: 0.1.0

app/media/MyHelm/templates/web/deployment.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: Secret
33
metadata:
4-
name: {{ .Release.Name }}-web-secret
4+
name: { include "MyHelm.fullname" . }-env
55
type: Opaque
66
data:
7-
ENV1: {{ .Values.web.env[0].value | b64enc | quote }}
7+
ENV1: { .Values.web.env[0].value | b64enc | quote }
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4-
name: {{ .Release.Name }}-web
4+
name: { include "MyHelm.fullname" . }
55
spec:
66
type: ClusterIP
77
ports:
8-
- port: 80
9-
targetPort: {{ .Values.web.targetPort }}
8+
- port: { .Values.web.service.port }
109
selector:
11-
app: {{ .Release.Name }}-web
10+
app: { include "MyHelm.name" . }

app/media/MyHelm/values.yaml

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

app/models/helm_models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class Environment(BaseModel):
99
name:str = "ENV1"
1010
value:str = "Hi"
1111

12+
class Ingress(BaseModel):
13+
enabled:bool = False
14+
host:str = "www.example.com"
15+
1216
class Pod(BaseModel):
1317
name:str = "web"
1418
image:str = "nginx"
@@ -17,7 +21,7 @@ class Pod(BaseModel):
1721
persistance: Persistance
1822
environment: List[Environment]
1923
stateless:bool = True
20-
ingress:bool = False
24+
ingress: Ingress
2125

2226
class HelmTemplateGeneration(BaseModel):
2327
api_version:int = 2

app/prompt_generators.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ def helm_template_generator(input : HelmTemplateGeneration) -> str:
8383
set replicas of pods following this dict format : {replicas_}.
8484
set persistance (pvc) of pods following this dict fomrat : {persistance}
8585
set environment variables of pods like this dict format : {envs}
86-
set ingress for pod if the pod ingress is true. here is a dict format for ingress : {ingress_}.
87-
create deployment.yaml in the related template if the pod stateless == true,
88-
you can see each pod status here in the dict format : {status}
86+
initialize ingress with a default host for pod if the pod ingress is true in here {ingress_}.
87+
8988
if environment variable is considered for pod, then create secret.yaml in the related template.
9089
91-
please set a something default in chart.yaml and values.yaml
90+
please set a something default in chart.yaml and values.yaml based on the requirement.
9291
9392
just Generate a python code without any additional notes or ```python3 entry
9493
"""

0 commit comments

Comments
 (0)