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
3 changes: 2 additions & 1 deletion backup/syncer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

v1alpha1 "github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1"
"github.com/radondb/radondb-mysql-kubernetes/backup"
"github.com/radondb/radondb-mysql-kubernetes/mysqlcluster"
"github.com/radondb/radondb-mysql-kubernetes/utils"
)

Expand Down Expand Up @@ -114,7 +115,7 @@ func (s *jobSyncer) ensurePodSpec(in corev1.PodSpec) corev1.PodSpec {
in.RestartPolicy = corev1.RestartPolicyNever
sctName := fmt.Sprintf("%s-secret", s.backup.Spec.ClusterName)
in.Containers[0].Name = utils.ContainerBackupName
in.Containers[0].Image = s.backup.Spec.Image
in.Containers[0].Image = fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), s.backup.Spec.Image)
in.Containers[0].Args = []string{
"request_a_backup",
s.backup.GetBackupURL(s.backup.Spec.ClusterName, s.backup.Spec.HostName),
Expand Down
13 changes: 12 additions & 1 deletion charts/mysql-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ spec:
containers:
{{- if .Values.rbacProxy.create }}
- name: kube-rbac-proxy
image: {{ .Values.rbacProxy.image }}
{{- if not .Values.imagePrefix }}
image: "{{ .Values.rbacProxy.image }}"
{{- else }}
image: "{{ .Values.imagePrefix }}/{{ .Values.rbacProxy.image }}"
{{- end }}
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
Expand All @@ -41,8 +45,15 @@ spec:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --leader-elect
{{- if not .Values.imagePrefix }}
image: "{{ .Values.manager.image }}:{{ .Values.manager.tag }}"
{{- else }}
image: "{{ .Values.imagePrefix }}/{{ .Values.manager.image }}:{{ .Values.manager.tag }}"
{{- end }}
imagePullPolicy: {{ .Values.imagePullPolicy | quote }}
env:
- name: IMAGE_PREFIX
value: {{ .Values.imagePrefix }}
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
Expand Down
1 change: 1 addition & 0 deletions charts/mysql-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ installCRDS: true
imagePullPolicy: IfNotPresent
nameOverride: ""
fullnameOverride: ""
imagePrefix: ""

manager:
image: radondb/mysql-operator
Expand Down
3 changes: 2 additions & 1 deletion mysqlcluster/container/auditlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package container

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestGetAuditlogName(t *testing.T) {
}

func TestGetAuditlogImage(t *testing.T) {
assert.Equal(t, "busybox", auditLogCase.Image)
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "busybox"), auditLogCase.Image)
}

func TestGetAuditlogCommand(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion mysqlcluster/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package container

import (
"fmt"

corev1 "k8s.io/api/core/v1"

"github.com/radondb/radondb-mysql-kubernetes/mysqlcluster"
Expand Down Expand Up @@ -61,7 +63,7 @@ func EnsureContainer(name string, c *mysqlcluster.MysqlCluster) corev1.Container

return corev1.Container{
Name: ctr.getName(),
Image: ctr.getImage(),
Image: fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), ctr.getImage()),
ImagePullPolicy: c.Spec.PodPolicy.ImagePullPolicy,
Command: ctr.getCommand(),
Env: ctr.getEnvVars(),
Expand Down
3 changes: 2 additions & 1 deletion mysqlcluster/container/init_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package container

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -109,7 +110,7 @@ func TestGetInitMysqlName(t *testing.T) {
}

func TestGetInitMysqlImage(t *testing.T) {
assert.Equal(t, "percona/percona-server:5.7.34", initMysqlCase.Image)
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "percona/percona-server:5.7.34"), initMysqlCase.Image)
}

func TestGetInitMysqlCommand(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion mysqlcluster/container/init_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package container

import (
"fmt"
"strconv"
"testing"

Expand Down Expand Up @@ -303,7 +304,7 @@ func TestGetInitSidecarName(t *testing.T) {
}

func TestGetInitSidecarImage(t *testing.T) {
assert.Equal(t, "sidecar image", initSidecarCase.Image)
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "sidecar image"), initSidecarCase.Image)
}

func TestGetInitSidecarCommand(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion mysqlcluster/container/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package container

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestGetMetricsName(t *testing.T) {
}

func TestGetMetricsImage(t *testing.T) {
assert.Equal(t, "metrics-image", metricsCase.Image)
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "metrics-image"), metricsCase.Image)
}

func TestGetMetricsCommand(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion mysqlcluster/container/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package container

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestGetMysqlName(t *testing.T) {
}

func TestGetMysqlImage(t *testing.T) {
assert.Equal(t, "percona/percona-server:5.7.34", mysqlCase.Image)
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "percona/percona-server:5.7.34"), mysqlCase.Image)
}

func TestGetMysqlCommand(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion mysqlcluster/container/slowlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package container

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestGetSlowlogName(t *testing.T) {
}

func TestGetSlowlogImage(t *testing.T) {
assert.Equal(t, "sidecar image", slowlogCase.Image)
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "sidecar image"), slowlogCase.Image)
}

func TestGetSlowlogCommand(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion mysqlcluster/container/xenon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package container

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -59,7 +60,7 @@ func TestGetXenonName(t *testing.T) {
}

func TestGetXenonImage(t *testing.T) {
assert.Equal(t, "xenon image", xenonCase.Image)
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "xenon image"), xenonCase.Image)
}

func TestGetXenonCommand(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"math"
"os"
"strconv"
"strings"
"unicode"
Expand Down Expand Up @@ -375,3 +376,12 @@ func (c *MysqlCluster) GetKey() client.ObjectKey {
Name: c.Name,
}
}

// GetPrefixFromEnv get the image prefix from the environment variable.
func GetPrefixFromEnv() string {
prefix := os.Getenv("IMAGE_PREFIX")
if len(prefix) == 0 {
return ""
}
return prefix + "/"
}
26 changes: 26 additions & 0 deletions mysqlcluster/mysqlcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package mysqlcluster

import (
"fmt"
"os"
"reflect"
"strconv"
"testing"
Expand Down Expand Up @@ -658,3 +659,28 @@ func TestSizeToBytes(t *testing.T) {
assert.Equal(t, err, fmt.Errorf("error"))
}
}

func TestGetPrefixFromEnv(t *testing.T) {
// Prefix is empty.
{
guard := Patch(os.Getenv, func(key string) string {
return ""
})
defer guard.Unpatch()

want := ""
result := GetPrefixFromEnv()
assert.Equal(t, want, result)
}
// Prefix is not empty.
{
guard := Patch(os.Getenv, func(key string) string {
return "docker.io"
})
defer guard.Unpatch()

want := "docker.io/"
result := GetPrefixFromEnv()
assert.Equal(t, want, result)
}
}