Skip to content

Commit a63ea60

Browse files
authored
moved hardcoded internal dns into configmap (#19)
* moved hardcoded internal dns into configmap Signed-off-by: wwanarif <[email protected]> * udpate setup script to apply internal dns configmap Signed-off-by: wwanarif <[email protected]> --------- Signed-off-by: wwanarif <[email protected]>
1 parent e6c4229 commit a63ea60

File tree

6 files changed

+85
-39
lines changed

6 files changed

+85
-39
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: internal-dns-config
5+
namespace: studio
6+
data:
7+
GRAFANA_DNS: "kube-prometheus-stack-grafana.monitoring.svc.cluster.local"
8+
STUDIO_FRONTEND_DNS: "studio-frontend.studio.svc.cluster.local:3000"
9+
APP_FRONTEND_DNS: "app-frontend.$namespace.svc.cluster.local:5175"
10+
APP_BACKEND_DNS: "app-backend.$namespace.svc.cluster.local:8888"
11+
PREPARE_DOC_REDIS_PREP_DNS: "prepare-doc-redis-prep-0.$namespace.svc.cluster.local:6007"
12+
STUDIO_BACKEND_DNS: "studio-backend.studio.svc.cluster.local:5000"

setup-scripts/setup-genai-studio/manifests/studio-manifest-aws-ecr.yaml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ data:
1919
# Copyright (C) 2024 Intel Corporation
2020
# SPDX-License-Identifier: Apache-2.0
2121
22-
upstream grafana {
23-
server localhost:3000;
24-
}
25-
2622
server {
2723
listen 80;
2824
listen [::]:80;
@@ -58,9 +54,9 @@ data:
5854
}
5955
6056
# Initialize the target host
61-
set $target_host http://studio-frontend.studio.svc.cluster.local:3000;
57+
set $target_host http://${STUDIO_FRONTEND_DNS};
6258
if ($namespace != "") {
63-
set $target_host http://app-frontend.$namespace.svc.cluster.local:5175;
59+
set $target_host http://${APP_FRONTEND_DNS};
6460
}
6561
6662
# Rewrite the request to include the namespace
@@ -86,7 +82,7 @@ data:
8682
rewrite ^/(.*)$ /$1?ns=$namespace break;
8783
8884
# Proxy to the desired service using the namespace
89-
proxy_pass http://app-backend.$namespace.svc.cluster.local:8888;
85+
proxy_pass http://${APP_BACKEND_DNS};
9086
9187
proxy_set_header Host $host;
9288
proxy_set_header X-Real-IP $remote_addr;
@@ -112,7 +108,7 @@ data:
112108
rewrite ^/(.*)$ /$1?ns=$namespace break;
113109
114110
# Proxy to the desired service using the namespace
115-
proxy_pass http://prepare-doc-redis-prep-0.$namespace.svc.cluster.local:6007;
111+
proxy_pass http://${PREPARE_DOC_REDIS_PREP_DNS};
116112
117113
proxy_set_header Host $host;
118114
proxy_set_header X-Real-IP $remote_addr;
@@ -122,7 +118,7 @@ data:
122118
123119
# Additional location block for Grafana static assets
124120
location /grafana {
125-
proxy_pass http://kube-prometheus-stack-grafana.monitoring.svc.cluster.local;
121+
proxy_pass http://${GRAFANA_DNS};
126122
proxy_set_header Host $host;
127123
proxy_set_header X-Real-IP $remote_addr;
128124
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -131,7 +127,7 @@ data:
131127
132128
# Proxy Grafana Live WebSocket connections
133129
location /grafana/api/live/ {
134-
proxy_pass http://kube-prometheus-stack-grafana.monitoring.svc.cluster.local;
130+
proxy_pass http://${GRAFANA_DNS};
135131
proxy_set_header Host $host;
136132
proxy_set_header X-Real-IP $remote_addr;
137133
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -144,15 +140,15 @@ data:
144140
}
145141
146142
location /studio-backend {
147-
proxy_pass http://studio-backend.studio.svc.cluster.local:5000;
143+
proxy_pass http://${STUDIO_BACKEND_DNS};
148144
proxy_set_header Host $host;
149145
proxy_set_header X-Real-IP $remote_addr;
150146
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
151147
proxy_set_header X-Forwarded-Proto $scheme;
152148
}
153149
154150
location /studio-backend/ws {
155-
proxy_pass http://studio-backend.studio.svc.cluster.local:5000/studio-backend/ws;
151+
proxy_pass http://${STUDIO_BACKEND_DNS}/studio-backend/ws;
156152
proxy_set_header Host $host;
157153
proxy_set_header X-Real-IP $remote_addr;
158154
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -196,19 +192,36 @@ spec:
196192
labels:
197193
app: studio-nginx
198194
spec:
195+
initContainers:
196+
- name: init-nginx
197+
image: nginx:1.27.1
198+
command: ["/bin/sh", "-c"]
199+
args:
200+
- |
201+
envsubst "$(env | grep _DNS= | awk -F= '{print "${"$1"}"}' | tr '\n' ' ')" < /tmp/default.conf > /etc/nginx/conf.d/default.conf
202+
envFrom:
203+
- configMapRef:
204+
name: internal-dns-config
205+
volumeMounts:
206+
- name: tmp-volume
207+
mountPath: /tmp
208+
- name: nginx-conf-volume
209+
mountPath: /etc/nginx/conf.d
199210
containers:
200-
- image: nginx:1.27.1
211+
- name: nginx
212+
image: nginx:1.27.1
201213
imagePullPolicy: IfNotPresent
202-
name: nginx
203214
volumeMounts:
204-
- mountPath: /etc/nginx/conf.d
205-
name: nginx-config-volume
215+
- name: nginx-conf-volume
216+
mountPath: /etc/nginx/conf.d
206217
securityContext: {}
207218
volumes:
208-
- configMap:
219+
- name: tmp-volume
220+
configMap:
209221
defaultMode: 420
210222
name: studio-nginx-config
211-
name: nginx-config-volume
223+
- name: nginx-conf-volume
224+
emptyDir: {}
212225
---
213226
apiVersion: v1
214227
kind: Service
@@ -307,6 +320,9 @@ spec:
307320
value: ${HTTP_PROXY}
308321
- name: SBX_NO_PROXY
309322
value: ${NO_PROXY}
323+
envFrom:
324+
- configMapRef:
325+
name: internal-dns-config
310326
ports:
311327
- containerPort: 5000
312328
resources:

setup-scripts/setup-genai-studio/manifests/studio-manifest.yaml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ data:
99
# Copyright (C) 2024 Intel Corporation
1010
# SPDX-License-Identifier: Apache-2.0
1111
12-
upstream grafana {
13-
server localhost:3000;
14-
}
15-
1612
server {
1713
listen 80;
1814
listen [::]:80;
@@ -48,9 +44,9 @@ data:
4844
}
4945
5046
# Initialize the target host
51-
set $target_host http://studio-frontend.studio.svc.cluster.local:3000;
47+
set $target_host http://${STUDIO_FRONTEND_DNS};
5248
if ($namespace != "") {
53-
set $target_host http://app-frontend.$namespace.svc.cluster.local:5175;
49+
set $target_host http://${APP_FRONTEND_DNS};
5450
}
5551
5652
# Rewrite the request to include the namespace
@@ -76,7 +72,7 @@ data:
7672
rewrite ^/(.*)$ /$1?ns=$namespace break;
7773
7874
# Proxy to the desired service using the namespace
79-
proxy_pass http://app-backend.$namespace.svc.cluster.local:8888;
75+
proxy_pass http://${APP_BACKEND_DNS};
8076
8177
proxy_set_header Host $host;
8278
proxy_set_header X-Real-IP $remote_addr;
@@ -102,7 +98,7 @@ data:
10298
rewrite ^/(.*)$ /$1?ns=$namespace break;
10399
104100
# Proxy to the desired service using the namespace
105-
proxy_pass http://prepare-doc-redis-prep-0.$namespace.svc.cluster.local:6007;
101+
proxy_pass http://${PREPARE_DOC_REDIS_PREP_DNS};
106102
107103
proxy_set_header Host $host;
108104
proxy_set_header X-Real-IP $remote_addr;
@@ -112,7 +108,7 @@ data:
112108
113109
# Additional location block for Grafana static assets
114110
location /grafana {
115-
proxy_pass http://kube-prometheus-stack-grafana.monitoring.svc.cluster.local;
111+
proxy_pass http://${GRAFANA_DNS};
116112
proxy_set_header Host $host;
117113
proxy_set_header X-Real-IP $remote_addr;
118114
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -121,7 +117,7 @@ data:
121117
122118
# Proxy Grafana Live WebSocket connections
123119
location /grafana/api/live/ {
124-
proxy_pass http://kube-prometheus-stack-grafana.monitoring.svc.cluster.local;
120+
proxy_pass http://${GRAFANA_DNS};
125121
proxy_set_header Host $host;
126122
proxy_set_header X-Real-IP $remote_addr;
127123
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -134,15 +130,15 @@ data:
134130
}
135131
136132
location /studio-backend {
137-
proxy_pass http://studio-backend.studio.svc.cluster.local:5000;
133+
proxy_pass http://${STUDIO_BACKEND_DNS};
138134
proxy_set_header Host $host;
139135
proxy_set_header X-Real-IP $remote_addr;
140136
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
141137
proxy_set_header X-Forwarded-Proto $scheme;
142138
}
143139
144140
location /studio-backend/ws {
145-
proxy_pass http://studio-backend.studio.svc.cluster.local:5000/studio-backend/ws;
141+
proxy_pass http://${STUDIO_BACKEND_DNS}/studio-backend/ws;
146142
proxy_set_header Host $host;
147143
proxy_set_header X-Real-IP $remote_addr;
148144
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -186,19 +182,36 @@ spec:
186182
labels:
187183
app: studio-nginx
188184
spec:
185+
initContainers:
186+
- name: init-nginx
187+
image: nginx:1.27.1
188+
command: ["/bin/sh", "-c"]
189+
args:
190+
- |
191+
envsubst "$(env | grep _DNS= | awk -F= '{print "${"$1"}"}' | tr '\n' ' ')" < /tmp/default.conf > /etc/nginx/conf.d/default.conf
192+
envFrom:
193+
- configMapRef:
194+
name: internal-dns-config
195+
volumeMounts:
196+
- name: tmp-volume
197+
mountPath: /tmp
198+
- name: nginx-conf-volume
199+
mountPath: /etc/nginx/conf.d
189200
containers:
190-
- image: nginx:1.27.1
201+
- name: nginx
202+
image: nginx:1.27.1
191203
imagePullPolicy: IfNotPresent
192-
name: nginx
193204
volumeMounts:
194-
- mountPath: /etc/nginx/conf.d
195-
name: nginx-config-volume
205+
- name: nginx-conf-volume
206+
mountPath: /etc/nginx/conf.d
196207
securityContext: {}
197208
volumes:
198-
- configMap:
209+
- name: tmp-volume
210+
configMap:
199211
defaultMode: 420
200212
name: studio-nginx-config
201-
name: nginx-config-volume
213+
- name: nginx-conf-volume
214+
emptyDir: {}
202215
---
203216
apiVersion: v1
204217
kind: Service
@@ -297,6 +310,9 @@ spec:
297310
value: ${HTTP_PROXY}
298311
- name: SBX_NO_PROXY
299312
value: ${NO_PROXY}
313+
envFrom:
314+
- configMapRef:
315+
name: internal-dns-config
300316
ports:
301317
- containerPort: 5000
302318
resources:

setup-scripts/setup-genai-studio/playbooks/deploy-studio.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
shell: sed -i 's/kube-dns/coredns/g' ../manifests/studio-manifest.yaml
1919
when: coredns_check.stdout != ''
2020

21+
- name: Apply internal DNS configuration
22+
command: kubectl apply -f ../internal-dns-config.yaml
23+
2124
- name: Apply customized studio manifest
2225
shell: "envsubst '${REGISTRY} ${TAG} ${HTTP_PROXY} ${NO_PROXY}' < ../manifests/studio-manifest.yaml | kubectl apply -f -"
2326
environment:

studio-backend/app/services/dashboard_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def import_grafana_dashboards(namespace_name):
1212

1313
print("Getting post_url")
14-
grafana_url = os.getenv("GRAFANA_URL", "kube-prometheus-stack-grafana.monitoring.svc.cluster.local")
14+
grafana_url = os.getenv("GRAFANA_DNS", "localhost:30007")
1515
post_url = f"http://{grafana_url}/grafana/api/dashboards/db"
1616

1717
print("Getting headers")
@@ -42,7 +42,7 @@ def import_grafana_dashboards(namespace_name):
4242
return response.text
4343

4444
def delete_dashboard(namespace_name):
45-
grafana_url = os.getenv("GRAFANA_URL", "kube-prometheus-stack-grafana.monitoring.svc.cluster.local")
45+
grafana_url = os.getenv("GRAFANA_DNS", "localhost:30007")
4646
post_url = f"http://{grafana_url}/grafana/api/dashboards/uid/{namespace_name.replace('sandbox-','')}"
4747
auth_str = f"admin:prom-operator"
4848
b64_auth_str = base64.b64encode(auth_str.encode()).decode()

studio-backend/tests/test_deploy-sandbox.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def test_deploy_sandbox_api(setup_and_teardown):
5959

6060
# Simulate a POST request to the /deploy-sandbox endpoint with the JSON payload
6161
test_client = TestClient(app)
62-
os.environ["GRAFANA_URL"] = "localhost:30007"
6362
response = test_client.post("/studio-backend/deploy-sandbox", content=json.dumps(payload))
6463

6564
# Check that the response is successful

0 commit comments

Comments
 (0)