working version, fixed local docker compose
This commit is contained in:
parent
9e0d7d0726
commit
b98d75cede
30
app.py
30
app.py
|
|
@ -1,8 +1,20 @@
|
||||||
import os
|
import os
|
||||||
|
import configparser
|
||||||
from flask import Flask, jsonify, render_template
|
from flask import Flask, jsonify, render_template
|
||||||
from kubernetes import client, config
|
from kubernetes import client, config
|
||||||
from kubernetes.client.rest import ApiException
|
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__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
def get_k8s_client():
|
def get_k8s_client():
|
||||||
|
|
@ -13,10 +25,16 @@ def get_k8s_client():
|
||||||
config.load_kube_config()
|
config.load_kube_config()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error loading kubeconfig: {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:
|
try:
|
||||||
config.load_kube_config(config_file="/root/.kube/config")
|
if os.path.exists(fallback_path):
|
||||||
except Exception as e2:
|
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}")
|
raise RuntimeError(f"Failed to load kubeconfig. Make sure the file exists and is accessible. Error: {e}")
|
||||||
return client.CoreV1Api(), client.CustomObjectsApi()
|
return client.CoreV1Api(), client.CustomObjectsApi()
|
||||||
|
|
||||||
|
|
@ -157,9 +175,13 @@ def cluster_data():
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
@app.route('/api/version')
|
||||||
|
def version_route():
|
||||||
|
return jsonify({"version": get_version()})
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
return render_template('index.html', version=get_version())
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5000)
|
app.run(host='0.0.0.0', port=5000)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "5000:5000"
|
||||||
environment:
|
environment:
|
||||||
- KUBECONFIG=/root/.kube/config
|
- KUBECONFIG=/home/nonroot/.kube/config
|
||||||
volumes:
|
volumes:
|
||||||
- ${KUBECONFIG:-~/.kube/config}:/root/.kube/config:ro
|
- ${KUBECONFIG:-~/.kube/config}:/home/nonroot/.kube/config:ro
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 159 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -64,6 +64,12 @@ body {
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.logo-icon {
|
||||||
|
height: 32px;
|
||||||
|
width: auto;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
.logo h1 {
|
.logo h1 {
|
||||||
font-size: 1.25rem;
|
font-size: 1.25rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
|
@ -224,7 +230,7 @@ body {
|
||||||
|
|
||||||
.legend-panel {
|
.legend-panel {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 1rem;
|
bottom: 3.25rem;
|
||||||
right: 1rem;
|
right: 1rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
@ -235,6 +241,19 @@ body {
|
||||||
pointer-events: none;
|
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 {
|
.legend-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,7 @@
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<header class="glass-panel header">
|
<header class="glass-panel header">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<img src="/static/k8spulselogo-sm.png" alt="K8s Pulse Logo" class="logo-icon">
|
||||||
<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>
|
|
||||||
<h1>K8s Pulse <span class="badge-3d">3D</span></h1>
|
<h1>K8s Pulse <span class="badge-3d">3D</span></h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
|
@ -72,6 +68,11 @@
|
||||||
<div class="legend-divider"></div>
|
<div class="legend-divider"></div>
|
||||||
<div class="legend-note">📐 <strong>Tower Height</strong> = Resource Usage</div>
|
<div class="legend-note">📐 <strong>Tower Height</strong> = Resource Usage</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Version Footer Overlay -->
|
||||||
|
<div class="version-overlay glass-panel">
|
||||||
|
<span>v: {{ version }}</span>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue