Skip to content

Commit 7a1f293

Browse files
author
wlanboy
committed
full context
1 parent 3b4e814 commit 7a1f293

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

src/main/resources/static/js/k8s-client.js

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* k8s-client.js
3-
* Fokus auf Envoy-Status und Pod-Kontext.
3+
* Fokus auf Tab C: Dynamische Anzeige des Pod-Kontexts
44
*/
55
const K8sClient = (() => {
66

@@ -19,57 +19,58 @@ const K8sClient = (() => {
1919
runFullDiagnostics: async (targetUrl) => {
2020
const configDiv = document.getElementById('configDisplay');
2121
const errorDiv = document.getElementById('errorDisplay');
22-
const resourceDiv = document.getElementById('resourceDisplay'); // Jetzt Context-Display
22+
const resourceDiv = document.getElementById('resourceDisplay');
2323

2424
const spinner = '<div class="text-center p-4"><div class="spinner-border text-info"></div></div>';
2525
[configDiv, errorDiv, resourceDiv].forEach(el => { if (el) el.innerHTML = spinner; });
2626

2727
try {
28-
// 1. Daten parallel abrufen
28+
// 1. Daten laden
2929
const [report, context] = await Promise.all([
3030
apiFetch('/api/k8s/istio/full-report'),
3131
K8sClient.loadContext()
3232
]);
3333

34-
if (report.error) throw new Error(report.error);
34+
// --- TAB A & B (Envoy Config & Errors) ---
35+
// Hier bleibt deine bestehende Rendering-Logik für report.reachability und report.healthDiagnostics
36+
configDiv.innerHTML = `<pre class="console x-small p-2 bg-dark text-success">${report.reachability.activeEndpoints}</pre>`;
3537

36-
// --- TAB A: ENVOY CONFIG ---
37-
configDiv.innerHTML = `
38-
<div class="mb-3">
39-
<label class="fw-bold small text-muted">ENVOY CLUSTERS:</label>
40-
<pre class="console x-small p-2" style="max-height: 250px; overflow:auto; background: #1a1a1a; color: #00ff41;">${report.reachability.activeEndpoints}</pre>
41-
<div class="badge bg-primary mt-1">${report.reachability.summary}</div>
42-
</div>
43-
<button class="btn btn-xs btn-outline-secondary" onclick="this.nextElementSibling.classList.toggle('d-none')">Raw JSON anzeigen</button>
44-
<pre class="console x-small d-none mt-2 bg-light p-2 border">${JSON.stringify(report.reachability.envoyConfig, null, 2)}</pre>`;
45-
46-
// --- TAB B: ACTIVE ERRORS ---
4738
const errorEntries = Object.entries(report.healthDiagnostics.activeErrorMetrics);
4839
errorDiv.innerHTML = errorEntries.length === 0 ?
49-
`<div class="alert alert-success mt-2 small">Keine aktiven Netzwerkfehler im Proxy.</div>` :
50-
`<table class="table table-sm table-hover small mt-2">
51-
<thead class="table-dark"><tr><th>Metrik</th><th class="text-end">Wert</th></tr></thead>
52-
<tbody>${errorEntries.map(([k, v]) => `<tr><td class="x-small font-monospace">${k}</td><td class="text-end text-danger fw-bold">${v}</td></tr>`).join('')}</tbody>
53-
</table>`;
40+
`<div class="alert alert-success small">Keine Fehler.</div>` :
41+
`<table class="table table-sm small">${errorEntries.map(([k, v]) => `<tr><td>${k}</td><td>${v}</td></tr>`).join('')}</table>`;
42+
43+
44+
// --- TAB C: POD KONTEXT (Dynamisch) ---
45+
// Wir iterieren über alle Keys im Context-Response
46+
const contextRows = Object.entries(context).map(([key, val]) => {
47+
let badgeClass = "bg-light text-dark border";
48+
if (val === true) badgeClass = "bg-success text-white";
49+
if (val === false) badgeClass = "bg-danger text-white";
50+
51+
return `
52+
<tr>
53+
<td class="bg-light fw-bold small text-muted w-25">${key}</td>
54+
<td><span class="badge ${badgeClass} font-monospace">${val}</span></td>
55+
</tr>`;
56+
}).join('');
5457

55-
// --- TAB C: K8S CONTEXT (ERSETZT RESSOURCEN) ---
5658
resourceDiv.innerHTML = `
5759
<div class="p-2">
58-
<h6 class="x-small fw-bold text-uppercase text-muted border-bottom pb-2 mb-3">Pod Identität & Umgebung</h6>
60+
<div class="d-flex justify-content-between align-items-center border-bottom pb-2 mb-3">
61+
<h6 class="x-small fw-bold text-uppercase text-muted mb-0">Identität & Kontext</h6>
62+
<button class="btn btn-xs btn-outline-primary" onclick="this.parentElement.nextElementSibling.nextElementSibling.classList.toggle('d-none')">
63+
<i class="bi bi-eye me-1"></i> Details (JSON)
64+
</button>
65+
</div>
66+
5967
<table class="table table-sm border shadow-sm">
60-
<tbody>
61-
<tr><td class="bg-light fw-bold small" style="width: 30%;">Pod Name</td><td class="font-monospace small">${context.podName || 'unbekannt'}</td></tr>
62-
<tr><td class="bg-light fw-bold small">Namespace</td><td><span class="badge bg-dark">${context.namespace}</span></td></tr>
63-
<tr><td class="bg-light fw-bold small">Istio Sidecar</td><td>
64-
<span class="badge ${context.istioSidecar ? 'bg-success' : 'bg-danger'}">
65-
${context.istioSidecar ? 'ACTIVE' : 'INACTIVE'}
66-
</span>
67-
</td></tr>
68-
<tr><td class="bg-light fw-bold small">Status Zeit</td><td class="text-muted small">${new Date().toLocaleString()}</td></tr>
69-
</tbody>
68+
<tbody>${contextRows}</tbody>
7069
</table>
71-
<div class="alert alert-secondary x-small mt-3">
72-
<i class="bi bi-info-circle me-1"></i> Dieser Kontext wird direkt aus dem Service-Account Token und Umgebungsvariablen des laufenden Containers gelesen.
70+
71+
<div class="d-none mt-3">
72+
<label class="x-small fw-bold text-muted">RAW CONTEXT RESPONSE:</label>
73+
<pre class="console x-small bg-light p-3 border">${JSON.stringify(context, null, 4)}</pre>
7374
</div>
7475
</div>`;
7576

@@ -82,13 +83,13 @@ const K8sClient = (() => {
8283
})();
8384

8485
/**
85-
* Event Listener Initialisierung
86+
* Event Listener
8687
*/
8788
document.addEventListener('DOMContentLoaded', async () => {
8889
const contextEl = document.getElementById('k8sContext');
8990
const diagnoseBtn = document.getElementById('k8sDiagnoseBtn');
9091

91-
// Navbar initial füllen
92+
// Navbar füllen
9293
const ctx = await K8sClient.loadContext();
9394
if (contextEl && !ctx.error) {
9495
contextEl.innerHTML = `
@@ -99,15 +100,11 @@ document.addEventListener('DOMContentLoaded', async () => {
99100
if (diagnoseBtn) {
100101
diagnoseBtn.addEventListener('click', () => {
101102
const currentUrl = document.getElementById('url').value;
102-
if (!currentUrl) {
103-
alert("Bitte eine URL eingeben.");
104-
return;
105-
}
103+
if (!currentUrl) return alert("Bitte URL eingeben.");
106104

107105
document.getElementById('resultArea').style.display = 'block';
108106
document.getElementById('istioPanel').style.display = 'block';
109107

110-
// Immer zum ersten Tab (Config) springen beim Klick
111108
const firstTab = document.querySelector('#config-tab');
112109
if (firstTab) firstTab.click();
113110

0 commit comments

Comments
 (0)