diff --git a/.gitignore b/.gitignore index 3240055..e363260 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,5 @@ dist backend/server/projects backend/database/drizzle -app.yaml \ No newline at end of file +app.yaml +ingressController.yaml \ No newline at end of file diff --git a/backend/orchestrator/.gcloudignore b/backend/orchestrator/.gcloudignore index 8067b59..ca3b9fc 100644 --- a/backend/orchestrator/.gcloudignore +++ b/backend/orchestrator/.gcloudignore @@ -15,5 +15,6 @@ # Node.js dependencies: node_modules/ +.env -.env \ No newline at end of file +ingressController.yaml \ No newline at end of file diff --git a/backend/orchestrator/src/index.ts b/backend/orchestrator/src/index.ts index 1db36ac..d25e6cf 100644 --- a/backend/orchestrator/src/index.ts +++ b/backend/orchestrator/src/index.ts @@ -30,24 +30,14 @@ if (process.env.NODE_ENV === "production") { kubeconfig.loadFromOptions({ clusters: [ { - name: 'docker-desktop', - server: process.env.DOCKER_DESKTOP_SERVER!, - caData: process.env.DOCKER_DESKTOP_CA_DATA, - }, - { - name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox', + name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox-cluster', server: process.env.GKE_CLUSTER_SERVER!, caData: process.env.GKE_CLUSTER_CA_DATA, } ], users: [ { - name: 'docker-desktop', - certData: process.env.DOCKER_DESKTOP_CLIENT_CERTIFICATE_DATA, - keyData: process.env.DOCKER_DESKTOP_CLIENT_KEY_DATA, - }, - { - name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox', + name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox-cluster', exec: { apiVersion: 'client.authentication.k8s.io/v1beta1', command: 'gke-gcloud-auth-plugin', @@ -76,8 +66,8 @@ if (process.env.NODE_ENV === "production") { } kubeconfig.loadFromDefault() -const coreV1Api = kubeconfig.makeApiClient(CoreV1Api) const appsV1Api = kubeconfig.makeApiClient(AppsV1Api) +const coreV1Api = kubeconfig.makeApiClient(CoreV1Api) const networkingV1Api = kubeconfig.makeApiClient(NetworkingV1Api) const readAndParseKubeYaml = ( @@ -131,14 +121,15 @@ app.post("/start", async (req, res) => { sandboxId ) - console.log("Successfully read and parsed kube yaml") - async function resourceExists(api: any, getMethod: string, name: string) { try { - await api[getMethod](namespace, name) + await api[getMethod](name, namespace) return true } catch (e: any) { - if (e.response && e.response.statusCode === 404) return false + if (e.response && e.response.statusCode === 404) { + console.log("Resource does not exist.", e.response.body.message, e.response.body.details) + return false + } throw e } } @@ -150,22 +141,16 @@ app.post("/start", async (req, res) => { if (!(await resourceExists(appsV1Api, 'readNamespacedDeployment', name))) { await appsV1Api.createNamespacedDeployment(namespace, manifest) console.log("Made deploymnet") - } else { - return res.status(200).send({ message: "Resource deployment already exists." }) } else if (kind === "Service") if (!(await resourceExists(coreV1Api, 'readNamespacedService', name))) { await coreV1Api.createNamespacedService(namespace, manifest) console.log("Made service") - } else { - return res.status(200).send({ message: "Resource service already exists." }) } else if (kind === "Ingress") if (!(await resourceExists(networkingV1Api, 'readNamespacedIngress', name))) { await networkingV1Api.createNamespacedIngress(namespace, manifest) console.log("Made ingress") - } else { - return res.status(200).send({ message: "Resource ingress already exists." }) } }) diff --git a/backend/server/src/index.ts b/backend/server/src/index.ts index 0553024..9c447fc 100644 --- a/backend/server/src/index.ts +++ b/backend/server/src/index.ts @@ -441,7 +441,7 @@ io.on("connection", async (socket) => { if (sockets.length === 0) { // close server console.log("Closing server due to inactivity."); - // const res = await stopServer(data.sandboxId, data.userId) + const res = await stopServer(data.sandboxId, data.userId) } }); }, 20000); diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index 928700a..df99094 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -4,7 +4,7 @@ import dynamic from "next/dynamic"; import Loading from "@/components/editor/loading"; import { Sandbox, User } from "@/lib/types"; import { useEffect, useState } from "react"; -import { startServer, stopServer } from "@/lib/utils"; +import { startServer } from "@/lib/utils"; import { toast } from "sonner"; const CodeEditor = dynamic(() => import("@/components/editor/editor"), { @@ -32,9 +32,9 @@ export default function Editor({ } }); - return () => { - stopServer(sandboxData.id, userData.id); - }; + // return () => { + // stopServer(sandboxData.id, userData.id); + // }; }, []); if (!isServerRunning) diff --git a/frontend/components/editor/preview/index.tsx b/frontend/components/editor/preview/index.tsx index afc503c..3373ec9 100644 --- a/frontend/components/editor/preview/index.tsx +++ b/frontend/components/editor/preview/index.tsx @@ -29,7 +29,7 @@ export default function PreviewWindow({