Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Add `backupCompressCommand` and `backupDecompressCommand` to allow using
different compressors/decompressors when backing up or restoring.
* Add support for MySQL version 8.0
* Add `go modules` cache
### Changed
* Only add `binlog-space-limit` for `percona` image
* Make user-defined InitContainer take the precedence
Expand All @@ -36,8 +37,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Set default MySQL server version to `5.7.31`
* Generate CRDs with controller-gen `v0.5.0`
* Update client-go to `v0.20.4`
* Update `getOrdinalFromHostname` and `IsFirstPodInSet`
### Removed
### Fixed
* Fix insufficient permissions during startup
* Fix the `xtrabackup` `--tables-exclude` cannot take effect
* Fix the pod unable to connect `Orchestrator`
* Fix pod labels diff of map
* Fixed backup cleanup job bug (#577)
* Fix Kubebuilder path in Makefile.
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ FROM golang:1.16.0 as builder

# Copy in the go src
WORKDIR /go/src/github.com/presslabs/mysql-operator

COPY go.mod go.sum ./
RUN go mod download

COPY pkg/ pkg/
COPY cmd/ cmd/
COPY go.mod go.sum ./

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o mysql-operator github.com/presslabs/mysql-operator/cmd/mysql-operator
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile.orchestrator
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ FROM golang:1.16.0 as builder

# Copy in the go src
WORKDIR /go/src/github.com/presslabs/mysql-operator

COPY go.mod go.sum ./
RUN go mod download

COPY pkg/ pkg/
COPY cmd/ cmd/
COPY go.mod go.sum ./

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o mysql-operator github.com/presslabs/mysql-operator/cmd/mysql-operator
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ FROM golang:1.16.0 as builder

# Copy in the go src
WORKDIR /go/src/github.com/presslabs/mysql-operator

COPY go.mod go.sum ./
RUN go mod download

COPY pkg/ pkg/
COPY cmd/ cmd/
COPY go.mod go.sum ./

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o mysql-operator github.com/presslabs/mysql-operator/cmd/mysql-operator
Expand Down
8 changes: 4 additions & 4 deletions charts/mysql-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ spec:

{{- if .Values.mysqlConf }}
mysqlConf:
{{ toYaml .Values.mysqlConf | nindent 4 }}
{{- toYaml .Values.mysqlConf | nindent 4 }}
{{- end }}

{{- if .Values.podSpec }}
podSpec:
{{ toYaml .Values.podSpec | nindent 4 }}
{{- toYaml .Values.podSpec | nindent 4 }}
{{- end }}

{{- if .Values.volumeSpec }}
volumeSpec:
{{ toYaml .Values.volumeSpec | nindent 4 }}
{{- toYaml .Values.volumeSpec | nindent 4 }}
{{- end }}

{{- if .Values.initFileExtraSQL }}
initFileExtraSQL:
{{ toYaml .Values.initFileExtraSQL | nindent 4 }}
{{- toYaml .Values.initFileExtraSQL | nindent 6 }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/mysql-operator/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ spec:
args:
- --leader-election-namespace={{ .Release.Namespace }}
# connect to orchestrator on localhost
- --orchestrator-uri=http://127.0.0.1:3000/api
- --orchestrator-uri=http://{{ template "mysql-operator.fullname" . }}.{{ .Release.Namespace }}/api
{{- if .Values.sidecarImage }}
- --sidecar-image={{ .Values.sidecarImage }}
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/mysqlcluster/internal/syncer/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ if [ ${read_only_status} -eq 0 ] && [ ${replica_status_count} -eq 0 ] && [ ${ha
then
masterhostname=$( curl -s "${ORCH_HTTP_API}/master/${ORCH_CLUSTER_ALIAS}" | awk -F":" '{print $3}' | awk -F'"' '{print $2}' )
echo "master from orchestrator: ${masterhostname}"
if [ "${FQDN}" == "${masterhostname}" ]
if [ "${MY_FQDN}" == "${masterhostname}" ]
then
curl -s "${ORCH_HTTP_API}/graceful-master-takeover-auto/${ORCH_CLUSTER_ALIAS}"
echo "graceful-master-takeover-auto is ongoing, sleep 5 seconds in order to make sure service can work well."
Expand Down
2 changes: 1 addition & 1 deletion pkg/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (o *orchestrator) Cluster(cluster string) ([]Instance, error) {
}

func (o *orchestrator) AuditRecovery(cluster string) ([]TopologyRecovery, error) {
path := fmt.Sprintf("audit-recovery/%s", cluster)
path := fmt.Sprintf("audit-recovery/cluster/%s", cluster)
var recoveries []TopologyRecovery
if err := o.makeGetRequest(path, &recoveries); err != nil {
return nil, err
Expand Down
8 changes: 5 additions & 3 deletions pkg/sidecar/appconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func initFileQuery(cfg *Config, gtidPurged string) []byte {
// configure operator utility user
queries = append(queries, createUserQuery(cfg.OperatorUser, cfg.OperatorPassword, "%",
[]string{"SUPER", "SHOW DATABASES", "PROCESS", "RELOAD", "CREATE", "SELECT"}, "*.*",
[]string{"REPLICATION SLAVE"}, "*.*",
[]string{"ALL"}, fmt.Sprintf("%s.*", toolsDbName))...)

// configure orchestrator user
Expand Down Expand Up @@ -195,9 +196,10 @@ func initFileQuery(cfg *Config, gtidPurged string) []byte {
[]string{"CREATE", "SELECT", "DELETE", "UPDATE", "INSERT"}, fmt.Sprintf("%s.%s", toolsDbName, toolsHeartbeatTableName),
[]string{"REPLICATION CLIENT"}, "*.*")...)

// the slave pod doesn't need to back up sys_operator.status, Xtrabackup might have some bugs that
// cause the table to be unclean. We can do this cleanup before the slave pod starts to avoid accidents.
if !cfg.IsFirstPodInSet() {
// when the status.ibd file does not exist
// need to delete the status table
_, err := os.Stat(path.Join(dataDir, constants.OperatorDbName, constants.OperatorStatusTableName+".ibd"))
if os.IsNotExist(err) {
queries = append(queries, fmt.Sprintf("DROP TABLE IF EXISTS %s.%s",
constants.OperatorDbName, constants.OperatorStatusTableName))
}
Expand Down
23 changes: 11 additions & 12 deletions pkg/sidecar/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ func (cfg *Config) MysqlDSN() string {

// IsFirstPodInSet returns true if this pod has an ordinal of 0, meaning it is the first one in the set
func (cfg *Config) IsFirstPodInSet() bool {
ordinal := getOrdinalFromHostname(cfg.Hostname)
return ordinal == 0
return getOrdinalFromHostname(cfg.Hostname) == 0
}

// ShouldCloneFromBucket returns true if it's time to initialize from a bucket URL provided
Expand Down Expand Up @@ -198,7 +197,7 @@ func (cfg *Config) XtrabackupArgs() []string {
"--backup",
"--slave-info",
"--stream=xbstream",
fmt.Sprintf("--tables-exclude=%s.%s", constants.OperatorDbName, constants.OperatorStatusTableName),
fmt.Sprintf("--tables-exclude=%s\\.%s", constants.OperatorDbName, constants.OperatorStatusTableName),
"--host=127.0.0.1",
fmt.Sprintf("--user=%s", cfg.ReplicationUser),
fmt.Sprintf("--password=%s", cfg.ReplicationPassword),
Expand Down Expand Up @@ -303,17 +302,17 @@ func getEnvValue(key string) string {
}

func getOrdinalFromHostname(hn string) int {
// mysql-master-1
// or
// stateful-ceva-3
l := strings.Split(hn, "-")
for i := len(l) - 1; i >= 0; i-- {
if o, err := strconv.ParseInt(l[i], 10, 8); err == nil {
return int(o)
}
begin := strings.LastIndex(hn, "-")
if begin < 0 {
return 0
}
index := hn[begin+1:]
o, err := strconv.Atoi(index)
if err != nil {
return -1
}

return 0
return o
}

// retryLookupHost tries to figure out a host IPs with retries
Expand Down