Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions setup-scripts/setup-genai-studio/internal-dns-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: internal-dns-config
namespace: studio
data:
GRAFANA_DNS: "kube-prometheus-stack-grafana.monitoring.svc.cluster.local"
STUDIO_FRONTEND_DNS: "studio-frontend.studio.svc.cluster.local:3000"
APP_FRONTEND_DNS: "app-frontend.$namespace.svc.cluster.local:5175"
APP_BACKEND_DNS: "app-backend.$namespace.svc.cluster.local:8888"
PREPARE_DOC_REDIS_PREP_DNS: "prepare-doc-redis-prep-0.$namespace.svc.cluster.local:6007"
STUDIO_BACKEND_DNS: "studio-backend.studio.svc.cluster.local:5000"
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ data:
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

upstream grafana {
server localhost:3000;
}

server {
listen 80;
listen [::]:80;
Expand Down Expand Up @@ -58,9 +54,9 @@ data:
}

# Initialize the target host
set $target_host http://studio-frontend.studio.svc.cluster.local:3000;
set $target_host http://${STUDIO_FRONTEND_DNS};
if ($namespace != "") {
set $target_host http://app-frontend.$namespace.svc.cluster.local:5175;
set $target_host http://${APP_FRONTEND_DNS};
}

# Rewrite the request to include the namespace
Expand All @@ -86,7 +82,7 @@ data:
rewrite ^/(.*)$ /$1?ns=$namespace break;

# Proxy to the desired service using the namespace
proxy_pass http://app-backend.$namespace.svc.cluster.local:8888;
proxy_pass http://${APP_BACKEND_DNS};

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
Expand All @@ -112,7 +108,7 @@ data:
rewrite ^/(.*)$ /$1?ns=$namespace break;

# Proxy to the desired service using the namespace
proxy_pass http://prepare-doc-redis-prep-0.$namespace.svc.cluster.local:6007;
proxy_pass http://${PREPARE_DOC_REDIS_PREP_DNS};

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
Expand All @@ -122,7 +118,7 @@ data:

