Repository: percona/percona-server-mongodb-operator

Issue:
[FEAT]: Arm64 support
This is written in Go, it should be 1h tops to add arm64 support to the container image. Please do this.

Discussion:
@spron-in: Hey @aleksasiriski - having operator itself in ARM is easy. But there are other components: mongodb itself, percona monitoring and management, backup tooling. We need to have these containers as ARM as well.

Or maybe I misunderstood and for some reason you need operator image only. Please let me know.

Anyway, we have it in our roadmap and it might come out in Q1'24.

@spron-in: @aleksasiriski shall we close this or do you want to keep it open till we have ARM builds for Percona Server for MongoDB and Backup (PBM)?@aleksasiriski: However you want it, if those other components have their own repos than this issue shouldn't be linked to them IMO. Thank you for pushing for ARM64 support, hope it gets fully supported ASAP.@sasikanthlanka: @aleksasiriski Both [percona-server-mongodb](https://hub.docker.com/r/percona/percona-server-mongodb/tags?page=1&name=6.0.9-7) as well as [percona-backup-mongodb](https://hub.docker.com/r/perconalab/percona-backup-mongodb/tags?page=1&name=2.3.0) now have support arm64. It's only missing in the operator. 

Wouldn't this [pr-1356](https://github.com/percona/percona-server-mongodb-operator/pull/1356/files) support it now? How about a 1.16 release?



@aleksasiriski: +1 For the new release of operator with support for Arm :D@Coennie: any progress news on the 1.16 release? Would really love to get arm supported@DevBey: Hello @Coennie, 

1.16 is out now I believe.

https://docs.percona.com/percona-operator-for-mongodb/RN/Kubernetes-Operator-for-PSMONGODB-RN1.16.0.html#support-for-arm-architecture-technical-preview

thought I am not sure why this is in technical preview?? 
are there still issues with using this in production ?? 
@spron-in ?? @DevBey: please avoid currently upgrading and moving to arm, 

we found out the hard way that currently pmm client doesn't support arm yet. 

https://hub.docker.com/r/percona/pmm-client/tags


https://perconadev.atlassian.net/browse/PMM-11932@qm3ster: Running operator via helm on aarch64 (Oracle Cloud Infrastructure) and it tries to run x86_64 `mongod` :sob:

