- planification crontab par stack (autoupdate.json), incompatible avec l'exclusion
- scheduler a la minute ; pull puis down + up -d seulement si une image a change (mode autoapply)
- API PUT .../targets/{t}/auto et GET /api/cron (apercu des prochaines executions)
- interface : option dans le detail, badge sarcelle, vue de suivi "Mises a jour auto"
- TZ dans docker-compose / .env.example (tzdata embarque)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LNfwm6UCYFyvNQNSF5i9Gy
89 lines
2.2 KiB
Go
89 lines
2.2 KiB
Go
package fleet
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
// Exclusions : stacks que l'administrateur a retirées des mises à jour. Elles
|
|
// restent analysées et affichées, mais ne proposent plus de mise à jour et ne
|
|
// sont plus comptées comme « à mettre à jour ». Persistées dans excluded.json.
|
|
|
|
// ExclusionKey identifie une stack exclue : serveur, connexion et répertoire.
|
|
func ExclusionKey(serverID, targetID, dir string) string {
|
|
return Key(serverID, targetID) + ":" + dir
|
|
}
|
|
|
|
func (m *Manager) saveExclusionsLocked() error {
|
|
list := make([]string, 0, len(m.excluded))
|
|
for k := range m.excluded {
|
|
list = append(list, k)
|
|
}
|
|
sort.Strings(list)
|
|
return writeJSON(filepath.Join(m.dir, "excluded.json"), list)
|
|
}
|
|
|
|
// dropExclusionsLocked oublie les exclusions d'une connexion supprimée.
|
|
func (m *Manager) dropExclusionsLocked(targetKey string) {
|
|
m.dropAutoLocked(targetKey)
|
|
prefix := targetKey + ":"
|
|
n := len(m.excluded)
|
|
for k := range m.excluded {
|
|
if strings.HasPrefix(k, prefix) {
|
|
delete(m.excluded, k)
|
|
}
|
|
}
|
|
if len(m.excluded) != n {
|
|
if err := m.saveExclusionsLocked(); err != nil {
|
|
slog.Error("exclusions non enregistrées", "err", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// SetExcluded exclut une stack des mises à jour (on) ou la réactive (!on).
|
|
// L'exclusion d'une stack exige qu'elle soit connue d'une analyse ; la
|
|
// réactivation est toujours acceptée.
|
|
func (m *Manager) SetExcluded(serverID, targetID, dir string, on bool) error {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
if _, _, err := m.find(serverID, targetID); err != nil {
|
|
return err
|
|
}
|
|
key := ExclusionKey(serverID, targetID, dir)
|
|
if m.excluded[key] == on {
|
|
return nil
|
|
}
|
|
if on {
|
|
known := false
|
|
if sc := m.scans[Key(serverID, targetID)]; sc != nil {
|
|
for _, s := range sc.Stacks {
|
|
if s.Dir == dir {
|
|
known = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if !known {
|
|
return fmt.Errorf("%w : stack inconnue (lancer une analyse)", ErrNotFound)
|
|
}
|
|
m.excluded[key] = true
|
|
} else {
|
|
delete(m.excluded, key)
|
|
}
|
|
if err := m.saveExclusionsLocked(); err != nil {
|
|
if on {
|
|
delete(m.excluded, key)
|
|
} else {
|
|
m.excluded[key] = true
|
|
}
|
|
return err
|
|
}
|
|
if on { // exclusion et mise a jour auto sont incompatibles : l'exclusion l'emporte
|
|
m.unscheduleLocked(key)
|
|
}
|
|
return nil
|
|
}
|