diff --git a/scripts/fleet/demo.go b/scripts/fleet/demo.go index 594408f..e5ee649 100644 --- a/scripts/fleet/demo.go +++ b/scripts/fleet/demo.go @@ -49,6 +49,20 @@ func role(pos int) string { return "mq" } +// demoContainers is how many containers host n runs in the demo: only app +// servers run Docker, each about most, give or take four, not every host +// the same. +func demoContainers(n, most int) int { + if role(n%siteSize) != "app" { + return 0 + } + c := max(1, most-4+seedInt(hostName(n)+" containers", time.Time{}, 9)) + if n == demoExited || n == demoStoppedOnPurp { + c = max(c, 10) // their stories need app-04 and app-09 + } + return c +} + // demoUnits are the systemd units host n must keep active. func demoUnits(n int) []string { base := []string{"ssh", "chrony"} // Debian's and Ubuntu's names @@ -268,7 +282,11 @@ func writeDemo(dir string, hosts, windows int) { var exp bytes.Buffer exp.WriteString("# The fleet demo's hosts: what must keep running (fleet config -demo).\nhosts:\n") for n := range hosts { - fmt.Fprintf(&exp, " %s:\n running: [\"app-*\"]\n units: [", hostName(n)) + fmt.Fprintf(&exp, " %s:\n", hostName(n)) + if role(n%siteSize) == "app" { + exp.WriteString(" running: [\"app-*\"]\n") + } + exp.WriteString(" units: [") for k, u := range demoUnits(n) { if k > 0 { exp.WriteString(", ") diff --git a/scripts/fleet/main.go b/scripts/fleet/main.go index 9373c19..8d1078f 100644 --- a/scripts/fleet/main.go +++ b/scripts/fleet/main.go @@ -170,7 +170,7 @@ func run(args []string) { tokFile := fs.String("tokens", "tokens", "from fleet config") n := fs.Int("n", 0, "agents to run (0: every token)") interval := fs.Duration("interval", 15*time.Second, "between one agent's reports") - containers := fs.Int("containers", 10, "containers per host (the cluster watcher's pods come later)") + containers := fs.Int("containers", 10, "containers per host; with -demo, only app servers run them, about this many each, give or take four") withMap := fs.Bool("map", true, "send map samples: sites of 50 hosts, WireGuard between sites, apps talking to databases") dur := fs.Duration("for", 5*time.Minute, "how long") every := fs.Duration("print", 30*time.Second, "how often to print") @@ -307,7 +307,11 @@ func run(args []string) { case i >= len(agents): // a Windows server (windows.go) h = newWindowsHost(a.host, *interval) default: - h = newHost(i, a.host, *containers, *interval) + n := *containers + if *demo { + n = demoContainers(fleetIndex(i, a.host), n) + } + h = newHost(i, a.host, n, *interval) } if *demo && h.win == nil && !isColl { h.demo = newDemoHost(fleetIndex(i, a.host), len(agents), demoAll)