Skip to content

Commit a56442a

Browse files
authored
Cleanup usage of go.rice in favor of go:embed (vitessio#10956)
* Cleanup usage of go.rice in favor of go:embed The usage of go.rice predates the availability of go:embed, but we should switch to using go:embed instead to ship specific assets like config files that we need. go.rice is also incompatible with Go 1.19 and while it might see a fix in the future, it seems better to go with the recommended Go approach that is available these days. Signed-off-by: Dirkjan Bussink <[email protected]> * Move vtctld to also use `go embed` instead of go.rice Signed-off-by: Dirkjan Bussink <[email protected]> * Remove last rice-box related comments Signed-off-by: Dirkjan Bussink <[email protected]> * Remove config moving This right now breaks building the actual tests since the tests might also end up loading the regular code which has a `go embed` and refers to the package with the config embeds. This doesn't mean that the config isn't properly included in the binaries. Also with using `go embed` we have a build time dependency on the files and we always know the latest is included, so we don't have the issue of potentially outdated files either. All in all, it seems simplest to remove this logic and trust that Go itself works as advertised. Signed-off-by: Dirkjan Bussink <[email protected]>
1 parent 06c3515 commit a56442a

File tree

20 files changed

+101
-617
lines changed

20 files changed

+101
-617
lines changed

.gitattributes

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ web/vtadmin/src/proto/*.ts -diff
44
go/vt/proto/** linguist-generated=true
55
go/vt/proto/*/*.pb.go -diff
66
go/vt/sqlparser/sql.go linguist-generated=true -diff
7-
go/vt/mysqlctl/rice-box.go linguist-generated=true -diff

.github/workflows/local_example.yml

-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,4 @@ jobs:
9595
if [ ${{matrix.os}} = "macos-latest" ]; then
9696
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
9797
fi
98-
# Make sure that testing is entirely non-reliant on config
99-
mv config config-moved
10098
eatmydata -- go run test.go -print-log -follow -retry=1 local_example

.github/workflows/region_example.yml

-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,5 @@ jobs:
9595
if [ ${{matrix.os}} = "macos-latest" ]; then
9696
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
9797
fi
98-
# Make sure that testing is entirely non-reliant on config
99-
mv config config-moved
10098
sed -i 's/user\/my-vitess/runner\/work\/vitess\/vitess/g' examples/region_sharding/main_vschema_sharded.json #set correct path to countries.json
10199
eatmydata -- go run test.go -print-log -follow -retry=1 region_example

Makefile

+1-23
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ endif
6969
# This is where Go will install binaries in response to `go build`.
7070
export VTROOTBIN=${VTROOT}/bin
7171

72-
# regenerate rice-box.go when any of the .cnf files change
73-
embed_config:
74-
cd go/vt/mysqlctl && go run github.com/GeertJohan/go.rice/rice embed-go && go build .
75-
7672
# build the vitess binaries with dynamic dependency on libc
7773
build-dyn:
7874
ifndef NOBANNER
@@ -83,8 +79,6 @@ endif
8379
-ldflags "$(shell tools/build_version_flags.sh)" \
8480
-o ${VTROOTBIN} ./go/...
8581

86-
(cd go/cmd/vttablet && go run github.com/GeertJohan/go.rice/rice append --exec=${VTROOTBIN}/vttablet)
87-
8882
# build the vitess binaries statically
8983
build:
9084
ifndef NOBANNER
@@ -98,9 +92,6 @@ endif
9892
-ldflags "$(shell tools/build_version_flags.sh)" \
9993
-o ${VTROOTBIN} ./go/...
10094

101-
# embed local resources in the vttablet executable
102-
(cd go/cmd/vttablet && go run github.com/GeertJohan/go.rice/rice append --exec=${VTROOT}/bin/vttablet)
103-
10495
# build vtorc with CGO, because it depends on sqlite
10596
CGO_ENABLED=1 go build \
10697
-trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \
@@ -129,19 +120,6 @@ endif
129120
echo "Missing vttablet at: ${VTROOTBIN}/${GOOS}_${GOARCH}." && exit; \
130121
fi
131122

132-
# Either ${GOPATH}/rice is already present, and we assume it is
133-
# compiled to the architecture of this machine, or it's not present, in
134-
# which case we need to download, compile and run it. We want to make
135-
# sure we compile it in the current machine's architecture, otherwise
136-
# we won't be able to run it.
137-
@if [ -x "${GOPATH}/rice" ]; then \
138-
echo "Applying ricebox to vttablet with already-present rice."; \
139-
(cd ${VTROOT}/go/cmd/vttablet && ${GOPATH}/rice --verbose append --exec=${VTROOTBIN}/${GOOS}_${GOARCH}/vttablet); \
140-
else \
141-
echo "Applying ricebox to vttablet with download-and-compile rice."; \
142-
(cd ${VTROOT}/go/cmd/vttablet && unset GOOS && unset GOARCH && go run github.com/GeertJohan/go.rice/rice --verbose append --exec=${VTROOTBIN}/${GOOS}_${GOARCH}/vttablet); \
143-
fi
144-
145123
# Cross-compiling w/ cgo isn't trivial and we don't need vtorc, so we can skip building it
146124

147125
debug:
@@ -479,7 +457,7 @@ web_bootstrap:
479457

480458
# Do a production build of the vtctld UI.
481459
# This target needs to be manually run every time any file within web/vtctld2/app
482-
# is modified to regenerate rice-box.go
460+
# is modified to regenerate assets.
483461
web_build: web_bootstrap
484462
./tools/web_build.sh
485463

config/embed.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package config
2+
3+
import _ "embed"
4+
5+
//go:embed init_db.sql
6+
var DefaultInitDB string
7+
8+
//go:embed mycnf/default.cnf
9+
var MycnfDefault string
10+
11+
//go:embed mycnf/mariadb100.cnf
12+
var MycnfMariaDB100 string
13+
14+
//go:embed mycnf/mariadb101.cnf
15+
var MycnfMariaDB101 string
16+
17+
//go:embed mycnf/mariadb102.cnf
18+
var MycnfMariaDB102 string
19+
20+
//go:embed mycnf/mariadb103.cnf
21+
var MycnfMariaDB103 string
22+
23+
//go:embed mycnf/mariadb104.cnf
24+
var MycnfMariaDB104 string
25+
26+
//go:embed mycnf/mysql57.cnf
27+
var MycnfMySQL57 string
28+
29+
//go:embed mycnf/mysql80.cnf
30+
var MycnfMySQL80 string

go.mod

-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/Azure/azure-pipeline-go v0.2.2
99
github.com/Azure/azure-storage-blob-go v0.10.0
1010
github.com/DataDog/datadog-go v2.2.0+incompatible
11-
github.com/GeertJohan/go.rice v1.0.0
1211
github.com/HdrHistogram/hdrhistogram-go v0.9.0 // indirect
1312
github.com/PuerkitoBio/goquery v1.5.1
1413
github.com/aquarapid/vaultlib v0.5.1
@@ -126,16 +125,13 @@ require github.com/bndr/gotabulate v1.1.2
126125
require (
127126
cloud.google.com/go v0.81.0 // indirect
128127
github.com/BurntSushi/toml v0.3.1 // indirect
129-
github.com/GeertJohan/go.incremental v1.0.0 // indirect
130-
github.com/akavel/rsrc v0.8.0 // indirect
131128
github.com/andybalholm/cascadia v1.1.0 // indirect
132129
github.com/beorn7/perks v1.0.1 // indirect
133130
github.com/blang/semver v3.5.1+incompatible // indirect
134131
github.com/coreos/go-semver v0.3.0 // indirect
135132
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
136133
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
137134
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
138-
github.com/daaku/go.zipexe v1.0.0 // indirect
139135
github.com/davecgh/go-spew v1.1.1 // indirect
140136
github.com/fatih/color v1.9.0 // indirect
141137
github.com/felixge/httpsnoop v1.0.1 // indirect
@@ -151,7 +147,6 @@ require (
151147
github.com/hashicorp/golang-lru v0.5.1 // indirect
152148
github.com/hashicorp/hcl v1.0.0 // indirect
153149
github.com/inconshreveable/mousetrap v1.0.0 // indirect
154-
github.com/jessevdk/go-flags v1.4.0 // indirect
155150
github.com/json-iterator/go v1.1.11 // indirect
156151
github.com/jstemmer/go-junit-report v0.9.1 // indirect
157152
github.com/mattn/go-colorable v0.1.6 // indirect
@@ -163,7 +158,6 @@ require (
163158
github.com/mitchellh/mapstructure v1.4.1 // indirect
164159
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
165160
github.com/modern-go/reflect2 v1.0.1 // indirect
166-
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 // indirect
167161
github.com/onsi/ginkgo v1.12.1 // indirect
168162
github.com/onsi/gomega v1.10.3 // indirect
169163
github.com/pelletier/go-toml v1.9.3 // indirect
@@ -178,8 +172,6 @@ require (
178172
github.com/subosito/gotenv v1.2.0 // indirect
179173
github.com/tidwall/match v1.1.1 // indirect
180174
github.com/tidwall/pretty v1.2.0 // indirect
181-
github.com/valyala/bytebufferpool v1.0.0 // indirect
182-
github.com/valyala/fasttemplate v1.0.1 // indirect
183175
go.opencensus.io v0.23.0 // indirect
184176
go.uber.org/atomic v1.7.0 // indirect
185177
go.uber.org/multierr v1.6.0 // indirect

go.sum

-16
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e h1:4ZrkT/RzpnRO
7979
github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e/go.mod h1:uw9h2sd4WWHOPdJ13MQpwK5qYWKYDumDqxWWIknEQ+k=
8080
github.com/DataDog/datadog-go v2.2.0+incompatible h1:V5BKkxACZLjzHjSgBbr2gvLA2Ae49yhc6CSY7MLy5k4=
8181
github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
82-
github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg=
83-
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
84-
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
85-
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
8682
github.com/HdrHistogram/hdrhistogram-go v0.9.0 h1:dpujRju0R4M/QZzcnR1LH1qm+TVG3UzkWdp5tH1WMcg=
8783
github.com/HdrHistogram/hdrhistogram-go v0.9.0/go.mod h1:nxrse8/Tzg2tg3DZcZjm6qEclQKK70g0KxO61gFFZD4=
8884
github.com/Masterminds/glide v0.13.2/go.mod h1:STyF5vcenH/rUqTEv+/hBXlSTo7KYwg2oc2f4tzPWic=
@@ -97,8 +93,6 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
9793
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
9894
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
9995
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
100-
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
101-
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
10296
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
10397
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
10498
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -177,8 +171,6 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
177171
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
178172
github.com/cyphar/filepath-securejoin v0.2.3 h1:YX6ebbZCZP7VkM3scTTokDgBL2TY741X51MTk3ycuNI=
179173
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
180-
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
181-
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
182174
github.com/dave/jennifer v1.4.1 h1:XyqG6cn5RQsTj3qlWQTKlRGAyrTcsk1kUmWdZBzRjDw=
183175
github.com/dave/jennifer v1.4.1/go.mod h1:7jEdnm+qBcxl8PC0zyp7vxcpSRnzXSt9r39tpTVGlwA=
184176
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -462,8 +454,6 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
462454
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
463455
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
464456
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
465-
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
466-
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
467457
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
468458
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
469459
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
@@ -578,8 +568,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
578568
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
579569
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
580570
github.com/ngdinhtoan/glide-cleanup v0.2.0/go.mod h1:UQzsmiDOb8YV3nOsCxK/c9zPpCZVNoHScRE3EO9pVMM=
581-
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg=
582-
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
583571
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
584572
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
585573
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
@@ -747,10 +735,6 @@ github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVK
747735
github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
748736
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
749737
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
750-
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
751-
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
752-
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
753-
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
754738
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
755739
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
756740
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=

go/cmd/vttablet/vttablet.go

+4-15
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import (
2424
"os"
2525

2626
"vitess.io/vitess/go/vt/vttablet/tabletmanager/vdiff"
27-
28-
rice "github.com/GeertJohan/go.rice"
27+
"vitess.io/vitess/resources"
2928

3029
"vitess.io/vitess/go/vt/binlog"
3130
"vitess.io/vitess/go/vt/dbconfigs"
@@ -171,24 +170,14 @@ func initConfig(tabletAlias *topodatapb.TabletAlias) (*tabletenv.TabletConfig, *
171170
}
172171

173172
// extractOnlineDDL extracts the gh-ost binary from this executable. gh-ost is appended
174-
// to vttablet executable by `make build` and via ricebox
173+
// to vttablet executable by `make build` with a go:embed
175174
func extractOnlineDDL() error {
176175
if binaryFileName, isOverride := onlineddl.GhostBinaryFileName(); !isOverride {
177-
riceBox, err := rice.FindBox("../../../resources/bin")
178-
if err != nil {
179-
return err
180-
}
181-
182-
// there is no path override for gh-ost. We're expected to auto-extract gh-ost.
183-
ghostBinary, err := riceBox.Bytes("gh-ost")
184-
if err != nil {
185-
return err
186-
}
187-
if err := os.WriteFile(binaryFileName, ghostBinary, 0755); err != nil {
176+
if err := os.WriteFile(binaryFileName, resources.GhostBinary, 0755); err != nil {
188177
// One possibility of failure is that gh-ost is up and running. In that case,
189178
// let's pause and check if the running gh-ost is exact same binary as the one we wish to extract.
190179
foundBytes, _ := os.ReadFile(binaryFileName)
191-
if bytes.Equal(ghostBinary, foundBytes) {
180+
if bytes.Equal(resources.GhostBinary, foundBytes) {
192181
// OK, it's the same binary, there is no need to extract the file anyway
193182
return nil
194183
}

go/vt/mysqlctl/mysqld.go

+35-19
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
"sync"
4242
"time"
4343

44-
rice "github.com/GeertJohan/go.rice"
44+
"vitess.io/vitess/config"
4545

4646
"vitess.io/vitess/go/mysql"
4747
"vitess.io/vitess/go/vt/dbconfigs"
@@ -668,12 +668,7 @@ func (mysqld *Mysqld) Init(ctx context.Context, cnf *Mycnf, initDBSQLFile string
668668
}
669669

670670
if initDBSQLFile == "" { // default to built-in
671-
riceBox := rice.MustFindBox("../../../config")
672-
sqlFile, err := riceBox.Open("init_db.sql")
673-
if err != nil {
674-
return fmt.Errorf("could not open built-in init_db.sql file")
675-
}
676-
if err := mysqld.executeMysqlScript(params, sqlFile); err != nil {
671+
if err := mysqld.executeMysqlScript(params, strings.NewReader(config.DefaultInitDB)); err != nil {
677672
return fmt.Errorf("failed to initialize mysqld: %v", err)
678673
}
679674
return nil
@@ -804,26 +799,47 @@ func (mysqld *Mysqld) getMycnfTemplate() string {
804799
}
805800
myTemplateSource := new(bytes.Buffer)
806801
myTemplateSource.WriteString("[mysqld]\n")
807-
808-
riceBox := rice.MustFindBox("../../../config")
809-
b, err := riceBox.Bytes("mycnf/default.cnf")
810-
if err != nil {
811-
log.Warningf("could not open embedded default.cnf config file")
812-
}
813-
myTemplateSource.Write(b)
802+
myTemplateSource.WriteString(config.MycnfDefault)
814803

815804
// database flavor + version specific file.
816805
// {flavor}{major}{minor}.cnf
817806
f := FlavorMariaDB
818807
if mysqld.capabilities.isMySQLLike() {
819808
f = FlavorMySQL
820809
}
821-
fn := fmt.Sprintf("mycnf/%s%d%d.cnf", f, mysqld.capabilities.version.Major, mysqld.capabilities.version.Minor)
822-
b, err = riceBox.Bytes(fn)
823-
if err != nil {
824-
log.Infof("this version of Vitess does not include built-in support for %v %v", mysqld.capabilities.flavor, mysqld.capabilities.version)
810+
var versionConfig string
811+
switch f {
812+
case FlavorPercona, FlavorMySQL:
813+
switch mysqld.capabilities.version.Major {
814+
case 5:
815+
if mysqld.capabilities.version.Minor == 7 {
816+
versionConfig = config.MycnfMySQL57
817+
} else {
818+
log.Infof("this version of Vitess does not include built-in support for %v %v", mysqld.capabilities.flavor, mysqld.capabilities.version)
819+
}
820+
case 8:
821+
versionConfig = config.MycnfMySQL80
822+
default:
823+
log.Infof("this version of Vitess does not include built-in support for %v %v", mysqld.capabilities.flavor, mysqld.capabilities.version)
824+
}
825+
case FlavorMariaDB:
826+
switch mysqld.capabilities.version.Minor {
827+
case 0:
828+
versionConfig = config.MycnfMariaDB100
829+
case 1:
830+
versionConfig = config.MycnfMariaDB101
831+
case 2:
832+
versionConfig = config.MycnfMariaDB102
833+
case 3:
834+
versionConfig = config.MycnfMariaDB103
835+
case 4:
836+
versionConfig = config.MycnfMariaDB104
837+
default:
838+
log.Infof("this version of Vitess does not include built-in support for %v %v", mysqld.capabilities.flavor, mysqld.capabilities.version)
839+
}
825840
}
826-
myTemplateSource.Write(b)
841+
842+
myTemplateSource.WriteString(versionConfig)
827843

828844
if extraCnf := os.Getenv("EXTRA_MY_CNF"); extraCnf != "" {
829845
parts := strings.Split(extraCnf, ":")

0 commit comments

Comments
 (0)