diff --git a/api/v1alpha1/perconaservermysql_types.go b/api/v1alpha1/perconaservermysql_types.go index da1b5b3e8..a0cfeca9c 100644 --- a/api/v1alpha1/perconaservermysql_types.go +++ b/api/v1alpha1/perconaservermysql_types.go @@ -24,6 +24,7 @@ import ( "strings" cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1" + "gopkg.in/ini.v1" "github.com/percona/percona-server-mysql-operator/pkg/platform" "github.com/percona/percona-server-mysql-operator/pkg/version" @@ -950,3 +951,20 @@ const ( UpgradeStrategyRecommended = "recommended" UpgradeStrategyLatest = "latest" ) + +// MySQLConfigHasKey check if cr.Spec.MySQL.Configuration has given key in given section +func (cr *PerconaServerMySQL) MySQLConfigHasKey(section, key string) (bool, error) { + file, err := ini.LoadSources(ini.LoadOptions{AllowBooleanKeys: true}, []byte(cr.Spec.MySQL.Configuration)) + if err != nil { + return false, errors.Wrap(err, "load configuration") + } + + s, err := file.GetSection(section) + if err != nil && strings.Contains(err.Error(), "does not exist") { + return false, nil + } else if err != nil { + return false, errors.Wrap(err, "get section") + } + + return s.HasKey(key), nil +} diff --git a/build/ps-entrypoint.sh b/build/ps-entrypoint.sh index 78a6053b1..51fe286f9 100755 --- a/build/ps-entrypoint.sh +++ b/build/ps-entrypoint.sh @@ -153,6 +153,7 @@ create_default_cnf() { echo '[mysqld]' >$CFG sed -i "/\[mysqld\]/a read_only=ON" $CFG sed -i "/\[mysqld\]/a server_id=${SERVER_ID}" $CFG + sed -i "/\[mysqld\]/a bind_address=${POD_IP}" $CFG sed -i "/\[mysqld\]/a admin-address=${POD_IP}" $CFG sed -i "/\[mysqld\]/a report_host=${FQDN}" $CFG sed -i "/\[mysqld\]/a report_port=3306" $CFG diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index 19b4a9f45..9107302cd 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -9,6 +9,11 @@ import ( "github.com/percona/percona-server-mysql-operator/pkg/mysql" ) +var ( + GitCommit string + BuildTime string +) + const ( fullClusterCrashFile = "/var/lib/mysql/full-cluster-crash" manualRecoveryFile = "/var/lib/mysql/sleep-forever" @@ -22,6 +27,8 @@ func main() { defer f.Close() log.SetOutput(f) + log.Printf("starting bootstrap... GitCommit: %s BuildTime: %s", GitCommit, BuildTime) + fullClusterCrash, err := fileExists(fullClusterCrashFile) if err == nil && fullClusterCrash { log.Printf("%s exists. exiting...", fullClusterCrashFile) diff --git a/go.mod b/go.mod index 965a45065..4f933726c 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( ) require ( + github.com/go-ini/ini v1.67.0 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect diff --git a/go.sum b/go.sum index cfaff3132..f60e2941a 100644 --- a/go.sum +++ b/go.sum @@ -56,6 +56,8 @@ github.com/evanphx/json-patch/v5 v5.8.0 h1:lRj6N9Nci7MvzrXuX6HFzU8XjmhPiXPlsKEy1 github.com/evanphx/json-patch/v5 v5.8.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3 h1:fmFk0Wt3bBxxwZnu48jqMdaOR/IZ4vdtJFuaFV8MpIE= github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3/go.mod h1:bJWSKrZyQvfTnb2OudyUjurSG4/edverV7n82+K3JiM= +github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= +github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= diff --git a/pkg/haproxy/haproxy.go b/pkg/haproxy/haproxy.go index 9af536637..d076e235b 100644 --- a/pkg/haproxy/haproxy.go +++ b/pkg/haproxy/haproxy.go @@ -348,6 +348,14 @@ func mysqlMonitContainer(cr *apiv1alpha1.PerconaServerMySQL) corev1.Container { } env = append(env, spec.Env...) + proxyProtocolEnabled, err := cr.MySQLConfigHasKey("", "proxy_protocol_networks") + if err == nil && proxyProtocolEnabled { + env = append(env, corev1.EnvVar{ + Name: "IS_PROXY_PROTOCOL", + Value: "yes", + }) + } + return corev1.Container{ Name: "mysql-monit", Image: spec.Image,