diff --git a/setup-scripts/setup-genai-studio/internal-dns-config.yaml b/setup-scripts/setup-genai-studio/internal-dns-config.yaml new file mode 100644 index 0000000..e87c12e --- /dev/null +++ b/setup-scripts/setup-genai-studio/internal-dns-config.yaml @@ -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" \ No newline at end of file diff --git a/setup-scripts/setup-genai-studio/manifests/studio-manifest-aws-ecr.yaml b/setup-scripts/setup-genai-studio/manifests/studio-manifest-aws-ecr.yaml index f06d066..1e33a3d 100644 --- a/setup-scripts/setup-genai-studio/manifests/studio-manifest-aws-ecr.yaml +++ b/setup-scripts/setup-genai-studio/manifests/studio-manifest-aws-ecr.yaml @@ -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; @@ -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 @@ -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; @@ -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; @@ -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; @@ -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; @@ -144,7 +140,7 @@ 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; @@ -152,7 +148,7 @@ data: } 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; @@ -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 @@ -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: diff --git a/setup-scripts/setup-genai-studio/manifests/studio-manifest.yaml b/setup-scripts/setup-genai-studio/manifests/studio-manifest.yaml index e8ae60f..8665bb1 100644 --- a/setup-scripts/setup-genai-studio/manifests/studio-manifest.yaml +++ b/setup-scripts/setup-genai-studio/manifests/studio-manifest.yaml @@ -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; @@ -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 @@ -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; @@ -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; @@ -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; @@ -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; @@ -134,7 +130,7 @@ 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; @@ -142,7 +138,7 @@ data: } 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; @@ -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 @@ -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: diff --git a/setup-scripts/setup-genai-studio/playbooks/deploy-studio.yml b/setup-scripts/setup-genai-studio/playbooks/deploy-studio.yml index ce8fa22..70d2f3a 100644 --- a/setup-scripts/setup-genai-studio/playbooks/deploy-studio.yml +++ b/setup-scripts/setup-genai-studio/playbooks/deploy-studio.yml @@ -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: diff --git a/studio-backend/app/services/dashboard_service.py b/studio-backend/app/services/dashboard_service.py index b6aee9b..8535429 100644 --- a/studio-backend/app/services/dashboard_service.py +++ b/studio-backend/app/services/dashboard_service.py @@ -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") @@ -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() diff --git a/studio-backend/tests/test_deploy-sandbox.py b/studio-backend/tests/test_deploy-sandbox.py index 0705395..d582a02 100644 --- a/studio-backend/tests/test_deploy-sandbox.py +++ b/studio-backend/tests/test_deploy-sandbox.py @@ -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