blob: 717d6ef1fc2d25c4de1ab187766475601edd69eb [file] [log] [blame]
Michael Pratt39f86e92024-02-07 09:32:46 -05001// 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
5package main
6
7import (
Michael Pratt4e5c55e2024-03-08 16:16:11 -05008 "cmp"
Michael Pratt39f86e92024-02-07 09:32:46 -05009 "fmt"
10 "log"
Michael Pratt4e5c55e2024-03-08 16:16:11 -050011 "slices"
12
13 "go.chromium.org/luci/swarming/client/swarming"
Michael Pratt39f86e92024-02-07 09:32:46 -050014)
15
Michael Pratt4e5c55e2024-03-08 16:16:11 -050016// swarmingConfig describes a swarming server.
17type swarmingConfig struct {
18 Host string // Swarming host URL
19 Pool string // Pool containing MacService bots
20
21 client swarming.Client
22}
23
Dmitri Shuralyova7058252024-04-26 15:10:23 -040024var (
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 Pratt4e5c55e2024-03-08 16:16:11 -050036
Michael Pratt39f86e92024-02-07 09:32:46 -050037// imageConfig describes how many instances of a specific image type should
38// exist.
39type imageConfig struct {
Michael Pratt28d72762024-03-08 15:33:53 -050040 Hostname string // LUCI hostname prefix
41 Cert string // Bot certificate (resolved with internal/secret)
42 Key string // bot key (resolved with internal/secret)
Michael Pratt39f86e92024-02-07 09:32:46 -050043 Image string // image SHA
44 MinCount int // minimum instance count to maintain
45}
46
Michael Pratt4e5c55e2024-03-08 16:16:11 -050047// Production image configuration for each swarming host.
Michael Pratt39f86e92024-02-07 09:32:46 -050048//
49// After changing an image here, makemac will automatically destroy instances
Michael Pratt28d72762024-03-08 15:33:53 -050050// 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 Pratt4e5c55e2024-03-08 16:16:11 -050056var 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 Prattce6736d2024-06-14 16:14:48 -040090 Image: "88491078fb25b3bd6db3fe519d0bca63448cddf3f7f10177da2e46019664a85b",
Michael Pratt4e5c55e2024-03-08 16:16:11 -050091 MinCount: 10,
92 },
Michael Pratt39f86e92024-02-07 09:32:46 -050093 },
Dmitri Shuralyova7058252024-04-26 15:10:23 -040094 internalSwarming: {
95 {
Dmitri Shuralyovfbb60e32024-05-10 10:27:03 -040096 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 Shuralyova7058252024-04-26 15:10:23 -0400124 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 Prattce6736d2024-06-14 16:14:48 -0400127 Image: "88491078fb25b3bd6db3fe519d0bca63448cddf3f7f10177da2e46019664a85b",
Dmitri Shuralyovfbb60e32024-05-10 10:27:03 -0400128 MinCount: 1,
Dmitri Shuralyova7058252024-04-26 15:10:23 -0400129 },
130 },
Michael Pratt39f86e92024-02-07 09:32:46 -0500131}
132
133// imageConfigMap returns a map from imageConfig.Image to imageConfig.
134func 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 Pratt4e5c55e2024-03-08 16:16:11 -0500146// sortedSwarmingConfigs returns the swarming configs in c, sorted by host.
147func 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 Pratt39f86e92024-02-07 09:32:46 -0500156}
157
Michael Pratt4e5c55e2024-03-08 16:16:11 -0500158func init() {
159 // Panic if prodImageConfig contains duplicates.
160 for _, c := range prodImageConfig {
161 imageConfigMap(c)
162 }
163}
164
165func logImageConfig(sc *swarmingConfig, cc []imageConfig) {
166 log.Printf("%s image configuration:", sc.Host)
Michael Pratt39f86e92024-02-07 09:32:46 -0500167 for _, c := range cc {
Michael Pratt28d72762024-03-08 15:33:53 -0500168 log.Printf("\t%s: image=%s\tcount=%d", c.Hostname, c.Image, c.MinCount)
Michael Pratt39f86e92024-02-07 09:32:46 -0500169 }
170}