Skip to content

Commit cac9035

Browse files
authored
Merge pull request #380 from runkecheng/support_image_prefix
*: Support custom repository address of images. #378
2 parents 7745f47 + 7d01a00 commit cac9035

File tree

13 files changed

+68
-10
lines changed

13 files changed

+68
-10
lines changed

backup/syncer/job.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
v1alpha1 "github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1"
3131
"github.com/radondb/radondb-mysql-kubernetes/backup"
32+
"github.com/radondb/radondb-mysql-kubernetes/mysqlcluster"
3233
"github.com/radondb/radondb-mysql-kubernetes/utils"
3334
)
3435

@@ -114,7 +115,7 @@ func (s *jobSyncer) ensurePodSpec(in corev1.PodSpec) corev1.PodSpec {
114115
in.RestartPolicy = corev1.RestartPolicyNever
115116
sctName := fmt.Sprintf("%s-secret", s.backup.Spec.ClusterName)
116117
in.Containers[0].Name = utils.ContainerBackupName
117-
in.Containers[0].Image = s.backup.Spec.Image
118+
in.Containers[0].Image = fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), s.backup.Spec.Image)
118119
in.Containers[0].Args = []string{
119120
"request_a_backup",
120121
s.backup.GetBackupURL(s.backup.Spec.ClusterName, s.backup.Spec.HostName),

charts/mysql-operator/templates/deployment.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ spec:
2424
containers:
2525
{{- if .Values.rbacProxy.create }}
2626
- name: kube-rbac-proxy
27-
image: {{ .Values.rbacProxy.image }}
27+
{{- if not .Values.imagePrefix }}
28+
image: "{{ .Values.rbacProxy.image }}"
29+
{{- else }}
30+
image: "{{ .Values.imagePrefix }}/{{ .Values.rbacProxy.image }}"
31+
{{- end }}
2832
args:
2933
- "--secure-listen-address=0.0.0.0:8443"
3034
- "--upstream=http://127.0.0.1:8080/"
@@ -41,8 +45,15 @@ spec:
4145
- --health-probe-bind-address=:8081
4246
- --metrics-bind-address=127.0.0.1:8080
4347
- --leader-elect
48+
{{- if not .Values.imagePrefix }}
4449
image: "{{ .Values.manager.image }}:{{ .Values.manager.tag }}"
50+
{{- else }}
51+
image: "{{ .Values.imagePrefix }}/{{ .Values.manager.image }}:{{ .Values.manager.tag }}"
52+
{{- end }}
4553
imagePullPolicy: {{ .Values.imagePullPolicy | quote }}
54+
env:
55+
- name: IMAGE_PREFIX
56+
value: {{ .Values.imagePrefix }}
4657
securityContext:
4758
allowPrivilegeEscalation: false
4859
livenessProbe:

charts/mysql-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ installCRDS: true
1212
imagePullPolicy: IfNotPresent
1313
nameOverride: ""
1414
fullnameOverride: ""
15+
imagePrefix: ""
1516

1617
manager:
1718
image: radondb/mysql-operator

mysqlcluster/container/auditlog_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package container
1818

1919
import (
20+
"fmt"
2021
"testing"
2122

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

5859
func TestGetAuditlogImage(t *testing.T) {
59-
assert.Equal(t, "busybox", auditLogCase.Image)
60+
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "busybox"), auditLogCase.Image)
6061
}
6162

6263
func TestGetAuditlogCommand(t *testing.T) {

mysqlcluster/container/container.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package container
1818

1919
import (
20+
"fmt"
21+
2022
corev1 "k8s.io/api/core/v1"
2123

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

6264
return corev1.Container{
6365
Name: ctr.getName(),
64-
Image: ctr.getImage(),
66+
Image: fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), ctr.getImage()),
6567
ImagePullPolicy: c.Spec.PodPolicy.ImagePullPolicy,
6668
Command: ctr.getCommand(),
6769
Env: ctr.getEnvVars(),

mysqlcluster/container/init_mysql_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package container
1818

1919
import (
20+
"fmt"
2021
"testing"
2122

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

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

115116
func TestGetInitMysqlCommand(t *testing.T) {

mysqlcluster/container/init_sidecar_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package container
1818

1919
import (
20+
"fmt"
2021
"strconv"
2122
"testing"
2223

@@ -303,7 +304,7 @@ func TestGetInitSidecarName(t *testing.T) {
303304
}
304305

305306
func TestGetInitSidecarImage(t *testing.T) {
306-
assert.Equal(t, "sidecar image", initSidecarCase.Image)
307+
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "sidecar image"), initSidecarCase.Image)
307308
}
308309

309310
func TestGetInitSidecarCommand(t *testing.T) {

mysqlcluster/container/metrics_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package container
1818

1919
import (
20+
"fmt"
2021
"testing"
2122

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

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

6263
func TestGetMetricsCommand(t *testing.T) {

mysqlcluster/container/mysql_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package container
1818

1919
import (
20+
"fmt"
2021
"testing"
2122

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

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

5960
func TestGetMysqlCommand(t *testing.T) {

mysqlcluster/container/slowlog_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package container
1818

1919
import (
20+
"fmt"
2021
"testing"
2122

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

5152
func TestGetSlowlogImage(t *testing.T) {
52-
assert.Equal(t, "sidecar image", slowlogCase.Image)
53+
assert.Equal(t, fmt.Sprintf("%s%s", mysqlcluster.GetPrefixFromEnv(), "sidecar image"), slowlogCase.Image)
5354
}
5455

5556
func TestGetSlowlogCommand(t *testing.T) {

0 commit comments

Comments
 (0)