feat: deliver fission console UI, k8s deploy, and tests
This commit is contained in:
+445
-12
@@ -47,6 +47,20 @@
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: .6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn.danger {
|
||||
background: #b43232;
|
||||
}
|
||||
|
||||
.btn.ghost {
|
||||
background: #0c2b49;
|
||||
}
|
||||
|
||||
.wrap {
|
||||
@@ -90,6 +104,14 @@
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
@@ -108,12 +130,124 @@
|
||||
font-size: 12px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-top: 10px;
|
||||
padding: 9px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
background: #0c2b49;
|
||||
border: 1px solid #1d486d;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.status.ok {
|
||||
background: #103625;
|
||||
border-color: #236843;
|
||||
}
|
||||
|
||||
.status.err {
|
||||
background: #411d1d;
|
||||
border-color: #7a2f2f;
|
||||
}
|
||||
|
||||
.chip {
|
||||
display: inline-block;
|
||||
padding: 2px 7px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid #1d486d;
|
||||
background: #0c2b49;
|
||||
font-size: 11px;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.modal {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,.45);
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.modal.open { display: flex; }
|
||||
|
||||
.panel {
|
||||
width: min(820px, 100%);
|
||||
max-height: 90vh;
|
||||
overflow: auto;
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.panel h3 {
|
||||
margin-bottom: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.field {
|
||||
flex: 1;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
input, select, textarea {
|
||||
width: 100%;
|
||||
border: 1px solid #1d486d;
|
||||
background: #03192c;
|
||||
color: var(--text-primary);
|
||||
border-radius: 6px;
|
||||
padding: 8px 10px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
min-height: 220px;
|
||||
resize: vertical;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
margin-top: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.nowrap {
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar">
|
||||
<div class="title">sless / Fission Console</div>
|
||||
<button class="btn" onclick="reloadAll()">Refresh</button>
|
||||
<div class="row" style="margin:0;">
|
||||
<button class="btn ghost" onclick="reloadAll()">Refresh</button>
|
||||
<button class="btn" onclick="openCreate()">+ Create Function</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wrap">
|
||||
@@ -126,40 +260,319 @@
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<div style="font-weight:600;">Functions (MVP list)</div>
|
||||
<div class="toolbar">
|
||||
<div style="font-weight:600;">Functions</div>
|
||||
<div class="hint">Actions: view, edit code, invoke, delete</div>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>Name</th><th>Environment</th><th>Package</th></tr>
|
||||
<tr><th>Name</th><th>Environment</th><th>Package</th><th>Route</th><th>Methods</th><th class="nowrap">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody id="fn-rows"></tbody>
|
||||
</table>
|
||||
<div class="hint">Initial MVP. Next step: create/edit/invoke/delete.</div>
|
||||
<div id="status" class="status"></div>
|
||||
<div class="hint">Namespace: default. CRUD происходит напрямую через CRD Fission.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="create-modal" class="modal">
|
||||
<div class="panel">
|
||||
<h3>Create Function</h3>
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label>Name</label>
|
||||
<input id="c-name" placeholder="demo-fn">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Environment</label>
|
||||
<select id="c-env"></select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Entrypoint</label>
|
||||
<input id="c-entry" value="main.main">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label>Route</label>
|
||||
<input id="c-route" placeholder="/demo-fn">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Methods (comma separated)</label>
|
||||
<input id="c-methods" value="GET">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Code</label>
|
||||
<textarea id="c-code">def main(ctx):
|
||||
return {"ok": True, "msg": "hello from fission console"}
|
||||
</textarea>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn ghost" onclick="closeCreate()">Cancel</button>
|
||||
<button id="c-submit" class="btn" onclick="submitCreate()">Create</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="edit-modal" class="modal">
|
||||
<div class="panel">
|
||||
<h3 id="e-title">Edit Code</h3>
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label>Name</label>
|
||||
<input id="e-name" disabled>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Environment</label>
|
||||
<input id="e-env" disabled>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Entrypoint</label>
|
||||
<input id="e-entry" disabled>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Code</label>
|
||||
<textarea id="e-code"></textarea>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn ghost" onclick="closeEdit()">Cancel</button>
|
||||
<button id="e-submit" class="btn" onclick="submitEdit()">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="invoke-modal" class="modal">
|
||||
<div class="panel">
|
||||
<h3 id="i-title">Invoke</h3>
|
||||
<div>
|
||||
<label>JSON payload</label>
|
||||
<textarea id="i-body">{"name":"world"}</textarea>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn ghost" onclick="closeInvoke()">Cancel</button>
|
||||
<button id="i-submit" class="btn" onclick="submitInvoke()">Invoke</button>
|
||||
</div>
|
||||
<div style="margin-top:10px;">
|
||||
<label>Response</label>
|
||||
<textarea id="i-resp" readonly style="min-height:160px;"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_BASE = window.location.pathname.startsWith('/console') ? '/console/api' : '/api';
|
||||
|
||||
const S = {
|
||||
envs: [],
|
||||
fns: [],
|
||||
triggers: [],
|
||||
currentEdit: null,
|
||||
currentInvoke: null
|
||||
};
|
||||
|
||||
async function getJSON(url) {
|
||||
const r = await fetch(url);
|
||||
if (!r.ok) {
|
||||
throw new Error(url + ': ' + r.status);
|
||||
let msg = '';
|
||||
try {
|
||||
const body = await r.json();
|
||||
msg = body.error || JSON.stringify(body);
|
||||
} catch (_) {
|
||||
msg = await r.text();
|
||||
}
|
||||
throw new Error(url + ': ' + r.status + (msg ? ' - ' + msg : ''));
|
||||
}
|
||||
return r.json();
|
||||
}
|
||||
|
||||
async function requestJSON(url, method, body) {
|
||||
const r = await fetch(url, {
|
||||
method: method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: body ? JSON.stringify(body) : undefined
|
||||
});
|
||||
let data = {};
|
||||
try { data = await r.json(); } catch (_) {}
|
||||
if (!r.ok) {
|
||||
throw new Error(data.error || (url + ': ' + r.status));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function setText(id, value) {
|
||||
document.getElementById(id).textContent = String(value);
|
||||
}
|
||||
|
||||
function showStatus(message, kind) {
|
||||
const el = document.getElementById('status');
|
||||
el.style.display = 'block';
|
||||
el.className = 'status ' + (kind || '');
|
||||
el.textContent = message;
|
||||
}
|
||||
|
||||
function clearStatus() {
|
||||
const el = document.getElementById('status');
|
||||
el.style.display = 'none';
|
||||
el.className = 'status';
|
||||
el.textContent = '';
|
||||
}
|
||||
|
||||
function parseMethods(v) {
|
||||
const items = String(v || '').split(',').map(s => s.trim().toUpperCase()).filter(Boolean);
|
||||
return items.length ? Array.from(new Set(items)) : ['GET'];
|
||||
}
|
||||
|
||||
function triggerByFn(fnName) {
|
||||
return (S.triggers || []).find(function (t) {
|
||||
return t.spec && t.spec.functionref && t.spec.functionref.name === fnName;
|
||||
});
|
||||
}
|
||||
|
||||
function h(v) {
|
||||
return String(v == null ? '' : v)
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll("'", ''');
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
const envSel = document.getElementById('c-env');
|
||||
envSel.innerHTML = (S.envs || []).map(function (e) {
|
||||
const n = (e.metadata && e.metadata.name) || '';
|
||||
return '<option value="' + h(n) + '">' + h(n) + '</option>';
|
||||
}).join('');
|
||||
document.getElementById('create-modal').classList.add('open');
|
||||
document.getElementById('c-name').focus();
|
||||
}
|
||||
|
||||
function closeCreate() {
|
||||
document.getElementById('create-modal').classList.remove('open');
|
||||
}
|
||||
|
||||
async function submitCreate() {
|
||||
const btn = document.getElementById('c-submit');
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const name = document.getElementById('c-name').value.trim();
|
||||
if (!name) throw new Error('name is required');
|
||||
const env = document.getElementById('c-env').value.trim();
|
||||
if (!env) throw new Error('environment is required');
|
||||
|
||||
await requestJSON(API_BASE + '/functions', 'POST', {
|
||||
name: name,
|
||||
environment: env,
|
||||
entrypoint: document.getElementById('c-entry').value.trim(),
|
||||
route: document.getElementById('c-route').value.trim(),
|
||||
methods: parseMethods(document.getElementById('c-methods').value),
|
||||
code: document.getElementById('c-code').value
|
||||
});
|
||||
|
||||
closeCreate();
|
||||
showStatus('Function created: ' + name, 'ok');
|
||||
await reloadAll();
|
||||
} catch (e) {
|
||||
showStatus('Create failed: ' + e.message, 'err');
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function openEdit(name) {
|
||||
try {
|
||||
const fn = await getJSON(API_BASE + '/functions/' + encodeURIComponent(name));
|
||||
S.currentEdit = fn;
|
||||
document.getElementById('e-title').textContent = 'Edit Code: ' + name;
|
||||
document.getElementById('e-name').value = name;
|
||||
document.getElementById('e-env').value = fn.environment || '';
|
||||
document.getElementById('e-entry').value = fn.entrypoint || '';
|
||||
document.getElementById('e-code').value = fn.code || '';
|
||||
document.getElementById('edit-modal').classList.add('open');
|
||||
} catch (e) {
|
||||
showStatus('Load function failed: ' + e.message, 'err');
|
||||
}
|
||||
}
|
||||
|
||||
function closeEdit() {
|
||||
document.getElementById('edit-modal').classList.remove('open');
|
||||
S.currentEdit = null;
|
||||
}
|
||||
|
||||
async function submitEdit() {
|
||||
if (!S.currentEdit) return;
|
||||
const btn = document.getElementById('e-submit');
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const name = S.currentEdit.name;
|
||||
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name) + '/code', 'PUT', {
|
||||
code: document.getElementById('e-code').value
|
||||
});
|
||||
closeEdit();
|
||||
showStatus('Code updated: ' + name, 'ok');
|
||||
} catch (e) {
|
||||
showStatus('Update failed: ' + e.message, 'err');
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openInvoke(name) {
|
||||
S.currentInvoke = name;
|
||||
document.getElementById('i-title').textContent = 'Invoke: ' + name;
|
||||
document.getElementById('i-resp').value = '';
|
||||
document.getElementById('invoke-modal').classList.add('open');
|
||||
}
|
||||
|
||||
function closeInvoke() {
|
||||
document.getElementById('invoke-modal').classList.remove('open');
|
||||
S.currentInvoke = null;
|
||||
}
|
||||
|
||||
async function submitInvoke() {
|
||||
if (!S.currentInvoke) return;
|
||||
const btn = document.getElementById('i-submit');
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const raw = document.getElementById('i-body').value.trim();
|
||||
let parsed = {};
|
||||
if (raw) parsed = JSON.parse(raw);
|
||||
const result = await requestJSON(API_BASE + '/functions/' + encodeURIComponent(S.currentInvoke) + '/invoke', 'POST', parsed);
|
||||
document.getElementById('i-resp').value = JSON.stringify(result, null, 2);
|
||||
} catch (e) {
|
||||
document.getElementById('i-resp').value = 'Invoke failed: ' + e.message;
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeFn(name) {
|
||||
if (!confirm('Delete function ' + name + '?')) return;
|
||||
try {
|
||||
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name), 'DELETE');
|
||||
showStatus('Function deleted: ' + name, 'ok');
|
||||
await reloadAll();
|
||||
} catch (e) {
|
||||
showStatus('Delete failed: ' + e.message, 'err');
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadAll() {
|
||||
try {
|
||||
const [envs, pkgs, fns, http, time] = await Promise.all([
|
||||
getJSON('/api/environments'),
|
||||
getJSON('/api/packages'),
|
||||
getJSON('/api/functions'),
|
||||
getJSON('/api/httptriggers'),
|
||||
getJSON('/api/timetriggers')
|
||||
getJSON(API_BASE + '/environments'),
|
||||
getJSON(API_BASE + '/packages'),
|
||||
getJSON(API_BASE + '/functions'),
|
||||
getJSON(API_BASE + '/httptriggers'),
|
||||
getJSON(API_BASE + '/timetriggers')
|
||||
]);
|
||||
|
||||
S.envs = envs || [];
|
||||
S.fns = fns || [];
|
||||
S.triggers = http || [];
|
||||
|
||||
setText('env-count', envs.length || 0);
|
||||
setText('pkg-count', pkgs.length || 0);
|
||||
setText('fn-count', fns.length || 0);
|
||||
@@ -171,12 +584,32 @@
|
||||
const env = (spec.environment && spec.environment.name) || '-';
|
||||
const pkg = (spec.package && spec.package.packageref && spec.package.packageref.name) || '-';
|
||||
const name = (f.metadata && f.metadata.name) || '-';
|
||||
return '<tr><td>' + name + '</td><td>' + env + '</td><td>' + pkg + '</td></tr>';
|
||||
const trig = triggerByFn(name) || {};
|
||||
const route = (trig.spec && trig.spec.relativeurl) || '-';
|
||||
const methods = (trig.spec && trig.spec.methods) || [];
|
||||
const chips = methods.map(function (m) { return '<span class="chip">' + h(m) + '</span>'; }).join('');
|
||||
const actions = [
|
||||
'<button class="btn ghost" onclick="openEdit(\'' + h(name) + '\')">Edit</button>',
|
||||
'<button class="btn ghost" onclick="openInvoke(\'' + h(name) + '\')">Invoke</button>',
|
||||
'<button class="btn danger" onclick="removeFn(\'' + h(name) + '\')">Delete</button>'
|
||||
].join(' ');
|
||||
return '<tr>' +
|
||||
'<td class="mono">' + h(name) + '</td>' +
|
||||
'<td>' + h(env) + '</td>' +
|
||||
'<td class="mono">' + h(pkg) + '</td>' +
|
||||
'<td class="mono">' + h(route) + '</td>' +
|
||||
'<td>' + chips + '</td>' +
|
||||
'<td class="nowrap">' + actions + '</td>' +
|
||||
'</tr>';
|
||||
}).join('');
|
||||
|
||||
document.getElementById('fn-rows').innerHTML = rows || '<tr><td colspan="3">No functions</td></tr>';
|
||||
if (!rows) {
|
||||
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="6">No functions</td></tr>';
|
||||
}
|
||||
} catch (e) {
|
||||
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="3">Load error: ' + e.message + '</td></tr>';
|
||||
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="6">Load error: ' + e.message + '</td></tr>';
|
||||
showStatus('Reload failed: ' + e.message, 'err');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user