Support multiple CarrierNode instances in carriernodeclient/coreconfig/mediacore

ProjectConfigurator's Projects workspace already lets an operator register more
than one CarrierNode instance (separate storage backends, HA/failover replicas,
or a mix), but every consumer only ever read a single carriernode_url. Add
carriernodeclient.NewMulti (ListFiles merges across instances, Probe/
FetchToScratch/ProbeMedia try each in order, writes stay primary-only),
coreconfig.Info.CarrierNodeURLs for pushed consumers, and
mediacore.CarrierNodeURLs for the 7 services that read settings directly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-11 11:37:56 +02:00
1 parent 87ac5ed25a
commit 9f78995d03
5 files changed
+434 -42

No files matched your search

+44
View File
@@ -37,6 +37,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
@@ -796,6 +797,49 @@ func SaveSetting(ctx context.Context, db *pgxpool.Pool, key, value string) error
return err
}
// carrierNodeInstancePattern matches a registered project key naming a CarrierNode instance: the
// base "carriernode" itself, or a numbered peer like "carriernode_2" - see
// ProjectConfigurator/backend/cmd/projectconfigurator/settings.go's identical pattern (kept in
// sync manually since one is the sender's copy and this is the direct-DB-read receiver's copy of
// the same convention, not literally shared code).
var carrierNodeInstancePattern = regexp.MustCompile(`^carriernode(_\d+)?$`)
// CarrierNodeURLs returns every CarrierNode instance registered in ProjectConfigurator's Projects
// workspace ("carriernode_url", "carriernode_2_url", ...), read directly from the shared
// `settings` table in registration order, dropping any instance with no URL set. This is for the
// 7 MEDIA_SERVICE instances that share this database directly instead of going through
// ProjectConfigurator's coreconfig push (see ProjectConfigurator/README.md's "Pushing core service
// info to other projects" section) - wire it as a carriernodeclient.Client's BaseURLs:
//
// carriernodeclient.NewMulti(secret, func(ctx context.Context) []string {
// return mediacore.CarrierNodeURLs(ctx, db, fallback)
// })
//
// Returns fallback if no carriernode* instance is registered (or none has a URL) yet.
func CarrierNodeURLs(ctx context.Context, db *pgxpool.Pool, fallback []string) []string {
var registered []string
_ = json.Unmarshal([]byte(SettingValue(ctx, db, "configured_central", "")), &registered)
var urls []string
for _, project := range registered {
key := strings.ToLower(strings.TrimSpace(project))
if !carrierNodeInstancePattern.MatchString(key) {
continue
}
if url := strings.TrimSpace(SettingValue(ctx, db, key+"_url", "")); url != "" {
urls = append(urls, url)
}
}
if len(urls) == 0 {
if url := strings.TrimSpace(SettingValue(ctx, db, "carriernode_url", "")); url != "" {
urls = []string{url}
}
}
if len(urls) == 0 {
return fallback
}
return urls
}
// --- path-safety helpers (generic, no Core dependency) ---
// SafeRelative reports whether value is a relative path with no `..`