Repository: mariadb-operator/mariadb-operator

Issue:
[Bug] MaxScale: 'command' and 'args' parameters not works as expected
By [MaxScaleSpec](https://github.com/mariadb-operator/mariadb-operator/blob/main/docs/API_REFERENCE.md#maxscalespec) we should be able to set _command_ and _args_.

**command** - is ignored at all
**args** - only allow to append argument to already hardcoded.

Ref: https://github.com/mariadb-operator/mariadb-operator/blob/b3365c13ec3e0f644fddea833fec7d19dce677e4/pkg/builder/container_builder.go#L126

I'm trying to bump MaxScale version and I'm only allow to use `image: mariadb/maxscale:23.08.6`
Because of UID and GID change in image:
```
unbound:x:998:996:Unbound DNS resolver:/etc/unbound:/sbin/nologin
maxscale:x:997:995::/home/maxscale:/bin/false
```
I need to use:
```
  podSecurityContext:
    fsGroup: 995
    runAsGroup: 995
    runAsNonRoot: true
    runAsUser: 997
```

Can't use newer version: 23.08.7 or 24.02.3
I'm getting error:
**Error: Failed to initialize groups for 'maxscale: 1 Operation not permitted**

This is related to this change:
https://github.com/mariadb-corporation/MaxScale/commit/3e1a96ca0646a09f42f22ff3fbdddbce36989080

Because podSecurityContext is used and mariadb-operator injecting this **-U maxscale** there is no option to overwrite this argument.

**Expected behaviour**

- By setting **command** and **args**, defaults should be overwritten.
- Argument **-U maxscale** should be skipped when SecurityContext is used.

**Steps to reproduce the bug**
1. set command and args
2. check pod manifest

**Environment details**
mariadb-operator version: 0.35.0


Discussion:
@github-actions: This issue is stale because it has been open 60 days with no activity.@github-actions: This issue was closed because it has been stalled for 30 days with no activity.@mmontes11: This has been supported in https://github.com/mariadb-operator/mariadb-operator/pull/1160

Solution patch:
diff --git a/.github/workflows/test-image-ent.yml b/.github/workflows/test-image-ent.yml
deleted file mode 100644
index dcb55ddf..00000000
--- a/.github/workflows/test-image-ent.yml
+++ /dev/null
@@ -1,58 +0,0 @@
-name: Test image UBI
-
-on:
-  workflow_dispatch:
-    inputs:
-      mariadb_image:
-        description: "MariaDB image used to run the tests"
-        required: true
-        type: string
-      mariadb_version:
-        description: "MariaDB version related by image if not obvious via tag"
-        required: false
-        type: string
-
-jobs:
-  test:
-    name: "Test \"${{ inputs.mariadb_image }}\" UBI image"
-    runs-on: ubuntu-latest
-    steps:
-      - name: MariaDB Version
-        run: |
-          docker run --rm ${{ inputs.mariadb_image }} mariadbd --version
-
-      - name: Checkout code
-        uses: actions/checkout@v4
-
-      - name: Setup Go
-        uses: actions/setup-go@v5
-        with:
-          go-version-file: "go.mod"
-          cache: true
-
-      - name: Cluster
-        run: |
-          make cluster
-          make install
-          make install-minio
-          make install-cert-manager
-          make net
-
-      - name: Integration tests
-        run: make test-int
-        env:
-          MARIADB_GALERA_LIB_PATH: /usr/lib64/galera/libgalera_smm.so
-          RELATED_IMAGE_MARIADB_ENT: "${{ inputs.mariadb_image }}"
-          MARIADB_ENTRYPOINT_VERSION_ENT: "${{ inputs.mariadb_version }}"
-
-      - name: Tell the MariaDB Folks that failed
-        if: ${{ failure() && contains(inputs.mariadb_image, 'mariadb-foundation') }}
-        uses: zulip/github-actions-zulip/send-message@v1
-        with:
-          api-key: ${{ secrets.MARIADB_ZULIP_API_KEY }}
-          email: "mariadb-operator-bot@mariadb.zulipchat.com"
-          organization-url: "https://mariadb.zulipchat.com"
-          to: "Buildbot"
-          type: "stream"
-          topic: "CI - MariaDB Operator"
-          content: "There was an error running MariaDB Operator integration tests on ${{ inputs.mariadb_image }} version(${{ inputs.mariadb_version }}) - URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}."
diff --git a/pkg/builder/container_builder.go b/pkg/builder/container_builder.go
index 18b5630e..72694900 100644
--- a/pkg/builder/container_builder.go
+++ b/pkg/builder/container_builder.go
@@ -133,9 +133,12 @@ func (b *Builder) maxscaleContainers(mxs *mariadbv1alpha1.MaxScale) ([]corev1.Co
 
 	container.Name = MaxScaleContainerName
 	container.Command = command.Command
+	if tpl.Command != nil {
+		container.Command = tpl.Command
+	}
 	container.Args = command.Args
 	if len(tpl.Args) > 0 {
-		container.Args = append(container.Args, tpl.Args...)
+		container.Args = tpl.Args
 	}
 	container.Ports = []corev1.ContainerPort{
 		{



Test patch:
diff --git a/pkg/builder/container_builder_test.go b/pkg/builder/container_builder_test.go
index 0687d52d..6ae9dee4 100644
--- a/pkg/builder/container_builder_test.go
+++ b/pkg/builder/container_builder_test.go
@@ -1865,6 +1865,72 @@ func TestMariadbInitContainers(t *testing.T) {
 	}
 }
 
+func TestMaxscaleContainers(t *testing.T) {
+	tests := []struct {
+		name        string
+		maxscale    *mariadbv1alpha1.MaxScale
+		wantCommand []string
+		wantArgs    []string
+	}{
+		{
+			name: "Without custom command and args",
+			maxscale: &mariadbv1alpha1.MaxScale{
+				Spec: mariadbv1alpha1.MaxScaleSpec{
+					ContainerTemplate: mariadbv1alpha1.ContainerTemplate{},
+				},
+			},
+			wantCommand: []string{"maxscale"},
+			wantArgs:    []string{"--config", "/etc/config/maxscale.cnf", "-dU", "maxscale", "-l", "stdout"},
+		},
+		{
+			name: "With custom command",
+			maxscale: &mariadbv1alpha1.MaxScale{
+				Spec: mariadbv1alpha1.MaxScaleSpec{
+					ContainerTemplate: mariadbv1alpha1.ContainerTemplate{
+						Command: []string{"maxscale-test"},
+					},
+				},
+			},
+			wantCommand: []string{"maxscale-test"},
+			wantArgs:    []string{"--config", "/etc/config/maxscale.cnf", "-dU", "maxscale", "-l", "stdout"},
+		},
+		{
+			name: "With custom command and args",
+			maxscale: &mariadbv1alpha1.MaxScale{
+				Spec: mariadbv1alpha1.MaxScaleSpec{
+					ContainerTemplate: mariadbv1alpha1.ContainerTemplate{
+						Command: []string{"maxscale-test"},
+						Args:    []string{"--test", "--unit"},
+					},
+				},
+			},
+			wantCommand: []string{"maxscale-test"},
+			wantArgs:    []string{"--test", "--unit"},
+		},
+	}
+
+	builder := newDefaultTestBuilder(t)
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			containers, err := builder.maxscaleContainers(tt.maxscale)
+			if err != nil {
+				t.Fatalf("unexpected error building containers: %v", err)
+			}
+
+			container := containers[0]
+
+			if !reflect.DeepEqual(container.Command[0], tt.wantCommand[0]) {
+				t.Errorf("unexpected result:\nexpected:\n%s\ngot:\n%s\n", tt.wantCommand[0], container.Command[0])
+			}
+
+			if !reflect.DeepEqual(tt.wantArgs, container.Args) {
+				t.Errorf("expected env keys \"%v\" to exist\n got:\"%v\"", tt.wantArgs, container.Args)
+			}
+		})
+	}
+}
+
 func defaultEnv(overrides []corev1.EnvVar) []corev1.EnvVar {
 	mysqlTcpPort := corev1.EnvVar{
 		Name:  "MYSQL_TCP_PORT",