Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(rexctl): base the cron upgrade offset on the domain (#3668)

Hampus7e30e95faa12
diff --git a/fluxer_rexctl/cmd/autoupgrade.go b/fluxer_rexctl/cmd/autoupgrade.go
index bf6af776f..71e4f85e5 100644
--- a/fluxer_rexctl/cmd/autoupgrade.go
+++ b/fluxer_rexctl/cmd/autoupgrade.go
@@ -99,6 +99,7 @@ func autoUpgradeFor(inst *instance.Instance, e *engine.Engine) (host.AutoUpgrade
a := host.AutoUpgrade{
Scheduler: host.UpgradeScheduler(),
Project: inst.Project(),
+ Domain: inst.Domain(),
Dir: dir,
Binary: bin,
Rootless: runtime.GOOS == "linux" && os.Geteuid() != 0,
diff --git a/fluxer_rexctl/internal/host/autoupgrade.go b/fluxer_rexctl/internal/host/autoupgrade.go
index 95618667c..44d08d8bd 100644
--- a/fluxer_rexctl/internal/host/autoupgrade.go
+++ b/fluxer_rexctl/internal/host/autoupgrade.go
@@ -50,6 +50,7 @@ func UpgradeScheduler() Scheduler {
type AutoUpgrade struct {
Scheduler Scheduler
Project string
+ Domain string
Dir string
Binary string
Podman bool
@@ -112,7 +113,7 @@ func (a AutoUpgrade) start() (int, int, error) {
return hour, minute, err
}
h := fnv.New32a()
- h.Write([]byte(a.Project + "\x00" + a.Dir))
+ h.Write([]byte(a.Domain + "\x00" + a.Project + "\x00" + a.Dir))
m := (hour*60 + minute + int(h.Sum32()%uint32(UpgradeWindow.Minutes()))) % (24 * 60)
return m / 60, m % 60, nil
}
diff --git a/fluxer_rexctl/internal/host/autoupgrade_test.go b/fluxer_rexctl/internal/host/autoupgrade_test.go
index 57823270a..d3a2b6616 100644
--- a/fluxer_rexctl/internal/host/autoupgrade_test.go
+++ b/fluxer_rexctl/internal/host/autoupgrade_test.go
@@ -4,6 +4,7 @@ package host
import (
"context"
+ "fmt"
"os"
"path/filepath"
"runtime"
@@ -112,7 +113,7 @@ func TestAutoUpgradeRefusesBadInput(t *testing.T) {
}
func TestAutoUpgradeCronStart(t *testing.T) {
- a := AutoUpgrade{Scheduler: Cron, Project: "fluxer", Dir: "/srv/fluxer", Binary: "/usr/local/bin/rexctl", At: "04:00", Log: "/srv/fluxer/.rexctl/auto-upgrade.log"}
+ a := AutoUpgrade{Scheduler: Cron, Project: "fluxer", Domain: "chat.example.com", Dir: "/srv/fluxer", Binary: "/usr/local/bin/rexctl", At: "04:00", Log: "/srv/fluxer/.rexctl/auto-upgrade.log"}
start, err := a.Start()
if err != nil {
t.Fatal(err)
@@ -127,15 +128,21 @@ func TestAutoUpgradeCronStart(t *testing.T) {
if err != nil || cronAt(files[0]) != start {
t.Errorf("cron file runs at %q, want %q (%v)", cronAt(files[0]), start, err)
}
- starts := map[string]bool{}
- for _, dir := range []string{"/srv/a", "/srv/b", "/srv/c", "/srv/d", "/srv/e", "/srv/f"} {
- b := a
- b.Dir = dir
- s, _ := b.Start()
- starts[s] = true
+ spread := func(vary func(*AutoUpgrade, int)) int {
+ starts := map[string]bool{}
+ for i := range 8 {
+ b := a
+ vary(&b, i)
+ s, _ := b.Start()
+ starts[s] = true
+ }
+ return len(starts)
+ }
+ if n := spread(func(b *AutoUpgrade, i int) { b.Domain = fmt.Sprintf("chat%d.example.com", i) }); n < 2 {
+ t.Errorf("eight servers with the default project and folder start at %d time, want them spread out", n)
}
- if len(starts) < 2 {
- t.Errorf("six instances all start at %v, want them spread out", starts)
+ if n := spread(func(b *AutoUpgrade, i int) { b.Dir = fmt.Sprintf("/srv/fluxer%d", i) }); n < 2 {
+ t.Errorf("eight instances on one host start at %d time, want them spread out", n)
}
late := a
late.At = "23:59"