Skip to content

Commit

Permalink
Merge branch 'main' into fix-monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hors authored Jul 10, 2024
2 parents 85f5ef6 + 7037956 commit bf056cd
Show file tree
Hide file tree
Showing 170 changed files with 4,909 additions and 1,015 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* @hors @egegunes @inelpandzic @pooknull
/e2e-tests/ @tplavcic @nmarukovich @ptankov
Jenkinsfile @tplavcic @nmarukovich @ptankov
/e2e-tests/ @tplavcic @nmarukovich @ptankov @jvpasinatto @eleo007
Jenkinsfile @tplavcic @nmarukovich @ptankov @jvpasinatto @eleo007
11 changes: 9 additions & 2 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
with:
go-version: '1.21'
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: latest
only-new-issues: true
Expand Down Expand Up @@ -86,6 +86,13 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- run: |
- name: check on release branch
if: ${{ contains(github.head_ref, 'release-') || contains(github.base_ref, 'release-') }}
run: |
make generate manifests VERSION="$(grep "Version" version/version.go|grep -oE "[0-9]+\.[0-9]+\.[0-9]+")" IMAGE_TAG_BASE="percona/percona-xtradb-cluster-operator"
git diff --exit-code
- name: check on non release branches
if: ${{ ! (contains(github.head_ref, 'release-') || contains(github.base_ref, 'release-')) }}
run: |
make generate manifests VERSION=main
git diff --exit-code
4 changes: 2 additions & 2 deletions .github/workflows/scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
./e2e-tests/build
- name: Run Trivy vulnerability scanner image (linux/arm64)
uses: aquasecurity/trivy-action@0.19.0
uses: aquasecurity/trivy-action@0.23.0
with:
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64'
format: 'table'
Expand All @@ -49,7 +49,7 @@ jobs:
./e2e-tests/build
- name: Run Trivy vulnerability scanner image (linux/amd64)
uses: aquasecurity/trivy-action@0.19.0
uses: aquasecurity/trivy-action@0.23.0
with:
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64'
format: 'table'
Expand Down
11 changes: 4 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,8 @@ pipeline {
curl -fsSL https://get.helm.sh/helm-v3.12.3-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm
sudo sh -c "curl -s -L https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64 > /usr/local/bin/yq"
sudo chmod +x /usr/local/bin/yq
sudo sh -c "curl -s -L https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64 > /usr/local/bin/jq"
sudo chmod +x /usr/local/bin/jq
sudo curl -fsSL https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64 -o /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq
sudo curl -fsSL https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux64 -o /usr/local/bin/jq && sudo chmod +x /usr/local/bin/jq
sudo tee /etc/yum.repos.d/google-cloud-sdk.repo << EOF
[google-cloud-cli]
Expand Down Expand Up @@ -364,7 +361,7 @@ EOF
--rm \
-v $WORKSPACE/src/github.com/percona/percona-xtradb-cluster-operator:/go/src/github.com/percona/percona-xtradb-cluster-operator \
-w /go/src/github.com/percona/percona-xtradb-cluster-operator \
golang:1.21 sh -c '
golang:1.22 sh -c '
go install -mod=readonly github.com/google/go-licenses@latest;
/go/bin/go-licenses csv github.com/percona/percona-xtradb-cluster-operator/cmd/manager \
| cut -d , -f 3 \
Expand Down Expand Up @@ -393,7 +390,7 @@ EOF
-w /go/src/github.com/percona/percona-xtradb-cluster-operator \
-e GO111MODULE=on \
-e GOFLAGS='-buildvcs=false' \
golang:1.21 sh -c 'go build -v -o percona-xtradb-cluster-operator github.com/percona/percona-xtradb-cluster-operator/cmd/manager'
golang:1.22 sh -c 'go build -v -o percona-xtradb-cluster-operator github.com/percona/percona-xtradb-cluster-operator/cmd/manager'
"
'''

Expand Down
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
NAME ?= percona-xtradb-cluster-operator
IMAGE_TAG_OWNER ?= perconalab
IMAGE_TAG_BASE ?= $(IMAGE_TAG_OWNER)/$(NAME)
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD | sed -e 's^/^-^g; s^[.]^-^g;' | tr '[:upper:]' '[:lower:]')
SED := $(shell which gsed || which sed)
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD | $(SED) -e 's^/^-^g; s^[.]^-^g;' | tr '[:upper:]' '[:lower:]')
IMAGE ?= $(IMAGE_TAG_BASE):$(VERSION)
DEPLOYDIR = ./deploy

Expand All @@ -22,11 +23,11 @@ $(DEPLOYDIR)/crd.yaml: kustomize generate

.PHONY: $(DEPLOYDIR)/operator.yaml
$(DEPLOYDIR)/operator.yaml:
sed -i "/^ containers:/,/^ image:/{s#image: .*#image: $(IMAGE_TAG_BASE):$(VERSION)#}" deploy/operator.yaml
$(SED) -i "/^ containers:/,/^ image:/{s#image: .*#image: $(IMAGE_TAG_BASE):$(VERSION)#}" deploy/operator.yaml

.PHONY: $(DEPLOYDIR)/cw-operator.yaml
$(DEPLOYDIR)/cw-operator.yaml:
sed -i "/^ containers:/,/^ image:/{s#image: .*#image: $(IMAGE_TAG_BASE):$(VERSION)#}" deploy/cw-operator.yaml
$(SED) -i "/^ containers:/,/^ image:/{s#image: .*#image: $(IMAGE_TAG_BASE):$(VERSION)#}" deploy/cw-operator.yaml

$(DEPLOYDIR)/bundle.yaml: $(DEPLOYDIR)/crd.yaml $(DEPLOYDIR)/rbac.yaml $(DEPLOYDIR)/operator.yaml ## Generate deploy/bundle.yaml
cat $(DEPLOYDIR)/crd.yaml > $(DEPLOYDIR)/bundle.yaml; echo "---" >> $(DEPLOYDIR)/bundle.yaml; cat $(DEPLOYDIR)/rbac.yaml >> $(DEPLOYDIR)/bundle.yaml; echo "---" >> $(DEPLOYDIR)/bundle.yaml; cat $(DEPLOYDIR)/operator.yaml >> $(DEPLOYDIR)/bundle.yaml
Expand Down Expand Up @@ -87,7 +88,7 @@ endef

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
Expand All @@ -100,14 +101,14 @@ envtest: ## Download envtest-setup locally if necessary.
# Prepare release
CERT_MANAGER_VER := $(shell grep -Eo "cert-manager v.*" go.mod|grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
release: manifests
sed -i "/CERT_MANAGER_VER/s/CERT_MANAGER_VER=\".*/CERT_MANAGER_VER=\"$(CERT_MANAGER_VER)\"/" e2e-tests/functions
sed -i "/Version = \"/s/Version = \".*/Version = \"$(VERSION)\"/" version/version.go
sed -i \
$(SED) -i "/CERT_MANAGER_VER/s/CERT_MANAGER_VER=\".*/CERT_MANAGER_VER=\"$(CERT_MANAGER_VER)\"/" e2e-tests/functions
$(SED) -i "/Version = \"/s/Version = \".*/Version = \"$(VERSION)\"/" version/version.go
$(SED) -i \
-e "s/crVersion: .*/crVersion: $(VERSION)/" \
-e "/^ pxc:/,/^ image:/{s#image: .*#image: percona/percona-xtradb-cluster:@@SET_TAG@@#}" \
-e "/^ haproxy:/,/^ image:/{s#image: .*#image: percona/percona-xtradb-cluster-operator:$(VERSION)-haproxy#}" \
-e "/^ logcollector:/,/^ image:/{s#image: .*#image: percona/percona-xtradb-cluster-operator:$(VERSION)-logcollector#}" deploy/cr-minimal.yaml
sed -i \
$(SED) -i \
-e "s/crVersion: .*/crVersion: $(VERSION)/" \
-e "/^ pxc:/,/^ image:/{s#image: .*#image: percona/percona-xtradb-cluster:@@SET_TAG@@#}" \
-e "/^ haproxy:/,/^ image:/{s#image: .*#image: percona/percona-xtradb-cluster-operator:$(VERSION)-haproxy#}" \
Expand All @@ -122,13 +123,13 @@ MAJOR_VER := $(shell grep -oE "crVersion: .*" deploy/cr.yaml|grep -oE "[0-9]+\.[
MINOR_VER := $(shell grep -oE "crVersion: .*" deploy/cr.yaml|grep -oE "[0-9]+\.[0-9]+\.[0-9]+"|cut -d'.' -f2)
NEXT_VER ?= $(MAJOR_VER).$$(($(MINOR_VER) + 1)).0
after-release: manifests
sed -i "/Version = \"/s/Version = \".*/Version = \"$(NEXT_VER)\"/" version/version.go
sed -i \
$(SED) -i "/Version = \"/s/Version = \".*/Version = \"$(NEXT_VER)\"/" version/version.go
$(SED) -i \
-e "s/crVersion: .*/crVersion: $(NEXT_VER)/" \
-e "/^ pxc:/,/^ image:/{s#image: .*#image: perconalab/percona-xtradb-cluster-operator:main-pxc8.0#}" \
-e "/^ haproxy:/,/^ image:/{s#image: .*#image: perconalab/percona-xtradb-cluster-operator:main-haproxy#}" \
-e "/^ logcollector:/,/^ image:/{s#image: .*#image: perconalab/percona-xtradb-cluster-operator:main-logcollector#}" deploy/cr-minimal.yaml
sed -i \
$(SED) -i \
-e "s/crVersion: .*/crVersion: $(NEXT_VER)/" \
-e "/^ pxc:/,/^ image:/{s#image: .*#image: perconalab/percona-xtradb-cluster-operator:main-pxc8.0#}" \
-e "/^ haproxy:/,/^ image:/{s#image: .*#image: perconalab/percona-xtradb-cluster-operator:main-haproxy#}" \
Expand Down
15 changes: 12 additions & 3 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${BUILDPLATFORM} golang:1.21 AS go_builder
FROM --platform=${BUILDPLATFORM} golang:1.22 AS go_builder
WORKDIR /go/src/github.com/percona/percona-xtradb-cluster-operator

COPY go.mod go.sum ./
Expand All @@ -21,8 +21,14 @@ RUN mkdir -p build/_output/bin \
cmd/manager/main.go \
&& cp -r build/_output/bin/percona-xtradb-cluster-operator /usr/local/bin/percona-xtradb-cluster-operator

RUN go build -o build/_output/bin/peer-list cmd/peer-list/main.go \
&& cp -r build/_output/bin/peer-list /usr/local/bin/
RUN GOOS=$GOOS GOARCH=${TARGETARCH} CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
go build -o build/_output/bin/peer-list cmd/peer-list/main.go \
&& cp -r build/_output/bin/peer-list /usr/local/bin/peer-list

RUN GOOS=$GOOS GOARCH=${TARGETARCH} CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
go build -o build/_output/bin/pitr \
cmd/pitr/main.go \
&& cp -r build/_output/bin/pitr /usr/local/bin/pitr

# Looking for all possible License/Notice files and copying them to the image
RUN find $GOPATH/pkg/mod -regextype posix-extended -iregex '.*(license|notice)(\.md|\.txt|$)' \
Expand All @@ -42,8 +48,11 @@ LABEL name="Percona XtraDB Cluster Operator" \
COPY LICENSE /licenses/
COPY --from=go_builder /usr/local/bin/percona-xtradb-cluster-operator /usr/local/bin/percona-xtradb-cluster-operator
COPY --from=go_builder /usr/local/bin/peer-list /peer-list
COPY --from=go_builder /usr/local/bin/pitr /pitr
COPY build/pxc-entrypoint.sh /pxc-entrypoint.sh
COPY build/pxc-init-entrypoint.sh /pxc-init-entrypoint.sh
COPY build/pitr-init-entrypoint.sh /pitr-init-entrypoint.sh
COPY build/backup-init-entrypoint.sh /backup-init-entrypoint.sh
COPY build/unsafe-bootstrap.sh /unsafe-bootstrap.sh
COPY build/pxc-configure-pxc.sh /pxc-configure-pxc.sh
COPY build/liveness-check.sh /liveness-check.sh
Expand Down
6 changes: 6 additions & 0 deletions build/backup-init-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -o errexit
set -o xtrace

install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /peer-list /opt/percona/peer-list
7 changes: 7 additions & 0 deletions build/pitr-init-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -o errexit
set -o xtrace

install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /pitr /opt/percona/pitr
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /peer-list /opt/percona/peer-list
2 changes: 1 addition & 1 deletion build/pxc-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ if [ -z "$CLUSTER_JOIN" ] && [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
GRANT ALL ON *.* TO 'operator'@'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ;
CREATE USER 'xtrabackup'@'%' IDENTIFIED BY '$(escape_special "${XTRABACKUP_PASSWORD}")' PASSWORD EXPIRE NEVER;
GRANT ALL ON *.* TO 'xtrabackup'@'%';
GRANT ALL ON *.* TO 'xtrabackup'@'%' WITH GRANT OPTION ;
CREATE USER 'monitor'@'${MONITOR_HOST}' IDENTIFIED BY '$(escape_special "${MONITOR_PASSWORD}")' WITH MAX_USER_CONNECTIONS 100 PASSWORD EXPIRE NEVER;
GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'monitor'@'${MONITOR_HOST}';
Expand Down
17 changes: 17 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"os"
"runtime"
Expand All @@ -13,11 +14,13 @@ import (
"github.com/go-logr/logr"
uzap "go.uber.org/zap"
"go.uber.org/zap/zapcore"
eventsv1 "k8s.io/api/events/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsServer "sigs.k8s.io/controller-runtime/pkg/metrics/server"
Expand Down Expand Up @@ -162,6 +165,20 @@ func main() {
os.Exit(1)
}

err = mgr.GetFieldIndexer().IndexField(
context.Background(),
&eventsv1.Event{},
"regarding.name",
func(rawObj client.Object) []string {
event := rawObj.(*eventsv1.Event)
return []string{event.Regarding.Name}
},
)
if err != nil {
setupLog.Error(err, "unable to index field")
os.Exit(1)
}

setupLog.Info("Starting the Cmd.")

ctx := k8s.StartStopSignalHandler(mgr.GetClient(), strings.Split(namespace, ","))
Expand Down
4 changes: 2 additions & 2 deletions cmd/pitr/pxc/pxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (p *PXC) GetHost() string {

// GetGTIDSet return GTID set by binary log file name
func (p *PXC) GetGTIDSet(ctx context.Context, binlogName string) (string, error) {
//select name from mysql.func where name='get_gtid_set_by_binlog'
// select name from mysql.func where name='get_gtid_set_by_binlog'
var existFunc string
nameRow := p.db.QueryRowContext(ctx, "select name from mysql.func where name='get_gtid_set_by_binlog'")
err := nameRow.Scan(&existFunc)
Expand Down Expand Up @@ -226,7 +226,7 @@ func (p *PXC) SubtractGTIDSet(ctx context.Context, set, subSet string) (string,
}

func getNodesByServiceName(ctx context.Context, pxcServiceName string) ([]string, error) {
cmd := exec.CommandContext(ctx, "peer-list", "-on-start=/usr/bin/get-pxc-state", "-service="+pxcServiceName)
cmd := exec.CommandContext(ctx, "/opt/percona/peer-list", "-on-start=/usr/bin/get-pxc-state", "-service="+pxcServiceName)
out, err := cmd.CombinedOutput()
if err != nil {
return nil, errors.Wrap(err, "get peer-list output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.15.0
name: perconaxtradbclusterbackups.pxc.percona.com
spec:
group: pxc.percona.com
Expand Down Expand Up @@ -89,12 +88,14 @@ spec:
key:
type: string
name:
default: ""
type: string
optional:
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
fieldRef:
properties:
apiVersion:
Expand All @@ -104,6 +105,7 @@ spec:
required:
- fieldPath
type: object
x-kubernetes-map-type: atomic
resourceFieldRef:
properties:
containerName:
Expand All @@ -119,17 +121,20 @@ spec:
required:
- resource
type: object
x-kubernetes-map-type: atomic
secretKeyRef:
properties:
key:
type: string
name:
default: ""
type: string
optional:
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
required:
- name
Expand Down Expand Up @@ -234,9 +239,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.15.0
name: perconaxtradbclusterrestores.pxc.percona.com
spec:
group: pxc.percona.com
Expand Down Expand Up @@ -167,12 +166,14 @@ spec:
key:
type: string
name:
default: ""
type: string
optional:
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
fieldRef:
properties:
apiVersion:
Expand All @@ -182,6 +183,7 @@ spec:
required:
- fieldPath
type: object
x-kubernetes-map-type: atomic
resourceFieldRef:
properties:
containerName:
Expand All @@ -197,17 +199,20 @@ spec:
required:
- resource
type: object
x-kubernetes-map-type: atomic
secretKeyRef:
properties:
key:
type: string
name:
default: ""
type: string
optional:
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
required:
- name
Expand Down Expand Up @@ -363,9 +368,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading

0 comments on commit bf056cd

Please sign in to comment.