@@ -22,16 +22,15 @@ import (
22
22
"sort"
23
23
"strings"
24
24
25
+ "github.com/bitpoke/mysql-operator/pkg/internal/mysqlcluster"
26
+ "github.com/blang/semver"
25
27
"github.com/go-ini/ini"
28
+ "github.com/presslabs/controller-util/syncer"
26
29
core "k8s.io/api/core/v1"
27
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
31
"k8s.io/apimachinery/pkg/runtime"
29
32
"k8s.io/apimachinery/pkg/util/intstr"
30
33
"sigs.k8s.io/controller-runtime/pkg/client"
31
-
32
- "github.com/presslabs/controller-util/syncer"
33
-
34
- "github.com/bitpoke/mysql-operator/pkg/internal/mysqlcluster"
35
34
)
36
35
37
36
// NewConfigMapSyncer returns config map syncer
96
95
func buildMysqlConfData (cluster * mysqlcluster.MysqlCluster ) (string , error ) {
97
96
cfg := ini .Empty ()
98
97
sec := cfg .Section ("mysqld" )
99
-
100
- if cluster . GetMySQLSemVer () .Major == 5 {
98
+ version := cluster . GetMySQLSemVer ()
99
+ if version .Major == 5 {
101
100
addKVConfigsToSection (sec , convertMapToKVConfig (mysql5xConfigs ))
102
- } else if cluster . GetMySQLSemVer () .Major == 8 {
101
+ } else if version .Major == 8 {
103
102
addKVConfigsToSection (sec , convertMapToKVConfig (mysql8xConfigs ))
104
103
}
105
104
106
105
// boolean configs
107
106
addBConfigsToSection (sec , mysqlMasterSlaveBooleanConfigs )
107
+ addSkipHostCacheByVersion (sec , version )
108
+ addReplicationRepositoryByVersion (sec , version )
108
109
// add custom configs, would overwrite common configs
109
110
addKVConfigsToSection (sec , convertMapToKVConfig (mysqlCommonConfigs ), cluster .Spec .MysqlConf )
110
111
@@ -170,6 +171,39 @@ func addBConfigsToSection(s *ini.Section, boolConfigs ...[]string) {
170
171
}
171
172
}
172
173
174
+ func addSkipHostCacheByVersion (s * ini.Section , version semver.Version ) {
175
+ // cannot find which version exactly removes the --skip-host-cache option
176
+ // but in https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html, it is deprecated.
177
+ if version .GTE (semver .MustParse ("8.0.30" )) {
178
+ // set host_cache_size to 0 for backward compatibility
179
+ _ , err := s .NewKey ("host_cache_size " , "0" )
180
+ if err != nil {
181
+ log .Error (err , "failed to add key to config section" , "key" , "host_cache_size" , "value" , "0" )
182
+ }
183
+ } else {
184
+ _ , err := s .NewBooleanKey ("skip-host-cache" )
185
+ if err != nil {
186
+ log .Error (err , "failed to add boolean key to config section" , "key" , "skip-host-cache" )
187
+ }
188
+ }
189
+ }
190
+
191
+ func addReplicationRepositoryByVersion (s * ini.Section , version semver.Version ) {
192
+ // https://dev.mysql.com/doc/relnotes/mysql/8.3/en/news-8-3-0.html
193
+ if version .LT (semver .MustParse ("8.3.0" )) {
194
+ _ , err := s .NewKey ("relay-log-info-repository" , "TABLE" )
195
+ if err != nil {
196
+ log .Error (err , "failed to add key to config section" , "key" , "relay-log-info-repository" , "value" , "TABLE" )
197
+ }
198
+
199
+ // https://github.com/github/orchestrator/issues/323#issuecomment-338451838
200
+ _ , err = s .NewKey ("master-info-repository" , "TABLE" )
201
+ if err != nil {
202
+ log .Error (err , "failed to add key to config section" , "key" , "master-info-repository" , "value" , "TABLE" )
203
+ }
204
+ }
205
+ }
206
+
173
207
// helper function to write to string ini.File
174
208
// nolint: interfacer
175
209
func writeConfigs (cfg * ini.File ) (string , error ) {
@@ -191,11 +225,7 @@ var mysqlCommonConfigs = map[string]string{
191
225
"skip-slave-start" : "on" ,
192
226
193
227
// Crash safe
194
- "relay-log-info-repository" : "TABLE" ,
195
- "relay-log-recovery" : "on" ,
196
-
197
- // https://github.com/github/orchestrator/issues/323#issuecomment-338451838
198
- "master-info-repository" : "TABLE" ,
228
+ "relay-log-recovery" : "on" ,
199
229
200
230
"default-storage-engine" : "InnoDB" ,
201
231
"gtid-mode" : "on" ,
@@ -256,5 +286,4 @@ var mysql8xConfigs = map[string]string{
256
286
var mysqlMasterSlaveBooleanConfigs = []string {
257
287
// Safety
258
288
"skip-name-resolve" ,
259
- "skip-host-cache" ,
260
289
}
0 commit comments