fixed that with `--set image.tag="7.0.8-5-multi"` (same tag as it was already using, but the multiarch manifest. No idea why this isn't the default)

However, now `backup-agent` is the one failing, and looking in [the tags](https://hub.docker.com/r/perconalab/percona-server-mongodb-operator/tags) there doesn't seem to be a similar solution for [`backup.image`](https://github.com/percona/percona-server-mongodb-operator/blob/334ec86ff2788a6b9b636e1d251335f172e6ea66/deploy/cr.yaml#L554-L556)


Also, lifehack:
```sh
kubectl -n percona-mongodb patch perconaservermongodb.psmdb.percona.com/butthole-mongodb-psmdb-db -p '{"metadata":{"finalizers":[]}}' --type=merge
```
helps when deleting your namespace/release deadlocks because it wants to do something in the unexecable containers@spron-in: Hey all. Sorry for not updating this thread :)

Updates: ARM support was added in 1.16 in tech preview.
PMM client does not support ARM yet, it is true. For users who are using PMM, please wait till PMM is released in Q3/Q4.

@DevBey "thought I am not sure why this is in technical preview??"
It is in tech preview as we need to capture more feedback. We keep high blast radius features in tech preview for at least one release. And there are multiple questions about ARM, which tells me we still have more work to do.

@aleksasiriski it is in 1.16.

Regarding -multi tag - in the following releases of Percona Server for MongoDB and Percona Backup for MongoDB there will be no need to use `-multi` tag for ARM, as we will make both images multi-arch.

Some details regarding using -multi were discussed here: https://forums.percona.com/t/mongo-operator-and-arm/24326/7

@qm3ster it might help with your problem as well.





Solution patch:
diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml
index 18eb497f..dc27cef9 100644
--- a/.github/workflows/reviewdog.yml
+++ b/.github/workflows/reviewdog.yml
@@ -30,7 +30,7 @@ jobs:
       - uses: actions/checkout@v4.1.1
       - uses: actions/setup-go@v5
         with:
-          go-version: '^1.17'
+          go-version: '^1.21'
       - run: go install mvdan.cc/sh/v3/cmd/shfmt@latest
       - run: $(go env GOPATH)/bin/shfmt -f . | grep -v 'vendor' | xargs $(go env GOPATH)/bin/shfmt -bn -ci -s -w
       - name: suggester / shfmt
diff --git a/.github/workflows/scan.yml b/.github/workflows/scan.yml
index 48af1f89..501cf6a6 100644
--- a/.github/workflows/scan.yml
+++ b/.github/workflows/scan.yml
@@ -1,5 +1,13 @@
 name: Scan docker
 on: [pull_request]
+
+env:
+  # Use docker.io for Docker Hub if empty
+  REGISTRY: docker.io
+
+  # github.repository as <account>/<repo>
+  IMAGE_NAME: perconalab/percona-server-mongodb-operator
+
 jobs:
   build:
     name: Build
@@ -7,16 +15,42 @@ jobs:
     steps:
       - name: Checkout code
         uses: actions/checkout@v4.1.1
-      - name: Build an image from Dockerfile
+
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v3
+
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v3
+
+      - name: Build an image from Dockerfile (linux/arm64)
         run: |
-          export IMAGE=perconalab/percona-server-mongodb-operator:${{ github.sha }}
+          export IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64
           export DOCKER_PUSH=0
           export DOCKER_SQUASH=0
+          export DOCKER_DEFAULT_PLATFORM='linux/arm64'
           ./e2e-tests/build
       - name: Run Trivy vulnerability scanner
         uses: aquasecurity/trivy-action@0.16.1
         with:
-          image-ref: 'docker.io/perconalab/percona-server-mongodb-operator:${{ github.sha }}'
+          image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64'
+          format: 'table'
+          exit-code: '1'
+          ignore-unfixed: true
+          vuln-type: 'os,library'
+          severity: 'CRITICAL,HIGH'
+
+      - name: Build an image from Dockerfile (linux/amd64)
+        run: |
+          export IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64
+          export DOCKER_PUSH=0
+          export DOCKER_SQUASH=0
+          export DOCKER_DEFAULT_PLATFORM='linux/amd64'
+          ./e2e-tests/build
+
+      - name: Run Trivy vulnerability scanner image (linux/amd64)
+        uses: aquasecurity/trivy-action@0.14.0
+        with:
+          image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64'
           format: 'table'
           exit-code: '1'
           ignore-unfixed: true
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 66e4317c..efbb25d7 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -7,7 +7,7 @@ jobs:
     steps:
       - uses: actions/setup-go@v5
         with:
-          go-version: '^1.19'
+          go-version: '^1.21'
       - uses: actions/checkout@v4.1.1
       - name: go test
         run: go test -v ./...
diff --git a/Jenkinsfile b/Jenkinsfile
index cabc82ad..c59088ba 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -323,6 +323,7 @@ EOF
                                 docker login -u '${USER}' -p '${PASS}'
                                 export RELEASE=0
                                 export IMAGE=\$DOCKER_TAG
+                                docker buildx create --use
                                 ./e2e-tests/build
                                 docker logout
                             "
@@ -349,7 +350,7 @@ EOF
                             -v $WORKSPACE/src/github.com/percona/percona-server-mongodb-operator:/go/src/github.com/percona/percona-server-mongodb-operator \
                             -w /go/src/github.com/percona/percona-server-mongodb-operator \
                             -e GOFLAGS='-buildvcs=false' \
-                            golang:1.19 sh -c '
+                            golang:1.21 sh -c '
                                 go install github.com/google/go-licenses@v1.0.0;
                                 /go/bin/go-licenses csv github.com/percona/percona-server-mongodb-operator/cmd/manager \
                                     | cut -d , -f 3 \
@@ -377,7 +378,7 @@ EOF
                             -v $WORKSPACE/src/github.com/percona/percona-server-mongodb-operator:/go/src/github.com/percona/percona-server-mongodb-operator \
                             -w /go/src/github.com/percona/percona-server-mongodb-operator \
                             -e GOFLAGS='-buildvcs=false' \
-                            golang:1.19 sh -c 'go build -v -o percona-server-mongodb-operator github.com/percona/percona-server-mongodb-operator/cmd/manager'
+                            golang:1.21 sh -c 'go build -v -o percona-server-mongodb-operator github.com/percona/percona-server-mongodb-operator/cmd/manager'
                     "
                 '''
 
diff --git a/build/Dockerfile b/build/Dockerfile
index 2bcac6e8..4961601e 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -7,17 +7,16 @@ ARG GIT_COMMIT
 ARG GIT_BRANCH
 ARG GO_LDFLAGS
 ARG GOOS=linux
-ARG GOARCH=amd64
 ARG CGO_ENABLED=0
 
 RUN go mod download \
     && mkdir -p build/_output/bin \
-    && GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
+    && GOOS=$GOOS CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
        go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -X main.GitBranch=$GIT_BRANCH" \
            -o build/_output/bin/percona-server-mongodb-operator \
                cmd/manager/main.go \
     && cp -r build/_output/bin/percona-server-mongodb-operator /usr/local/bin/percona-server-mongodb-operator \
-    && GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
+    && GOOS=$GOOS CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
        go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -X main.GitBranch=$GIT_BRANCH" \
            -o build/_output/bin/mongodb-healthcheck \
                cmd/mongodb-healthcheck/main.go \



Test patch:
diff --git a/e2e-tests/build b/e2e-tests/build
index 06acdb1d..4414ab36 100755
--- a/e2e-tests/build
+++ b/e2e-tests/build
@@ -14,6 +14,11 @@ fi
 if [[ ${DOCKER_SQUASH:-1} == 1 ]]; then
 	squash="--squash"
 fi
+if [[ ${DOCKER_PUSH:-1} == 1 ]]; then
+	imgresult="--push=true"
+else
+	imgresult="--load"
+fi
 
 build_operator() {
 	if [ "${RELEASE:-1}" = 0 ]; then
@@ -21,21 +26,19 @@ build_operator() {
 	fi
 
 	export IMAGE
-	export DOCKER_DEFAULT_PLATFORM=${DOCKER_DEFAULT_PLATFORM:-linux/amd64}
+	export DOCKER_DEFAULT_PLATFORM=${DOCKER_DEFAULT_PLATFORM:-"linux/amd64,linux/arm64"}
 	export GO_LDFLAGS="-w -s -trimpath $GO_LDFLAGS"
 	pushd ${src_dir}
-	docker build \
+	docker buildx build \
+		--platform $DOCKER_DEFAULT_PLATFORM \
 		--build-arg GIT_COMMIT=$GIT_COMMIT \
 		--build-arg GIT_BRANCH=$GIT_BRANCH \
 		--build-arg GO_LDFLAGS="$GO_LDFLAGS" \
+		$imgresult \
 		$squash \
 		$no_cache \
 		-t "${IMAGE}" -f build/Dockerfile .
 	popd
-
-	if [ "${DOCKER_PUSH:-1}" = 1 ]; then
-		docker push ${IMAGE}
-	fi
 }
 
 until docker ps; do sleep 1; done