Skip to content

Commit

Permalink
Merge pull request #92 from vsliouniaev/main
Browse files Browse the repository at this point in the history
Option to to use localhost instead of pod name
  • Loading branch information
zoetrope authored May 17, 2024
2 parents 758daa3 + 0682c13 commit e0f8fc9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cmd/moco-agent/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var config struct {
socketPath string
grpcCertDir string
transactionQueueingWait time.Duration
mysqldLocalHost bool
}

type mysqlLogger struct{}
Expand Down Expand Up @@ -108,6 +109,11 @@ var rootCmd = &cobra.Command{
ConnectionTimeout: config.connectionTimeout,
ReadTimeout: config.readTimeout,
}

if config.mysqldLocalHost {
conf.Host = "localhost"
}

agent, err := server.New(conf, clusterName, config.socketPath, mocoagent.VarLogPath,
config.maxDelayThreshold, config.transactionQueueingWait, rLogger.WithName("agent"))
if err != nil {
Expand Down Expand Up @@ -238,6 +244,7 @@ func init() {
fs.StringVar(&config.socketPath, "socket-path", socketPathDefault, "Path of mysqld socket file.")
fs.StringVar(&config.grpcCertDir, "grpc-cert-dir", "/grpc-cert", "gRPC certificate directory")
fs.DurationVar(&config.transactionQueueingWait, "transaction-queueing-wait", time.Minute, "The maximum amount of time for waiting transaction queueing on replica")
fs.BoolVar(&config.mysqldLocalHost, "mysqld-localhost", false, "If true, access mysqld on localhost instead of pod name")
}

func initializeMySQLForMOCO(ctx context.Context, socketPath string, logger logr.Logger) error {
Expand Down
10 changes: 8 additions & 2 deletions cmd/moco-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var config struct {
lowerCaseTableNames int
visitedLowerCaseTableNames *int

mysqldLocalhost bool

podName string
baseID uint32
podIndex uint32
Expand Down Expand Up @@ -162,13 +164,16 @@ func initMySQL(mysqld string) error {

func createConf() error {
tmpl := template.Must(template.New("my.cnf").Parse(mycnfTmpl))

adminAddress := config.podName
if config.mysqldLocalhost {
adminAddress = "localhost"
}
v := struct {
ServerID uint32
AdminAddress string
}{
ServerID: config.baseID + config.podIndex,
AdminAddress: config.podName,
AdminAddress: adminAddress,
}

f, err := os.OpenFile(filepath.Join(config.confDir, "my.cnf"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
Expand Down Expand Up @@ -202,4 +207,5 @@ func init() {
// On Unix, the default value of lower_case_table_names is 0.
// https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html
rootCmd.Flags().IntVar(&config.lowerCaseTableNames, "lower-case-table-names", 0, "The value to pass to the '--lower-case-table-names' flag.")
rootCmd.Flags().BoolVar(&config.mysqldLocalhost, "mysqld-localhost", false, "If true, bind mysqld admin to localhost instead of pod name")
}

0 comments on commit e0f8fc9

Please sign in to comment.