working version, fixed local docker compose

This commit is contained in:
Isaac Johnson 2026-07-24 08:20:03 -05:00
parent 9e0d7d0726
commit b98d75cede
6 changed files with 55 additions and 13 deletions

30
app.py
View File

@ -1,8 +1,20 @@
import os
import configparser
from flask import Flask, jsonify, render_template
from kubernetes import client, config
from kubernetes.client.rest import ApiException
def get_version():
try:
ini_path = os.path.join(os.path.dirname(__file__), 'version.ini')
if os.path.exists(ini_path):
parser = configparser.ConfigParser()
parser.read(ini_path)
return parser.get('metadata', 'version', fallback='0.5')
except Exception as e:
print(f"Error reading version.ini: {e}")
return '0.5'
app = Flask(__name__)
def get_k8s_client():
@ -13,10 +25,16 @@ def get_k8s_client():
config.load_kube_config()
except Exception as e:
print(f"Error loading kubeconfig: {e}")
# Try a fallback if they mounted to /root/.kube/config but KUBECONFIG is wrong
loaded = False
for fallback_path in ["/home/nonroot/.kube/config", "/root/.kube/config"]:
try:
config.load_kube_config(config_file="/root/.kube/config")
except Exception as e2:
if os.path.exists(fallback_path):
config.load_kube_config(config_file=fallback_path)
loaded = True
break
except Exception:
pass
if not loaded:
raise RuntimeError(f"Failed to load kubeconfig. Make sure the file exists and is accessible. Error: {e}")
return client.CoreV1Api(), client.CustomObjectsApi()
@ -157,9 +175,13 @@ def cluster_data():
traceback.print_exc()
return jsonify({"error": str(e)}), 500
@app.route('/api/version')
def version_route():
return jsonify({"version": get_version()})
@app.route('/')
def index():
return render_template('index.html')
return render_template('index.html', version=get_version())
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

View File

@ -7,7 +7,7 @@ services:
ports:
- "5000:5000"
environment:
- KUBECONFIG=/root/.kube/config
- KUBECONFIG=/home/nonroot/.kube/config
volumes:
- ${KUBECONFIG:-~/.kube/config}:/root/.kube/config:ro
- ${KUBECONFIG:-~/.kube/config}:/home/nonroot/.kube/config:ro
restart: unless-stopped

BIN
static/k8spulselogo-lg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

BIN
static/k8spulselogo-sm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -64,6 +64,12 @@ body {
color: var(--accent);
}
.logo-icon {
height: 32px;
width: auto;
object-fit: contain;
}
.logo h1 {
font-size: 1.25rem;
font-weight: 700;
@ -224,7 +230,7 @@ body {
.legend-panel {
position: absolute;
bottom: 1rem;
bottom: 3.25rem;
right: 1rem;
display: flex;
flex-direction: column;
@ -235,6 +241,19 @@ body {
pointer-events: none;
}
.version-overlay {
position: absolute;
bottom: 1rem;
right: 1rem;
padding: 0.35rem 0.75rem;
font-size: 0.75rem;
font-weight: 600;
color: var(--text-muted);
z-index: 10;
pointer-events: none;
letter-spacing: 0.05em;
}
.legend-item {
display: flex;
align-items: center;

View File

@ -18,11 +18,7 @@
<div class="app-container">
<header class="glass-panel header">
<div class="logo">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2L2 7L12 12L22 7L12 2Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 17L12 22L22 17" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 12L12 17L22 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<img src="/static/k8spulselogo-sm.png" alt="K8s Pulse Logo" class="logo-icon">
<h1>K8s Pulse <span class="badge-3d">3D</span></h1>
</div>
<div class="controls">
@ -72,6 +68,11 @@
<div class="legend-divider"></div>
<div class="legend-note">📐 <strong>Tower Height</strong> = Resource Usage</div>
</div>
<!-- Version Footer Overlay -->
<div class="version-overlay glass-panel">
<span>v: {{ version }}</span>
</div>
</main>
</div>