Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit 2221afc

Browse files
authored
Allow Configuration of Mongo image and registry (#137)
1 parent 4b79e74 commit 2221afc

File tree

8 files changed

+33
-11
lines changed

8 files changed

+33
-11
lines changed

.evergreen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ functions:
4040
DIR: ${workdir}/bin
4141

4242
# upload_e2e_logs has the responsibility of dumping as much information as
43-
# posible into the S3 bucket
43+
# possible into the S3 bucket
4444
upload_e2e_logs:
4545
- command: s3.put
4646
params:

deploy/operator.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
- name: mongodb-kubernetes-operator
1818
image: quay.io/mongodb/mongodb-kubernetes-operator:0.2.0
1919
command:
20-
- mongodb-kubernetes-operator
20+
- mongodb-kubernetes-operator
2121
imagePullPolicy: Always
2222
env:
2323
- name: WATCH_NAMESPACE
@@ -34,3 +34,7 @@ spec:
3434
value: quay.io/mongodb/mongodb-agent:10.19.0.6562-1
3535
- name: VERSION_UPGRADE_HOOK_IMAGE
3636
value: quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook:1.0.2
37+
- name: MONGODB_IMAGE
38+
value: "library/mongo"
39+
- name: MONGODB_REPO_URL
40+
value: "registry.hub.docker.com"

pkg/authentication/scramcredentials/scram_credentials.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scramcredentials
22

33
import (
44
"crypto/hmac"
5-
"crypto/md5"
5+
"crypto/md5" //nolint
66
"crypto/sha1" //nolint
77
"crypto/sha256"
88
"encoding/base64"
@@ -44,8 +44,8 @@ func ComputeScramSha1Creds(username, password string, salt []byte) (ScramCreds,
4444
}
4545

4646
func md5Hex(s string) string {
47-
h := md5.New()
48-
h.Write([]byte(s))
47+
h := md5.New() // nolint
48+
h.Write([]byte(s)) //nolint
4949
return hex.EncodeToString(h.Sum(nil))
5050
}
5151

pkg/authentication/scramcredentials/scram_credentials_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scramcredentials
22

33
import (
4-
"crypto/sha1"
4+
"crypto/sha1" //nolint
55
"crypto/sha256"
66
"hash"
77
"testing"

pkg/controller/mongodb/build_statefulset_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func init() {
1818
}
1919

2020
func TestMultipleCalls_DoNotCauseSideEffects(t *testing.T) {
21+
_ = os.Setenv(mongodbRepoUrl, "repo")
22+
_ = os.Setenv(mongodbImageEnv, "mongo")
23+
2124
mdb := newTestReplicaSet()
2225
stsFunc := buildStatefulSetModificationFunction(mdb)
2326
sts := &appsv1.StatefulSet{}
@@ -56,7 +59,7 @@ func assertStatefulSetIsBuiltCorrectly(t *testing.T, mdb mdbv1.MongoDB, sts *app
5659
assert.Len(t, agentContainer.VolumeMounts, 4)
5760

5861
mongodContainer := sts.Spec.Template.Spec.Containers[1]
59-
assert.Equal(t, "mongo:4.2.2", mongodContainer.Image)
62+
assert.Equal(t, "repo/mongo:4.2.2", mongodContainer.Image)
6063
assert.NotNil(t, sts.Spec.Template.Spec.Containers[0].ReadinessProbe)
6164
assert.Len(t, mongodContainer.VolumeMounts, 4)
6265

pkg/controller/mongodb/replica_set_controller.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io/ioutil"
99
"os"
10+
"strings"
1011
"time"
1112

1213
"github.com/mongodb/mongodb-kubernetes-operator/pkg/util/envvar"
@@ -56,6 +57,8 @@ const (
5657
agentImageEnv = "AGENT_IMAGE"
5758
versionUpgradeHookImageEnv = "VERSION_UPGRADE_HOOK_IMAGE"
5859
agentHealthStatusFilePathEnv = "AGENT_STATUS_FILEPATH"
60+
mongodbImageEnv = "MONGODB_IMAGE"
61+
mongodbRepoUrl = "MONGODB_REPO_URL"
5962
mongodbToolsVersionEnv = "MONGODB_TOOLS_VERSION"
6063

6164
AutomationConfigKey = "automation-config"
@@ -505,7 +508,7 @@ func getMongodConfigModification(mdb mdbv1.MongoDB) automationconfig.Modificatio
505508
return func(ac *automationconfig.AutomationConfig) {
506509
for i := range ac.Processes {
507510
// Mergo requires both objects to have the same type
508-
// TODO: proper error handling
511+
// TODO: handle this error gracefully, we may need to add an error as second argument for all modification functions
509512
_ = mergo.Merge(&ac.Processes[i].Args26, objx.New(mdb.Spec.AdditionalMongodConfig.Object), mergo.WithOverride)
510513
}
511514
}
@@ -572,6 +575,15 @@ func versionUpgradeHookInit(volumeMount []corev1.VolumeMount) container.Modifica
572575
)
573576
}
574577

578+
func getMongoDBImage(version string) string {
579+
repoUrl := os.Getenv(mongodbRepoUrl)
580+
if strings.HasSuffix(repoUrl, "/") {
581+
repoUrl = strings.TrimRight(repoUrl, "/")
582+
}
583+
mongoImageName := os.Getenv(mongodbImageEnv)
584+
return fmt.Sprintf("%s/%s:%s", repoUrl, mongoImageName, version)
585+
}
586+
575587
func mongodbContainer(version string, volumeMounts []corev1.VolumeMount) container.Modification {
576588
mongoDbCommand := []string{
577589
"/bin/sh",
@@ -590,7 +602,7 @@ exec mongod -f /data/automation-mongod.conf ;
590602

591603
return container.Apply(
592604
container.WithName(mongodbName),
593-
container.WithImage(fmt.Sprintf("mongo:%s", version)),
605+
container.WithImage(getMongoDBImage(version)),
594606
container.WithResourceRequirements(resourcerequirements.Defaults()),
595607
container.WithCommand(mongoDbCommand),
596608
container.WithEnvs(

pkg/controller/mongodb/replicaset_controller_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ func TestKubernetesResources_AreCreated(t *testing.T) {
142142
}
143143

144144
func TestStatefulSet_IsCorrectlyConfigured(t *testing.T) {
145+
_ = os.Setenv(mongodbRepoUrl, "repo")
146+
_ = os.Setenv(mongodbImageEnv, "mongo")
147+
145148
mdb := newTestReplicaSet()
146149
mgr := client.NewManager(&mdb)
147150
r := newReconciler(mgr, mockManifestProvider(mdb.Spec.Version))
@@ -162,7 +165,7 @@ func TestStatefulSet_IsCorrectlyConfigured(t *testing.T) {
162165

163166
mongodbContainer := sts.Spec.Template.Spec.Containers[1]
164167
assert.Equal(t, mongodbName, mongodbContainer.Name)
165-
assert.Equal(t, "mongo:4.2.2", mongodbContainer.Image)
168+
assert.Equal(t, "repo/mongo:4.2.2", mongodbContainer.Image)
166169

167170
assert.Equal(t, resourcerequirements.Defaults(), agentContainer.Resources)
168171

test/e2e/setup/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func registerTypesWithFramework(newTypes ...runtime.Object) error {
5050

5151
// CreateTLSResources will setup the CA ConfigMap and cert-key Secret necessary for TLS
5252
// The certificates and keys are stored in testdata/tls
53-
func CreateTLSResources(namespace string, ctx *f.TestCtx) error {
53+
func CreateTLSResources(namespace string, ctx *f.TestCtx) error { //nolint
5454
tlsConfig := e2eutil.NewTestTLSConfig(false)
5555

5656
// Create CA ConfigMap

0 commit comments

Comments
 (0)