diff --git a/Changelog.md b/Changelog.md index b85f90195..12840acb3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 @@ -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. diff --git a/Dockerfile b/Dockerfile index 025e4b8fd..00043d15a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Dockerfile.orchestrator b/Dockerfile.orchestrator index 26648c56e..82e039386 100644 --- a/Dockerfile.orchestrator +++ b/Dockerfile.orchestrator @@ -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 diff --git a/Dockerfile.sidecar b/Dockerfile.sidecar index 003134630..c0bfac7c0 100644 --- a/Dockerfile.sidecar +++ b/Dockerfile.sidecar @@ -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 diff --git a/charts/mysql-cluster/templates/cluster.yaml b/charts/mysql-cluster/templates/cluster.yaml index 2ba4f28eb..cee6c716f 100644 --- a/charts/mysql-cluster/templates/cluster.yaml +++ b/charts/mysql-cluster/templates/cluster.yaml @@ -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 }} diff --git a/charts/mysql-operator/templates/statefulset.yaml b/charts/mysql-operator/templates/statefulset.yaml index 4717e97cd..4749d1f9e 100644 --- a/charts/mysql-operator/templates/statefulset.yaml +++ b/charts/mysql-operator/templates/statefulset.yaml @@ -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 -}} diff --git a/pkg/controller/mysqlcluster/internal/syncer/config_map.go b/pkg/controller/mysqlcluster/internal/syncer/config_map.go index 98d0b6ede..bbae55db6 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/config_map.go +++ b/pkg/controller/mysqlcluster/internal/syncer/config_map.go @@ -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." diff --git a/pkg/orchestrator/orchestrator.go b/pkg/orchestrator/orchestrator.go index 239a92428..21e22a3fb 100644 --- a/pkg/orchestrator/orchestrator.go +++ b/pkg/orchestrator/orchestrator.go @@ -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 diff --git a/pkg/sidecar/appconf.go b/pkg/sidecar/appconf.go index 10a31a86a..b134aa7a1 100644 --- a/pkg/sidecar/appconf.go +++ b/pkg/sidecar/appconf.go @@ -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 @@ -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)) } diff --git a/pkg/sidecar/configs.go b/pkg/sidecar/configs.go index 2299b7e80..5780ea4d1 100644 --- a/pkg/sidecar/configs.go +++ b/pkg/sidecar/configs.go @@ -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 @@ -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), @@ -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