Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 1 | // Copyright 2024 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package main |
| 6 | |
| 7 | import ( |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 8 | "cmp" |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 9 | "fmt" |
| 10 | "log" |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 11 | "slices" |
| 12 | |
| 13 | "go.chromium.org/luci/swarming/client/swarming" |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 14 | ) |
| 15 | |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 16 | // swarmingConfig describes a swarming server. |
| 17 | type swarmingConfig struct { |
| 18 | Host string // Swarming host URL |
| 19 | Pool string // Pool containing MacService bots |
| 20 | |
| 21 | client swarming.Client |
| 22 | } |
| 23 | |
Dmitri Shuralyov | a705825 | 2024-04-26 15:10:23 -0400 | [diff] [blame] | 24 | var ( |
| 25 | // Public swarming host. |
| 26 | publicSwarming = &swarmingConfig{ |
| 27 | Host: "chromium-swarm.appspot.com", |
| 28 | Pool: "luci.golang.shared-workers", |
| 29 | } |
| 30 | // Security swarming host. |
| 31 | internalSwarming = &swarmingConfig{ |
| 32 | Host: "chrome-swarming.appspot.com", |
| 33 | Pool: "luci.golang.security-try-workers", |
| 34 | } |
| 35 | ) |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 36 | |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 37 | // imageConfig describes how many instances of a specific image type should |
| 38 | // exist. |
| 39 | type imageConfig struct { |
Michael Pratt | 28d7276 | 2024-03-08 15:33:53 -0500 | [diff] [blame] | 40 | Hostname string // LUCI hostname prefix |
| 41 | Cert string // Bot certificate (resolved with internal/secret) |
| 42 | Key string // bot key (resolved with internal/secret) |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 43 | Image string // image SHA |
| 44 | MinCount int // minimum instance count to maintain |
| 45 | } |
| 46 | |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 47 | // Production image configuration for each swarming host. |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 48 | // |
| 49 | // After changing an image here, makemac will automatically destroy instances |
Michael Pratt | 28d7276 | 2024-03-08 15:33:53 -0500 | [diff] [blame] | 50 | // with the old image. Changing hostname, cert, or key will _not_ automatically |
| 51 | // destroy instances. |
| 52 | // |
| 53 | // TODO(prattmic): rather than storing secrets in secret manager, makemac could |
| 54 | // use genbotcert to generate valid certificate/key pairs on the fly, unique to |
| 55 | // each lease, which could then have unique hostnames. |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 56 | var prodImageConfig = map[*swarmingConfig][]imageConfig{ |
| 57 | publicSwarming: { |
| 58 | { |
| 59 | Hostname: "darwin-amd64-10_15", |
| 60 | Cert: "secret:symbolic-datum-552/darwin-amd64-10_15-cert", |
| 61 | Key: "secret:symbolic-datum-552/darwin-amd64-10_15-key", |
| 62 | Image: "57b56e0a86984934370bf00058b2bd708031d256104167a3bbbc5ff5aaaf6939", |
| 63 | MinCount: 5, // release branches only |
| 64 | }, |
| 65 | { |
| 66 | Hostname: "darwin-amd64-11", |
| 67 | Cert: "secret:symbolic-datum-552/darwin-amd64-11-cert", |
| 68 | Key: "secret:symbolic-datum-552/darwin-amd64-11-key", |
| 69 | Image: "3279e7f8aef8a1d02ba0897de44e5306f94c8cacec3c8c662a897b810879f655", |
| 70 | MinCount: 10, |
| 71 | }, |
| 72 | { |
| 73 | Hostname: "darwin-amd64-12", |
| 74 | Cert: "secret:symbolic-datum-552/darwin-amd64-12-cert", |
| 75 | Key: "secret:symbolic-datum-552/darwin-amd64-12-key", |
| 76 | Image: "959a409833522fcba0be62c0c818d68b29d4e1be28d3cbf43dbbc81cb3e3fdeb", |
| 77 | MinCount: 10, |
| 78 | }, |
| 79 | { |
| 80 | Hostname: "darwin-amd64-13", |
| 81 | Cert: "secret:symbolic-datum-552/darwin-amd64-13-cert", |
| 82 | Key: "secret:symbolic-datum-552/darwin-amd64-13-key", |
| 83 | Image: "30efbbd26e846da8158a7252d47b3adca15b30270668a95620ace3502cdcaa36", |
| 84 | MinCount: 10, |
| 85 | }, |
| 86 | { |
| 87 | Hostname: "darwin-amd64-14", |
| 88 | Cert: "secret:symbolic-datum-552/darwin-amd64-14-cert", |
| 89 | Key: "secret:symbolic-datum-552/darwin-amd64-14-key", |
Michael Pratt | ce6736d | 2024-06-14 16:14:48 -0400 | [diff] [blame] | 90 | Image: "88491078fb25b3bd6db3fe519d0bca63448cddf3f7f10177da2e46019664a85b", |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 91 | MinCount: 10, |
| 92 | }, |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 93 | }, |
Dmitri Shuralyov | a705825 | 2024-04-26 15:10:23 -0400 | [diff] [blame] | 94 | internalSwarming: { |
| 95 | { |
Dmitri Shuralyov | fbb60e3 | 2024-05-10 10:27:03 -0400 | [diff] [blame] | 96 | Hostname: "darwin-amd64-10_15-security", |
| 97 | Cert: "secret:symbolic-datum-552/darwin-amd64-10_15-security-cert", |
| 98 | Key: "secret:symbolic-datum-552/darwin-amd64-10_15-security-key", |
| 99 | Image: "57b56e0a86984934370bf00058b2bd708031d256104167a3bbbc5ff5aaaf6939", |
| 100 | MinCount: 1, |
| 101 | }, |
| 102 | { |
| 103 | Hostname: "darwin-amd64-11-security", |
| 104 | Cert: "secret:symbolic-datum-552/darwin-amd64-11-security-cert", |
| 105 | Key: "secret:symbolic-datum-552/darwin-amd64-11-security-key", |
| 106 | Image: "3279e7f8aef8a1d02ba0897de44e5306f94c8cacec3c8c662a897b810879f655", |
| 107 | MinCount: 1, |
| 108 | }, |
| 109 | { |
| 110 | Hostname: "darwin-amd64-12-security", |
| 111 | Cert: "secret:symbolic-datum-552/darwin-amd64-12-security-cert", |
| 112 | Key: "secret:symbolic-datum-552/darwin-amd64-12-security-key", |
| 113 | Image: "959a409833522fcba0be62c0c818d68b29d4e1be28d3cbf43dbbc81cb3e3fdeb", |
| 114 | MinCount: 1, |
| 115 | }, |
| 116 | { |
| 117 | Hostname: "darwin-amd64-13-security", |
| 118 | Cert: "secret:symbolic-datum-552/darwin-amd64-13-security-cert", |
| 119 | Key: "secret:symbolic-datum-552/darwin-amd64-13-security-key", |
| 120 | Image: "30efbbd26e846da8158a7252d47b3adca15b30270668a95620ace3502cdcaa36", |
| 121 | MinCount: 1, |
| 122 | }, |
| 123 | { |
Dmitri Shuralyov | a705825 | 2024-04-26 15:10:23 -0400 | [diff] [blame] | 124 | Hostname: "darwin-amd64-14-security", |
| 125 | Cert: "secret:symbolic-datum-552/darwin-amd64-14-security-cert", |
| 126 | Key: "secret:symbolic-datum-552/darwin-amd64-14-security-key", |
Michael Pratt | ce6736d | 2024-06-14 16:14:48 -0400 | [diff] [blame] | 127 | Image: "88491078fb25b3bd6db3fe519d0bca63448cddf3f7f10177da2e46019664a85b", |
Dmitri Shuralyov | fbb60e3 | 2024-05-10 10:27:03 -0400 | [diff] [blame] | 128 | MinCount: 1, |
Dmitri Shuralyov | a705825 | 2024-04-26 15:10:23 -0400 | [diff] [blame] | 129 | }, |
| 130 | }, |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // imageConfigMap returns a map from imageConfig.Image to imageConfig. |
| 134 | func imageConfigMap(cc []imageConfig) map[string]*imageConfig { |
| 135 | m := make(map[string]*imageConfig) |
| 136 | for _, c := range cc { |
| 137 | c := c |
| 138 | if _, ok := m[c.Image]; ok { |
| 139 | panic(fmt.Sprintf("duplicate image %s in image config", c.Image)) |
| 140 | } |
| 141 | m[c.Image] = &c |
| 142 | } |
| 143 | return m |
| 144 | } |
| 145 | |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 146 | // sortedSwarmingConfigs returns the swarming configs in c, sorted by host. |
| 147 | func sortedSwarmingConfigs(c map[*swarmingConfig][]imageConfig) []*swarmingConfig { |
| 148 | scs := make([]*swarmingConfig, 0, len(c)) |
| 149 | for sc := range c { |
| 150 | scs = append(scs, sc) |
| 151 | } |
| 152 | slices.SortFunc(scs, func(a, b *swarmingConfig) int { |
| 153 | return cmp.Compare(a.Host, b.Host) |
| 154 | }) |
| 155 | return scs |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 156 | } |
| 157 | |
Michael Pratt | 4e5c55e | 2024-03-08 16:16:11 -0500 | [diff] [blame] | 158 | func init() { |
| 159 | // Panic if prodImageConfig contains duplicates. |
| 160 | for _, c := range prodImageConfig { |
| 161 | imageConfigMap(c) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | func logImageConfig(sc *swarmingConfig, cc []imageConfig) { |
| 166 | log.Printf("%s image configuration:", sc.Host) |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 167 | for _, c := range cc { |
Michael Pratt | 28d7276 | 2024-03-08 15:33:53 -0500 | [diff] [blame] | 168 | log.Printf("\t%s: image=%s\tcount=%d", c.Hostname, c.Image, c.MinCount) |
Michael Pratt | 39f86e9 | 2024-02-07 09:32:46 -0500 | [diff] [blame] | 169 | } |
| 170 | } |