# Additional location block for Grafana static assets
location /grafana {
proxy_pass http://kube-prometheus-stack-grafana.monitoring.svc.cluster.local;
proxy_pass http://${GRAFANA_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand All @@ -131,7 +127,7 @@ data:

# Proxy Grafana Live WebSocket connections
location /grafana/api/live/ {
proxy_pass http://kube-prometheus-stack-grafana.monitoring.svc.cluster.local;
proxy_pass http://${GRAFANA_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand All @@ -144,15 +140,15 @@ data:
}

location /studio-backend {
proxy_pass http://studio-backend.studio.svc.cluster.local:5000;
proxy_pass http://${STUDIO_BACKEND_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /studio-backend/ws {
proxy_pass http://studio-backend.studio.svc.cluster.local:5000/studio-backend/ws;
proxy_pass http://${STUDIO_BACKEND_DNS}/studio-backend/ws;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down Expand Up @@ -196,19 +192,36 @@ spec:
labels:
app: studio-nginx
spec:
initContainers:
- name: init-nginx
image: nginx:1.27.1
command: ["/bin/sh", "-c"]
args:
- |
envsubst "$(env | grep _DNS= | awk -F= '{print "${"$1"}"}' | tr '\n' ' ')" < /tmp/default.conf > /etc/nginx/conf.d/default.conf
envFrom:
- configMapRef:
name: internal-dns-config
volumeMounts:
- name: tmp-volume
mountPath: /tmp
- name: nginx-conf-volume
mountPath: /etc/nginx/conf.d
containers:
- image: nginx:1.27.1
- name: nginx
image: nginx:1.27.1
imagePullPolicy: IfNotPresent
name: nginx
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: nginx-config-volume
- name: nginx-conf-volume
mountPath: /etc/nginx/conf.d
securityContext: {}
volumes:
- configMap:
- name: tmp-volume
configMap:
defaultMode: 420
name: studio-nginx-config
name: nginx-config-volume
- name: nginx-conf-volume
emptyDir: {}
---
apiVersion: v1
kind: Service
Expand Down Expand Up @@ -307,6 +320,9 @@ spec:
value: ${HTTP_PROXY}
- name: SBX_NO_PROXY
value: ${NO_PROXY}
envFrom:
- configMapRef:
name: internal-dns-config
ports:
- containerPort: 5000
resources:
Expand Down
52 changes: 34 additions & 18 deletions setup-scripts/setup-genai-studio/manifests/studio-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ data:
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

upstream grafana {
server localhost:3000;
}

server {
listen 80;
listen [::]:80;
Expand Down Expand Up @@ -48,9 +44,9 @@ data:
}

# Initialize the target host
set $target_host http://studio-frontend.studio.svc.cluster.local:3000;
set $target_host http://${STUDIO_FRONTEND_DNS};
if ($namespace != "") {
set $target_host http://app-frontend.$namespace.svc.cluster.local:5175;
set $target_host http://${APP_FRONTEND_DNS};
}

# Rewrite the request to include the namespace
Expand All @@ -76,7 +72,7 @@ data:
rewrite ^/(.*)$ /$1?ns=$namespace break;

# Proxy to the desired service using the namespace
proxy_pass http://app-backend.$namespace.svc.cluster.local:8888;
proxy_pass http://${APP_BACKEND_DNS};

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
Expand All @@ -102,7 +98,7 @@ data:
rewrite ^/(.*)$ /$1?ns=$namespace break;

# Proxy to the desired service using the namespace
proxy_pass http://prepare-doc-redis-prep-0.$namespace.svc.cluster.local:6007;
proxy_pass http://${PREPARE_DOC_REDIS_PREP_DNS};

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
Expand All @@ -112,7 +108,7 @@ data:

# Additional location block for Grafana static assets
location /grafana {
proxy_pass http://kube-prometheus-stack-grafana.monitoring.svc.cluster.local;
proxy_pass http://${GRAFANA_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand All @@ -121,7 +117,7 @@ data:

# Proxy Grafana Live WebSocket connections
location /grafana/api/live/ {
proxy_pass http://kube-prometheus-stack-grafana.monitoring.svc.cluster.local;
proxy_pass http://${GRAFANA_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand All @@ -134,15 +130,15 @@ data:
}

location /studio-backend {
proxy_pass http://studio-backend.studio.svc.cluster.local:5000;
proxy_pass http://${STUDIO_BACKEND_DNS};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /studio-backend/ws {
proxy_pass http://studio-backend.studio.svc.cluster.local:5000/studio-backend/ws;
proxy_pass http://${STUDIO_BACKEND_DNS}/studio-backend/ws;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down Expand Up @@ -186,19 +182,36 @@ spec:
labels:
app: studio-nginx
spec:
initContainers:
- name: init-nginx
image: nginx:1.27.1
command: ["/bin/sh", "-c"]
args:
- |
envsubst "$(env | grep _DNS= | awk -F= '{print "${"$1"}"}' | tr '\n' ' ')" < /tmp/default.conf > /etc/nginx/conf.d/default.conf
envFrom:
- configMapRef:
name: internal-dns-config
volumeMounts:
- name: tmp-volume
mountPath: /tmp
- name: nginx-conf-volume
mountPath: /etc/nginx/conf.d
containers:
- image: nginx:1.27.1
- name: nginx
image: nginx:1.27.1
imagePullPolicy: IfNotPresent
name: nginx
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: nginx-config-volume
- name: nginx-conf-volume
mountPath: /etc/nginx/conf.d
securityContext: {}
volumes:
- configMap:
- name: tmp-volume
configMap:
defaultMode: 420
name: studio-nginx-config
name: nginx-config-volume
- name: nginx-conf-volume
emptyDir: {}
---
apiVersion: v1
kind: Service
Expand Down Expand Up @@ -297,6 +310,9 @@ spec:
value: ${HTTP_PROXY}
- name: SBX_NO_PROXY
value: ${NO_PROXY}
envFrom:
- configMapRef:
name: internal-dns-config
ports:
- containerPort: 5000
resources:
Expand Down
3 changes: 3 additions & 0 deletions setup-scripts/setup-genai-studio/playbooks/deploy-studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
shell: sed -i 's/kube-dns/coredns/g' ../manifests/studio-manifest.yaml
when: coredns_check.stdout != ''

- name: Apply internal DNS configuration
command: kubectl apply -f ../internal-dns-config.yaml

- name: Apply customized studio manifest
shell: "envsubst '${REGISTRY} ${TAG} ${HTTP_PROXY} ${NO_PROXY}' < ../manifests/studio-manifest.yaml | kubectl apply -f -"
environment:
Expand Down
4 changes: 2 additions & 2 deletions studio-backend/app/services/dashboard_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def import_grafana_dashboards(namespace_name):

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

print("Getting headers")
Expand Down Expand Up @@ -42,7 +42,7 @@ def import_grafana_dashboards(namespace_name):
return response.text

def delete_dashboard(namespace_name):
grafana_url = os.getenv("GRAFANA_URL", "kube-prometheus-stack-grafana.monitoring.svc.cluster.local")
grafana_url = os.getenv("GRAFANA_DNS", "localhost:30007")
post_url = f"http://{grafana_url}/grafana/api/dashboards/uid/{namespace_name.replace('sandbox-','')}"
auth_str = f"admin:prom-operator"
b64_auth_str = base64.b64encode(auth_str.encode()).decode()
Expand Down
1 change: 0 additions & 1 deletion studio-backend/tests/test_deploy-sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def test_deploy_sandbox_api(setup_and_teardown):

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

# Check that the response is successful
Expand Down
Loading