-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CreateServiceForm, refactor Service
update deps
- Loading branch information
Showing
12 changed files
with
795 additions
and
264 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { createServerAction$, redirect } from "solid-start/server"; | ||
import { k8sCustomObjects } from "~/k8s"; | ||
|
||
export const CreateServiceForm = () => { | ||
const [enrolling, { Form }] = createServerAction$( | ||
async (form: FormData, { request }) => { | ||
const service = { | ||
name: form.get("name") as string, | ||
image: form.get("image") as string, | ||
port: Number(form.get("port")) as number, | ||
}; | ||
|
||
const { body } = await k8sCustomObjects.createNamespacedCustomObject( | ||
"serving.knative.dev", | ||
"v1", | ||
"adb-sh", | ||
"services", | ||
{ | ||
"apiVersion": "serving.knative.dev/v1", | ||
"kind": "Service", | ||
"metadata": { | ||
"name": service.name, | ||
"namespace": "adb-sh", | ||
}, | ||
"spec": { | ||
"template": { | ||
"metadata": { | ||
"annotations": { | ||
//"autoscaling.knative.dev/min-scale": "1", | ||
}, | ||
}, | ||
"spec": { | ||
"containerConcurrency": 0, | ||
"containers": [ | ||
{ | ||
"image": service.image, | ||
"name": "user-container", | ||
"ports": [ | ||
{ | ||
"containerPort": service.port, | ||
"protocol": "TCP", | ||
}, | ||
], | ||
"readinessProbe": { | ||
"successThreshold": 1, | ||
"tcpSocket": { | ||
"port": 0, | ||
}, | ||
}, | ||
"resources": {}, | ||
}, | ||
], | ||
"enableServiceLinks": false, | ||
"timeoutSeconds": 300, | ||
}, | ||
}, | ||
}, | ||
}, | ||
); | ||
}, | ||
); | ||
|
||
return ( | ||
<figure class="absolute top-8 left-1/2 -translate-x-1/2 w-128 m-3"> | ||
<div class="overflow-y-auto rounded-xl bg-gray-50 dark:bg-gray-800 drop-shadow-2xl p-6"> | ||
<h2 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white"> | ||
Create Service | ||
</h2> | ||
<Form> | ||
<div class="mb-6"> | ||
<label | ||
for="name" | ||
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" | ||
> | ||
Name | ||
</label> | ||
<input | ||
type="text" | ||
name="name" | ||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" | ||
required | ||
/> | ||
</div> | ||
<div class="mb-6"> | ||
<label | ||
for="image" | ||
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" | ||
> | ||
Image | ||
</label> | ||
<input | ||
type="text" | ||
name="image" | ||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" | ||
required | ||
/> | ||
</div> | ||
<div class="mb-6"> | ||
<label | ||
for="port" | ||
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" | ||
> | ||
Container Port | ||
</label> | ||
<input | ||
type="number" | ||
name="port" | ||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" | ||
required | ||
/> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Deploy</button> | ||
</Form> | ||
|
||
<div class="inline-flex items-center justify-center w-full"> | ||
<hr class="w-64 h-px my-8 bg-gray-200 border-0 dark:bg-gray-700" /> | ||
<span class="absolute px-3 font-medium text-gray-900 -translate-x-1/2 bg-white left-1/2 dark:text-white dark:bg-gray-800"> | ||
or | ||
</span> | ||
</div> | ||
<h3 class="mb-2 text-xl font-bold tracking-tight text-gray-900 dark:text-white"> | ||
Add via cli | ||
</h3> | ||
<ol class="list-decimal ml-6"> | ||
<li> | ||
<code class="bg-slate-600 px-1 rounded"> | ||
npx @deploycat/cli service create my-app | ||
</code> | ||
</li> | ||
</ol> | ||
</div> | ||
</figure> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { For } from "solid-js"; | ||
import { createServerAction$ } from "solid-start/server"; | ||
import { Status } from "./Status"; | ||
import { k8sCustomObjects } from "~/k8s"; | ||
import { TrashIcon } from "@deploy-cat/heroicons-solid/24/solid/esm"; | ||
|
||
export const Service = ({ service }) => { | ||
const [deleting, { Form }] = createServerAction$( | ||
async (form: FormData, { request }) => { | ||
const service = { | ||
name: form.get("name") as string, | ||
}; | ||
|
||
const { body } = await k8sCustomObjects.deleteNamespacedCustomObject( | ||
"serving.knative.dev", | ||
"v1", | ||
"adb-sh", | ||
"services", | ||
service.name, | ||
); | ||
}, | ||
); | ||
|
||
return ( | ||
<figure class="card relative basis-64 grow p-6 m-3 hover:drop-shadow-md transition-all duration-100"> | ||
<h2 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white"> | ||
{service.metadata.name} | ||
</h2> | ||
<div class="absolute top-4 right-4"> | ||
<Form> | ||
<input type="hidden" name="name" value={service.metadata.name} /> | ||
<button type="submit" disabled={deleting.pending}> | ||
<TrashIcon class="flex-shrink-0 w-5 h-5 text-gray-500 hover:text-red-500 transition duration-75 dark:text-gray-400 dark:hover:text-red-800" /> | ||
</button> | ||
</Form> | ||
</div> | ||
<p class="font-normal text-gray-700 dark:text-gray-400 my-1"> | ||
<For each={service.spec.template.spec.containers}> | ||
{(container) => <span>{container.image}</span>} | ||
</For> | ||
</p> | ||
<p class="font-normal text-gray-700 dark:text-gray-400 my-1"> | ||
<a | ||
class="text-sky-400" | ||
href={service.status.url} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{service.status.url} | ||
</a> | ||
</p> | ||
<p class="font-bold text-sm text-gray-700 dark:text-gray-400 my-1"> | ||
<Show | ||
when={service.status.conditions?.length} | ||
fallback={<span>n/a/</span>} | ||
> | ||
<Status conditions={service.status.conditions} /> | ||
</Show> | ||
</p> | ||
</figure> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { For, Show } from "solid-js"; | ||
|
||
export const Status = ({ conditions }) => ( | ||
<div class="flex"> | ||
<For each={conditions}> | ||
{(condition) => ( | ||
<figure class="flex items-center mr-4"> | ||
<symbol | ||
class={`status inline-flex items-center justify-center w-2 h-2 mr-2 rounded`} | ||
classList={{ | ||
ready: condition.status === "True", | ||
}} | ||
/> | ||
<span class="font-normal text-sm text-gray-700 dark:text-gray-400"> | ||
{condition.type} | ||
<Show when={condition.reason}>{" "}({condition.reason})</Show> | ||
</span> | ||
</figure> | ||
)} | ||
</For> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.