working orchestrator

This commit is contained in:
Ishaan Dey 2024-05-13 13:22:11 -07:00
parent 6a6ddf5363
commit aef8105bb0
4 changed files with 48 additions and 40 deletions

View File

@ -15,17 +15,17 @@ spec:
app: <SANDBOX>
spec:
volumes:
- name: workspace-volume
- name: projects-volume
emptyDir: {}
containers:
- name: runner
- name: sandbox
image: ishaan1013/sandbox:latest
ports:
- containerPort: 4000
- containerPort: 8000
- containerPort: 3000
volumeMounts:
- name: workspace-volume
mountPath: /workspace
- name: projects-volume
mountPath: /projects
resources:
requests:
cpu: "1"
@ -53,14 +53,16 @@ spec:
port: 4000
targetPort: 4000
- protocol: TCP
name: s
port: 8000
targetPort: 8000
name: user
port: 3000
targetPort: 3000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: <SANDBOX>
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
ingressClassName: nginx
rules:
@ -83,4 +85,4 @@ spec:
service:
name: <SANDBOX>
port:
number: 8000
number: 3000

View File

@ -18,11 +18,11 @@ const port = process.env.PORT || 4001
app.use(express.json())
dotenv.config()
const corsOptions = {
origin: ['http://localhost:3000', 'https://s.ishaand.com', 'http://localhost:4000', /\.ws\.ishaand\.com$/],
}
// const corsOptions = {
// origin: ['http://localhost:3000', 'https://s.ishaand.com', 'http://localhost:4000', /\.ws\.ishaand\.com$/],
// }
// app.use(cors(corsOptions))
app.use(cors())
const kubeconfig = new KubeConfig()
@ -41,8 +41,6 @@ if (process.env.NODE_ENV === "production") {
exec: {
apiVersion: 'client.authentication.k8s.io/v1beta1',
command: 'gke-gcloud-auth-plugin',
args: [],
env: null,
installHint: 'Install gke-gcloud-auth-plugin for use with kubectl by following https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_plugin',
interactiveMode: 'IfAvailable',
provideClusterInfo: true
@ -51,17 +49,12 @@ if (process.env.NODE_ENV === "production") {
],
contexts: [
{
name: 'docker-desktop',
cluster: 'docker-desktop',
user: 'docker-desktop'
},
{
name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox',
cluster: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox',
user: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox'
name: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox-cluster',
cluster: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox-cluster',
user: 'gke_sylvan-epoch-422219-f9_us-central1_sandbox-cluster'
}
],
currentContext: "gke_sylvan-epoch-422219-f9_us-central1_sandbox",
currentContext: "gke_sylvan-epoch-422219-f9_us-central1_sandbox-cluster"
});
}
kubeconfig.loadFromDefault()
@ -134,23 +127,31 @@ app.post("/start", async (req, res) => {
}
}
const createResource = async (api: any, method: string, manifest: any) => {
const { kind, metadata: { name } } = manifest;
if (!(await resourceExists(api, 'readNamespaced' + kind, name))) {
await api['createNamespaced' + kind](namespace, manifest);
console.log(`Created ${kind.toLowerCase()}`, name);
} else {
console.log(`${kind} ${name} already exists.`);
}
};
const promises = kubeManifests.map(async (manifest) => {
const { kind, metadata: { name } } = manifest
if (kind === "Deployment")
if (!(await resourceExists(appsV1Api, 'readNamespacedDeployment', name))) {
await appsV1Api.createNamespacedDeployment(namespace, manifest)
console.log("Made deploymnet")
}
else if (kind === "Service")
if (!(await resourceExists(coreV1Api, 'readNamespacedService', name))) {
await coreV1Api.createNamespacedService(namespace, manifest)
console.log("Made service")
}
else if (kind === "Ingress")
if (!(await resourceExists(networkingV1Api, 'readNamespacedIngress', name))) {
await networkingV1Api.createNamespacedIngress(namespace, manifest)
console.log("Made ingress")
console.log("Kind:", kind)
switch (manifest.kind) {
case 'Deployment':
return createResource(appsV1Api, 'Deployment', manifest);
case 'Service':
return createResource(coreV1Api, 'Service', manifest);
case 'Ingress':
return createResource(networkingV1Api, 'Ingress', manifest);
default:
console.error("Unsupported kind:", manifest.kind);
return Promise.reject("Unsupported kind: " + manifest.kind);
}
})

View File

@ -22,6 +22,10 @@ const getSandboxData = async (id: string) => {
};
const getSharedUsers = async (usersToSandboxes: UsersToSandboxes[]) => {
if (!usersToSandboxes) {
return [];
}
const shared = await Promise.all(
usersToSandboxes.map(async (user) => {
const userRes = await fetch(

View File

@ -19,6 +19,7 @@ export default function Editor({
userData: User;
sandboxData: Sandbox;
}) {
console.log("userData", userData);
const [isServerRunning, setIsServerRunning] = useState(false);
const [didFail, setDidFail] = useState(false);