Skip to content

Commit 0a823b5

Browse files
bradfitzcodebien
authored andcommitted
cmd/buildlet, cmd/coordinator: delete old --reverse mode
All the buildlets have been updated to use --reverse-type with a host type instead of a builder type. Fixes golang/go#21260 Change-Id: I1264261f099c3686fe01455949486f523b94c6de Reviewed-on: https://go-review.googlesource.com/c/build/+/205608 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent db29b3b commit 0a823b5

File tree

4 files changed

+36
-133
lines changed

4 files changed

+36
-133
lines changed

cmd/buildlet/buildlet.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ var (
5050
rebootOnHalt = flag.Bool("reboot", false, "reboot system in /halt handler.")
5151
workDir = flag.String("workdir", "", "Temporary directory to use. The contents of this directory may be deleted at any time. If empty, TempDir is used to create one.")
5252
listenAddr = flag.String("listen", "AUTO", "address to listen on. Unused in reverse mode. Warning: this service is inherently insecure and offers no protection of its own. Do not expose this port to the world.")
53-
reverse = flag.String("reverse", "", "[deprecated; use --reverse-type instead] if non-empty, go into reverse mode where the buildlet dials the coordinator instead of listening for connections. The value is a comma-separated list of modes, e.g. 'darwin-arm,darwin-amd64-race'")
5453
reverseType = flag.String("reverse-type", "", "if non-empty, go into reverse mode where the buildlet dials the coordinator instead of listening for connections. The value is the dashboard/builders.go Hosts map key, naming a HostConfig. This buildlet will receive work for any BuildConfig specifying this named HostConfig.")
5554
coordinator = flag.String("coordinator", "localhost:8119", "address of coordinator, in production use farmer.golang.org. Only used in reverse mode.")
5655
hostname = flag.String("hostname", "", "hostname to advertise to coordinator for reverse mode; default is actual hostname")
@@ -157,10 +156,7 @@ func main() {
157156
log.Printf("set OS rlimits.")
158157
}
159158

160-
if *reverse != "" && *reverseType != "" {
161-
log.Fatalf("can't specify both --reverse and --reverse-type")
162-
}
163-
isReverse := *reverse != "" || *reverseType != ""
159+
isReverse := *reverseType != ""
164160

165161
if *listenAddr == "AUTO" && !isReverse {
166162
v := defaultListenAddr()

cmd/buildlet/reverse.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ func keyForMode(mode string) (string, error) {
4949
os.Remove(keyPath)
5050
}
5151
if err != nil {
52-
if os.IsNotExist(err) && *reverse != "" && !strings.Contains(*reverse, ",") {
53-
globalKeyPath := filepath.Join(homedir(), ".gobuildkey")
54-
key, err = ioutil.ReadFile(globalKeyPath)
55-
if err != nil {
56-
return "", fmt.Errorf("cannot read either key file %q or %q: %v", keyPath, globalKeyPath, err)
57-
}
58-
}
5952
if len(key) == 0 || err != nil {
6053
return "", fmt.Errorf("cannot read key file %q: %v", keyPath, err)
6154
}
@@ -77,24 +70,9 @@ func dialCoordinator() error {
7770
}
7871
}
7972

80-
var modes, keys []string
81-
if *reverse != "" {
82-
// Old way.
83-
modes = strings.Split(*reverse, ",")
84-
for _, m := range modes {
85-
key, err := keyForMode(m)
86-
if err != nil {
87-
log.Fatalf("failed to find key for %s: %v", m, err)
88-
}
89-
keys = append(keys, key)
90-
}
91-
} else {
92-
// New way.
93-
key, err := keyForMode(*reverseType)
94-
if err != nil {
95-
log.Fatalf("failed to find key for %s: %v", *reverseType, err)
96-
}
97-
keys = append(keys, key)
73+
key, err := keyForMode(*reverseType)
74+
if err != nil {
75+
log.Fatalf("failed to find key for %s: %v", *reverseType, err)
9876
}
9977

10078
addr := *coordinator
@@ -138,13 +116,8 @@ func dialCoordinator() error {
138116
if err != nil {
139117
log.Fatal(err)
140118
}
141-
if *reverse != "" {
142-
// Old way.
143-
req.Header["X-Go-Builder-Type"] = modes
144-
} else {
145-
req.Header.Set("X-Go-Host-Type", *reverseType)
146-
}
147-
req.Header["X-Go-Builder-Key"] = keys
119+
req.Header.Set("X-Go-Host-Type", *reverseType)
120+
req.Header.Set("X-Go-Builder-Key", key)
148121
req.Header.Set("X-Go-Builder-Hostname", *hostname)
149122
req.Header.Set("X-Go-Builder-Version", strconv.Itoa(buildletVersion))
150123
req.Header.Set("X-Revdial-Version", "2")

cmd/coordinator/reverse.go

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -541,14 +541,14 @@ func handleReverse(w http.ResponseWriter, r *http.Request) {
541541
http.Error(w, "buildlet registration requires SSL", http.StatusInternalServerError)
542542
return
543543
}
544-
// Check build keys.
545544

546-
// modes can be either 1 buildlet type (new way) or builder mode(s) (the old way)
547-
hostType := r.Header.Get("X-Go-Host-Type")
548-
modes := r.Header["X-Go-Builder-Type"] // old way
549-
gobuildkeys := r.Header["X-Go-Builder-Key"]
550-
buildletVersion := r.Header.Get("X-Go-Builder-Version")
551-
revDialVersion := r.Header.Get("X-Revdial-Version")
545+
var (
546+
hostType = r.Header.Get("X-Go-Host-Type")
547+
buildKey = r.Header.Get("X-Go-Builder-Key")
548+
buildletVersion = r.Header.Get("X-Go-Builder-Version")
549+
revDialVersion = r.Header.Get("X-Revdial-Version")
550+
hostname = r.Header.Get("X-Go-Builder-Hostname")
551+
)
552552

553553
switch revDialVersion {
554554
case "":
@@ -561,34 +561,14 @@ func handleReverse(w http.ResponseWriter, r *http.Request) {
561561
return
562562
}
563563

564-
// Convert the new argument style (X-Go-Host-Type) into the
565-
// old way, to minimize changes in the rest of this code.
564+
// Check build keys.
566565
if hostType != "" {
567-
if len(modes) > 0 {
568-
http.Error(w, "invalid mix of X-Go-Host-Type and X-Go-Builder-Type", http.StatusBadRequest)
569-
return
570-
}
571-
modes = []string{hostType}
572-
}
573-
if len(modes) == 0 || len(modes) != len(gobuildkeys) {
574-
http.Error(w, fmt.Sprintf("need at least one mode and matching key, got %d/%d", len(modes), len(gobuildkeys)), http.StatusPreconditionFailed)
566+
http.Error(w, "missing X-Go-Host-Type; old buildlet binary?", http.StatusBadRequest)
575567
return
576568
}
577-
hostname := r.Header.Get("X-Go-Builder-Hostname")
578-
579-
for i, m := range modes {
580-
if gobuildkeys[i] != builderKey(m) {
581-
http.Error(w, fmt.Sprintf("bad key for mode %q", m), http.StatusPreconditionFailed)
582-
return
583-
}
584-
}
585-
586-
// For older builders using the buildlet's -reverse flag only,
587-
// collapse their builder modes down into a singular hostType.
588-
legacyNote := ""
589-
if hostType == "" {
590-
hostType = mapBuilderToHostType(modes)
591-
legacyNote = fmt.Sprintf(" (mapped from legacy modes %q)", modes)
569+
if buildKey != builderKey(hostType) {
570+
http.Error(w, "invalid build key", http.StatusPreconditionFailed)
571+
return
592572
}
593573

594574
conn, bufrw, err := w.(http.Hijacker).Hijack()
@@ -603,8 +583,8 @@ func handleReverse(w http.ResponseWriter, r *http.Request) {
603583
return
604584
}
605585

606-
log.Printf("Registering reverse buildlet %q (%s) for host type %v %s; buildletVersion=%v; revDialVersion=%v",
607-
hostname, r.RemoteAddr, hostType, legacyNote, buildletVersion, revDialVersion)
586+
log.Printf("Registering reverse buildlet %q (%s) for host type %v; buildletVersion=%v; revDialVersion=%v",
587+
hostname, r.RemoteAddr, hostType, buildletVersion, revDialVersion)
608588

609589
var dialer func(context.Context) (net.Conn, error)
610590
var revDialerDone <-chan struct{}
@@ -659,8 +639,8 @@ func handleReverse(w http.ResponseWriter, r *http.Request) {
659639
tstatus := time.Now()
660640
status, err := client.Status()
661641
if err != nil {
662-
log.Printf("Reverse connection %s/%s for modes %v did not answer status after %v: %v",
663-
hostname, r.RemoteAddr, modes, time.Since(tstatus), err)
642+
log.Printf("Reverse connection %s/%s for %s did not answer status after %v: %v",
643+
hostname, r.RemoteAddr, hostType, time.Since(tstatus), err)
664644
conn.Close()
665645
return
666646
}
@@ -669,7 +649,7 @@ func handleReverse(w http.ResponseWriter, r *http.Request) {
669649
conn.Close()
670650
return
671651
}
672-
log.Printf("Buildlet %s/%s: %+v for %s", hostname, r.RemoteAddr, status, modes)
652+
log.Printf("Buildlet %s/%s: %+v for %s", hostname, r.RemoteAddr, status, hostType)
673653

674654
now := time.Now()
675655
b := &reverseBuildlet{
@@ -683,11 +663,8 @@ func handleReverse(w http.ResponseWriter, r *http.Request) {
683663
regTime: now,
684664
}
685665
reversePool.addBuildlet(b)
686-
registerBuildlet(modes) // testing only
687666
}
688667

689-
var registerBuildlet = func(modes []string) {} // test hook
690-
691668
type byTypeThenHostname []*reverseBuildlet
692669

693670
func (s byTypeThenHostname) Len() int { return len(s) }
@@ -700,29 +677,3 @@ func (s byTypeThenHostname) Less(i, j int) bool {
700677
}
701678
return ti < tj
702679
}
703-
704-
// mapBuilderToHostType maps from the user's Request.Header["X-Go-Builder-Type"]
705-
// mode list down into a single host type, or the empty string if unknown.
706-
func mapBuilderToHostType(modes []string) string {
707-
// First, see if any of the provided modes are a host type.
708-
// If so, this is an updated client.
709-
for _, v := range modes {
710-
if _, ok := dashboard.Hosts[v]; ok {
711-
return v
712-
}
713-
}
714-
715-
// Else, it's an old client, still speaking in terms of
716-
// builder names. See if any are registered aliases. First
717-
// one wins. (There are no ambiguities in the wild.)
718-
for hostType, hconf := range dashboard.Hosts {
719-
for _, alias := range hconf.ReverseAliases {
720-
for _, v := range modes {
721-
if v == alias {
722-
return hostType
723-
}
724-
}
725-
}
726-
}
727-
return ""
728-
}

dashboard/builders.go

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,13 @@ var Hosts = map[string]*HostConfig{
200200
HermeticReverse: true,
201201
ExpectNum: 50,
202202
env: []string{"GOROOT_BOOTSTRAP=/usr/local/go"},
203-
ReverseAliases: []string{"linux-arm", "linux-arm-arm5"},
204203
SSHUsername: "root",
205204
},
206205
"host-linux-arm5spacemonkey": &HostConfig{
207-
IsReverse: true,
208-
ExpectNum: 3,
209-
env: []string{"GOROOT_BOOTSTRAP=/usr/local/go"},
210-
ReverseAliases: []string{"linux-arm-arm5spacemonkey"},
211-
OwnerGithub: "esnolte", // https://github.com/golang/go/issues/34973#issuecomment-543836871
206+
IsReverse: true,
207+
ExpectNum: 3,
208+
env: []string{"GOROOT_BOOTSTRAP=/usr/local/go"},
209+
OwnerGithub: "esnolte", // https://github.com/golang/go/issues/34973#issuecomment-543836871
212210
},
213211
"host-openbsd-amd64-60": &HostConfig{
214212
VMImage: "openbsd-amd64-60",
@@ -357,12 +355,11 @@ var Hosts = map[string]*HostConfig{
357355
OwnerGithub: "tuxillo",
358356
},
359357
"host-freebsd-arm-paulzhol": &HostConfig{
360-
IsReverse: true,
361-
ExpectNum: 1,
362-
Notes: "Cubiboard2 1Gb RAM dual-core Cortex-A7 (Allwinner A20), FreeBSD 11.1-RELEASE",
363-
env: []string{"GOROOT_BOOTSTRAP=/usr/home/paulzhol/go1.4"},
364-
ReverseAliases: []string{"freebsd-arm-paulzhol"},
365-
OwnerGithub: "paulzhol",
358+
IsReverse: true,
359+
ExpectNum: 1,
360+
Notes: "Cubiboard2 1Gb RAM dual-core Cortex-A7 (Allwinner A20), FreeBSD 11.1-RELEASE",
361+
env: []string{"GOROOT_BOOTSTRAP=/usr/home/paulzhol/go1.4"},
362+
OwnerGithub: "paulzhol",
366363
},
367364
"host-freebsd-arm64-dmgk": &HostConfig{
368365
IsReverse: true,
@@ -452,7 +449,6 @@ var Hosts = map[string]*HostConfig{
452449
env: []string{
453450
"GOROOT_BOOTSTRAP=/Users/gopher/go1.4",
454451
},
455-
ReverseAliases: []string{"darwin-amd64-10_8"},
456452
SSHUsername: "gopher",
457453
HermeticReverse: false, // TODO: make it so, like 10.12
458454
},
@@ -463,7 +459,6 @@ var Hosts = map[string]*HostConfig{
463459
env: []string{
464460
"GOROOT_BOOTSTRAP=/Users/gopher/go1.4",
465461
},
466-
ReverseAliases: []string{"darwin-amd64-10_10"},
467462
SSHUsername: "gopher",
468463
HermeticReverse: false, // TODO: make it so, like 10.12
469464
},
@@ -474,7 +469,6 @@ var Hosts = map[string]*HostConfig{
474469
env: []string{
475470
"GOROOT_BOOTSTRAP=/Users/gopher/go1.4",
476471
},
477-
ReverseAliases: []string{"darwin-amd64-10_11"},
478472
SSHUsername: "gopher",
479473
HermeticReverse: false, // TODO: make it so, like 10.12
480474
},
@@ -485,7 +479,6 @@ var Hosts = map[string]*HostConfig{
485479
env: []string{
486480
"GOROOT_BOOTSTRAP=/Users/gopher/go1.4",
487481
},
488-
ReverseAliases: []string{"darwin-amd64-10_12"},
489482
SSHUsername: "gopher",
490483
HermeticReverse: true, // we destroy the VM when done & let cmd/makemac recreate
491484
},
@@ -500,18 +493,16 @@ var Hosts = map[string]*HostConfig{
500493
HermeticReverse: true, // we destroy the VM when done & let cmd/makemac recreate
501494
},
502495
"host-linux-s390x": &HostConfig{
503-
Notes: "run by IBM",
504-
OwnerGithub: "mundaym",
505-
IsReverse: true,
506-
env: []string{"GOROOT_BOOTSTRAP=/var/buildlet/go-linux-s390x-bootstrap"},
507-
ReverseAliases: []string{"linux-s390x-ibm"},
496+
Notes: "run by IBM",
497+
OwnerGithub: "mundaym",
498+
IsReverse: true,
499+
env: []string{"GOROOT_BOOTSTRAP=/var/buildlet/go-linux-s390x-bootstrap"},
508500
},
509501
"host-linux-ppc64-osu": &HostConfig{
510502
Notes: "Debian jessie; run by Go team on osuosl.org",
511503
IsReverse: true,
512504
ExpectNum: 5,
513505
env: []string{"GOROOT_BOOTSTRAP=/usr/local/go-bootstrap"},
514-
ReverseAliases: []string{"linux-ppc64-buildlet"},
515506
SSHUsername: "root",
516507
HermeticReverse: false, // TODO: run in chroots with overlayfs? https://github.com/golang/go/issues/34830#issuecomment-543386764
517508
},
@@ -723,14 +714,6 @@ type HostConfig struct {
723714
Notes string // notes for humans
724715

725716
SSHUsername string // username to ssh as, empty means not supported
726-
727-
// ReverseAliases lists alternate names for this buildlet
728-
// config, for older clients doing a reverse dial into the
729-
// coordinator from outside. This prevents us from updating
730-
// 75+ dedicated machines/VMs atomically, switching them to
731-
// the new "host-*" names.
732-
// This is only applicable if IsReverse.
733-
ReverseAliases []string
734717
}
735718

736719
// A BuildConfig describes how to run a builder.

0 commit comments

Comments
 (0)