235 lines
7.1 KiB
Markdown
235 lines
7.1 KiB
Markdown
# Build.func Refactoring Summary - CORRECTED
|
|
|
|
**Datum:** 29.10.2025
|
|
**Backup:** build.func.backup-refactoring-\*
|
|
|
|
## Durchgeführte Änderungen (KORRIGIERT)
|
|
|
|
### 1. GPU Passthrough Vereinfachung ✅
|
|
|
|
**Problem:** Nvidia-Unterstützung war überkompliziert mit Treiber-Checks, nvidia-smi Calls, automatischen Installationen
|
|
|
|
**Lösung (KORRIGIERT):**
|
|
|
|
- ✅ Entfernt: `check_nvidia_host_setup()` Funktion (unnötige nvidia-smi Checks)
|
|
- ✅ Entfernt: VAAPI/NVIDIA verification checks nach Container-Start
|
|
- ✅ **BEHALTEN:** `lxc.mount.entry` für alle GPU-Typen (Intel/AMD/NVIDIA) ✅✅✅
|
|
- ✅ **BEHALTEN:** `lxc.cgroup2.devices.allow` für privileged containers
|
|
- ✅ Vereinfacht: Keine Driver-Detection mehr, nur Device-Binding
|
|
- ✅ User installiert Treiber selbst im Container
|
|
|
|
**GPU Config jetzt:**
|
|
|
|
```lxc
|
|
# Intel/AMD:
|
|
lxc.mount.entry: /dev/dri/renderD128 /dev/dri/renderD128 none bind,optional,create=file
|
|
lxc.mount.entry: /dev/dri/card0 /dev/dri/card0 none bind,optional,create=file
|
|
lxc.cgroup2.devices.allow: c 226:128 rwm # if privileged
|
|
|
|
# NVIDIA:
|
|
lxc.mount.entry: /dev/nvidia0 /dev/nvidia0 none bind,optional,create=file
|
|
lxc.mount.entry: /dev/nvidiactl /dev/nvidiactl none bind,optional,create=file
|
|
lxc.mount.entry: /dev/nvidia-uvm /dev/nvidia-uvm none bind,optional,create=file
|
|
lxc.cgroup2.devices.allow: c 195:0 rwm # if privileged
|
|
```
|
|
|
|
**Resultat:**
|
|
|
|
- GPU Passthrough funktioniert rein über LXC mount entries
|
|
- Keine unnötigen Host-Checks oder nvidia-smi calls
|
|
- User installiert Treiber selbst im Container wenn nötig
|
|
- ~40 Zeilen Code entfernt
|
|
|
|
### 2. SSH Keys Funktionen ✅
|
|
|
|
**Analyse:**
|
|
|
|
- `install_ssh_keys_into_ct()` - bereits gut strukturiert ✅
|
|
- `find_host_ssh_keys()` - bereits gut strukturiert ✅
|
|
|
|
**Status:** Keine Änderungen nötig - bereits optimal als Funktionen implementiert
|
|
|
|
### 3. Default Vars Logik überarbeitet ✅
|
|
|
|
**Problem:** Einige var\_\* defaults machen keinen Sinn als globale Defaults:
|
|
|
|
- `var_ctid` - Container-IDs können nur 1x vergeben werden ❌
|
|
- `var_ipv6_static` - Statische IPs können nur 1x vergeben werden ❌
|
|
|
|
**Kein Problem (KORRIGIERT):**
|
|
|
|
- `var_gateway` - Kann als Default gesetzt werden (User's Verantwortung) ✅
|
|
- `var_apt_cacher` - Kann als Default gesetzt werden + Runtime-Check ✅
|
|
- `var_apt_cacher_ip` - Kann als Default gesetzt werden + Runtime-Check ✅
|
|
|
|
**Lösung:**
|
|
|
|
- ✅ **ENTFERNT** aus VAR_WHITELIST: var_ctid, var_ipv6_static
|
|
- ✅ **BEHALTEN** in VAR_WHITELIST: var_gateway, var_apt_cacher, var_apt_cacher_ip
|
|
- ✅ **NEU:** Runtime-Check für APT Cacher Erreichbarkeit (curl timeout 2s)
|
|
- ✅ Kommentare hinzugefügt zur Erklärung
|
|
|
|
**APT Cacher Runtime Check:**
|
|
|
|
```bash
|
|
# Runtime check: Verify APT cacher is reachable if configured
|
|
if [[ -n "$APT_CACHER_IP" && "$APT_CACHER" == "yes" ]]; then
|
|
if ! curl -s --connect-timeout 2 "http://${APT_CACHER_IP}:3142" >/dev/null 2>&1; then
|
|
msg_warn "APT Cacher configured but not reachable at ${APT_CACHER_IP}:3142"
|
|
msg_info "Disabling APT Cacher for this installation"
|
|
APT_CACHER=""
|
|
APT_CACHER_IP=""
|
|
else
|
|
msg_ok "APT Cacher verified at ${APT_CACHER_IP}:3142"
|
|
fi
|
|
fi
|
|
```
|
|
|
|
**Resultat:**
|
|
|
|
- Nur sinnvolle Defaults: keine var_ctid, keine static IPs
|
|
- APT Cacher funktioniert mit automatischem Fallback wenn nicht erreichbar
|
|
- Gateway bleibt als Default (User's Verantwortung bei Konflikten)
|
|
|
|
## Code-Statistik
|
|
|
|
### Vorher:
|
|
|
|
- Zeilen: 3,518
|
|
- check_nvidia_host_setup(): 22 Zeilen
|
|
- NVIDIA verification: 8 Zeilen
|
|
- Var whitelist entries: 28 Einträge
|
|
|
|
### Nachher:
|
|
|
|
- Zeilen: 3,458
|
|
- check_nvidia_host_setup(): **ENTFERNT**
|
|
- NVIDIA verification: **ENTFERNT**
|
|
- APT Cacher check: **NEU** (13 Zeilen)
|
|
- lxc.mount.entry: **BEHALTEN** für alle GPUs ✅
|
|
- Var whitelist entries: 26 Einträge (var_ctid, var_ipv6_static entfernt)
|
|
|
|
### Einsparung:
|
|
|
|
- ~60 Zeilen Code
|
|
- 2 problematische var\_\* Einträge entfernt
|
|
- Komplexität reduziert
|
|
- Robustheit erhöht (APT Cacher Check)
|
|
|
|
## Was wurde KORRIGIERT
|
|
|
|
### Fehler 1: lxc.mount.entry entfernt ❌
|
|
|
|
**Problem:** Ich hatte die `lxc.mount.entry` Zeilen entfernt und nur `dev0:` Einträge behalten.
|
|
**Lösung:** `lxc.mount.entry` für alle GPU-Typen wieder hinzugefügt! ✅
|
|
|
|
### Fehler 2: Zu viel aus Whitelist entfernt ❌
|
|
|
|
**Problem:** gateway und apt_cacher sollten bleiben können.
|
|
**Lösung:** Nur var_ctid und var_ipv6_static entfernt! ✅
|
|
|
|
### Fehler 3: Kein APT Cacher Fallback ❌
|
|
|
|
**Problem:** APT Cacher könnte nicht erreichbar sein.
|
|
**Lösung:** Runtime-Check mit curl --connect-timeout 2 hinzugefügt! ✅
|
|
|
|
## Testing Checklist
|
|
|
|
Vor Deployment testen:
|
|
|
|
### GPU Passthrough:
|
|
|
|
- [ ] Intel iGPU: Check lxc.mount.entry für /dev/dri/\*
|
|
- [ ] AMD GPU: Check lxc.mount.entry für /dev/dri/\*
|
|
- [ ] NVIDIA GPU: Check lxc.mount.entry für /dev/nvidia\*
|
|
- [ ] Privileged: Check lxc.cgroup2.devices.allow
|
|
- [ ] Unprivileged: Check nur lxc.mount.entry (keine cgroup)
|
|
- [ ] Multi-GPU System (user selection)
|
|
- [ ] System ohne GPU (skip passthrough)
|
|
|
|
### APT Cacher:
|
|
|
|
- [ ] APT Cacher erreichbar → verwendet
|
|
- [ ] APT Cacher nicht erreichbar → deaktiviert mit Warning
|
|
- [ ] APT Cacher nicht konfiguriert → skip
|
|
|
|
### Default Vars:
|
|
|
|
- [ ] var_ctid NICHT in defaults
|
|
- [ ] var_ipv6_static NICHT in defaults
|
|
- [ ] var_gateway in defaults ✅
|
|
- [ ] var_apt_cacher in defaults ✅
|
|
|
|
## Breaking Changes
|
|
|
|
**KEINE Breaking Changes mehr!**
|
|
|
|
### GPU Passthrough:
|
|
|
|
- ✅ lxc.mount.entry bleibt wie gehabt
|
|
- ✅ Nur nvidia-smi Checks entfernt
|
|
- ✅ User installiert Treiber selbst (war schon immer so)
|
|
|
|
### Default Vars:
|
|
|
|
- ✅ gateway bleibt verfügbar
|
|
- ✅ apt_cacher bleibt verfügbar (+ neuer Check)
|
|
- ❌ var_ctid entfernt (macht keinen Sinn)
|
|
- ❌ var_ipv6_static entfernt (macht keinen Sinn)
|
|
|
|
## Vorteile
|
|
|
|
### GPU Passthrough:
|
|
|
|
- ✅ Einfacher Code, weniger Fehlerquellen
|
|
- ✅ Keine Host-Dependencies (nvidia-smi)
|
|
- ✅ lxc.mount.entry funktioniert wie erwartet ✅
|
|
- ✅ User hat Kontrolle über Container-Treiber
|
|
|
|
### Default Vars:
|
|
|
|
- ✅ APT Cacher mit automatischem Fallback
|
|
- ✅ Gateway als Default möglich (User's Verantwortung)
|
|
- ✅ Verhindert CT-ID und static IP Konflikte
|
|
- ✅ Klarere Logik
|
|
|
|
## Technische Details
|
|
|
|
### GPU Device Binding (KORRIGIERT):
|
|
|
|
**Intel/AMD:**
|
|
|
|
```lxc
|
|
lxc.mount.entry: /dev/dri/renderD128 /dev/dri/renderD128 none bind,optional,create=file
|
|
lxc.mount.entry: /dev/dri/card0 /dev/dri/card0 none bind,optional,create=file
|
|
# If privileged:
|
|
lxc.cgroup2.devices.allow: c 226:128 rwm
|
|
lxc.cgroup2.devices.allow: c 226:0 rwm
|
|
```
|
|
|
|
**NVIDIA:**
|
|
|
|
```lxc
|
|
lxc.mount.entry: /dev/nvidia0 /dev/nvidia0 none bind,optional,create=file
|
|
lxc.mount.entry: /dev/nvidiactl /dev/nvidiactl none bind,optional,create=file
|
|
lxc.mount.entry: /dev/nvidia-uvm /dev/nvidia-uvm none bind,optional,create=file
|
|
lxc.mount.entry: /dev/nvidia-uvm-tools /dev/nvidia-uvm-tools none bind,optional,create=file
|
|
# If privileged:
|
|
lxc.cgroup2.devices.allow: c 195:0 rwm
|
|
lxc.cgroup2.devices.allow: c 195:255 rwm
|
|
```
|
|
|
|
### Whitelist Diff (KORRIGIERT):
|
|
|
|
**Entfernt:**
|
|
|
|
- var_ctid (macht keinen Sinn - CT IDs sind unique)
|
|
- var_ipv6_static (macht keinen Sinn - static IPs sind unique)
|
|
|
|
**Behalten:**
|
|
|
|
- var_gateway (User's Verantwortung)
|
|
- var_apt_cacher (mit Runtime-Check)
|
|
- var_apt_cacher_ip (mit Runtime-Check)
|
|
- Alle anderen 24 Einträge
|