@@ -22,16 +22,15 @@ import (
2222 "sort"
2323 "strings"
2424
25+ "github.com/bitpoke/mysql-operator/pkg/internal/mysqlcluster"
26+ "github.com/blang/semver"
2527 "github.com/go-ini/ini"
28+ "github.com/presslabs/controller-util/syncer"
2629 core "k8s.io/api/core/v1"
2730 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2831 "k8s.io/apimachinery/pkg/runtime"
2932 "k8s.io/apimachinery/pkg/util/intstr"
3033 "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"
3534)
3635
3736// NewConfigMapSyncer returns config map syncer
9695func buildMysqlConfData (cluster * mysqlcluster.MysqlCluster ) (string , error ) {
9796 cfg := ini .Empty ()
9897 sec := cfg .Section ("mysqld" )
99-
100- if cluster . GetMySQLSemVer () .Major == 5 {
98+ version := cluster . GetMySQLSemVer ()
99+ if version .Major == 5 {
101100 addKVConfigsToSection (sec , convertMapToKVConfig (mysql5xConfigs ))
102- } else if cluster . GetMySQLSemVer () .Major == 8 {
101+ } else if version .Major == 8 {
103102 addKVConfigsToSection (sec , convertMapToKVConfig (mysql8xConfigs ))
104103 }
105104
106105 // boolean configs
107106 addBConfigsToSection (sec , mysqlMasterSlaveBooleanConfigs )
107+ addSkipHostCacheByVersion (sec , version )
108+ addReplicationRepositoryByVersion (sec , version )
108109 // add custom configs, would overwrite common configs
109110 addKVConfigsToSection (sec , convertMapToKVConfig (mysqlCommonConfigs ), cluster .Spec .MysqlConf )
110111
@@ -170,6 +171,39 @@ func addBConfigsToSection(s *ini.Section, boolConfigs ...[]string) {
170171 }
171172}
172173
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+
173207// helper function to write to string ini.File
174208// nolint: interfacer
175209func writeConfigs (cfg * ini.File ) (string , error ) {
@@ -191,11 +225,7 @@ var mysqlCommonConfigs = map[string]string{
191225 "skip-slave-start" : "on" ,
192226
193227 // 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" ,
199229
200230 "default-storage-engine" : "InnoDB" ,
201231 "gtid-mode" : "on" ,
@@ -256,5 +286,4 @@ var mysql8xConfigs = map[string]string{
256286var mysqlMasterSlaveBooleanConfigs = []string {
257287 // Safety
258288 "skip-name-resolve" ,
259- "skip-host-cache" ,
260289}
0 commit comments