Skip to content

Commit ca0c007

Browse files
committed
baseline refactoring
1 parent e370e1f commit ca0c007

File tree

9 files changed

+49
-13
lines changed

9 files changed

+49
-13
lines changed

controllers/operator/construct/database_construction.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@ func buildDatabaseStatefulSetConfigurationFunction(mdb databaseStatefulSetSource
489489

490490
if architectures.IsRunningStaticArchitecture(mdb.GetAnnotations()) {
491491
shareProcessNs = func(sts *appsv1.StatefulSet) {
492-
a := true
493-
sts.Spec.Template.Spec.ShareProcessNamespace = &a
492+
sts.Spec.Template.Spec.ShareProcessNamespace = ptr.To(true)
494493
}
495494
secondContainerModification = podtemplatespec.WithContainerByIndex(1, container.WithVolumeMounts(volumeMounts))
496495
}
@@ -697,7 +696,7 @@ func buildMongoDBPodTemplateSpec(opts DatabaseStatefulSetOptions, mdb databaseSt
697696
container.WithCommand([]string{"bash", "-c", "tail -F -n0 ${MDB_LOG_FILE_MONGODB} mongodb_marker"}),
698697
containerSecurityContext,
699698
)}
700-
staticContainerMongodContainerModification = podtemplatespec.WithContainerByIndex(1, mongodModification...)
699+
staticContainerMongodContainerModification = podtemplatespec.WithContainer(util.DatabaseContainerName, mongodModification...)
701700

702701
// We are not setting the database-scripts volume on purpose,
703702
// since we don't need to copy things from the init container over.
@@ -726,19 +725,17 @@ func buildMongoDBPodTemplateSpec(opts DatabaseStatefulSetOptions, mdb databaseSt
726725
databaseContainerModifications = append(databaseContainerModifications, modification)
727726
}
728727

729-
serviceAccountName := getServiceAccountName(opts)
730-
731728
mods := []podtemplatespec.Modification{
732729
sharedDatabaseConfiguration(opts, mdb),
733730
podtemplatespec.WithServiceAccount(util.MongoDBServiceAccount),
734-
podtemplatespec.WithServiceAccount(serviceAccountName),
731+
podtemplatespec.WithServiceAccount(getServiceAccountName(opts)),
735732
podtemplatespec.WithVolumes(volumes),
736733
podtemplatespec.WithContainerByIndex(0, databaseContainerModifications...),
737734
staticContainerMongodContainerModification,
738735
}
739736

740737
if len(initContainerModifications) > 0 {
741-
mods = append(mods, podtemplatespec.WithInitContainerByIndex(0, initContainerModifications...))
738+
mods = append(mods, podtemplatespec.WithInitContainer(InitDatabaseContainerName, initContainerModifications...))
742739
}
743740

744741
return podtemplatespec.Apply(mods...)

controllers/operator/database_statefulset_options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ func WithDefaultConfigSrvStorageSize() func(options *construct.DatabaseStatefulS
100100
}
101101
}
102102

103-
// WithInitDatabaseNonStaticImage sets the InitDatabaseNonStaticImage field.
103+
// WithInitDatabaseNonStaticImage sets the InitDatabaseImage field.
104104
func WithInitDatabaseNonStaticImage(image string) func(*construct.DatabaseStatefulSetOptions) {
105105
return func(opts *construct.DatabaseStatefulSetOptions) {
106-
opts.InitDatabaseNonStaticImage = image
106+
opts.InitDatabaseImage = image
107107
}
108108
}
109109

docker/mongodb-agent/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ COPY --from=base /data/readinessprobe /opt/scripts/readinessprobe
1818
COPY --from=base /data/version-upgrade-hook /opt/scripts/version-upgrade-hook
1919
COPY --from=base /data/agent-launcher-lib.sh /opt/scripts/agent-launcher-lib.sh
2020
COPY --from=base /data/agent-launcher.sh /opt/scripts/agent-launcher.sh
21+
COPY agent-launcher-shim.sh /agent-launcher-shim.sh
22+
RUN chmod +x /agent-launcher-shim.sh
2123
COPY --from=base /data/LICENSE /licenses/LICENSE
2224

2325
# Replace libcurl-minimal and curl-minimal with the full versions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Wait for agent-launcher container to start
5+
echo "Waiting for agent-launcher container to be ready..."
6+
while [ ! -d "/proc/$(pgrep -f 'tail -F -n0 /dev/null' | head -n1)/root/opt/scripts" ]; do
7+
sleep 1
8+
done
9+
10+
# Copy agent launcher scripts
11+
echo "Copying agent launcher scripts..."
12+
cp -r /proc/$(pgrep -f 'tail -F -n0 /dev/null' | head -n1)/root/opt/scripts/* /opt/scripts/
13+
14+
# Make scripts executable
15+
chmod +x /opt/scripts/*.sh
16+
17+
# Start the agent launcher
18+
echo "Starting agent launcher..."
19+
exec /opt/scripts/agent-launcher.sh

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ require (
1313
github.com/hashicorp/go-retryablehttp v0.7.7
1414
github.com/hashicorp/vault/api v1.16.0
1515
github.com/imdario/mergo v0.3.15
16+
github.com/onsi/ginkgo/v2 v2.17.1
17+
github.com/onsi/gomega v1.32.0
1618
github.com/pkg/errors v0.9.1
1719
github.com/prometheus/client_golang v1.22.0
1820
github.com/r3labs/diff/v3 v3.0.1
@@ -54,13 +56,15 @@ require (
5456
github.com/go-openapi/jsonpointer v0.19.6 // indirect
5557
github.com/go-openapi/jsonreference v0.20.2 // indirect
5658
github.com/go-openapi/swag v0.22.3 // indirect
59+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
5760
github.com/gogo/protobuf v1.3.2 // indirect
5861
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
5962
github.com/golang/protobuf v1.5.4 // indirect
6063
github.com/golang/snappy v0.0.4 // indirect
6164
github.com/google/gnostic-models v0.6.8 // indirect
6265
github.com/google/go-querystring v1.1.0 // indirect
6366
github.com/google/gofuzz v1.2.0 // indirect
67+
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
6468
github.com/gorilla/websocket v1.5.0 // indirect
6569
github.com/hashicorp/errwrap v1.1.0 // indirect
6670
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
1010
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
1111
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1212
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
13+
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
14+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
15+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
1316
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1417
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1518
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -110,6 +113,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
110113
github.com/hashicorp/vault/api v1.16.0 h1:nbEYGJiAPGzT9U4oWgaaB0g+Rj8E59QuHKyA5LhwQN4=
111114
github.com/hashicorp/vault/api v1.16.0/go.mod h1:KhuUhzOD8lDSk29AtzNjgAu2kxRA9jL9NAbkFlqvkBA=
112115
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
116+
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
113117
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
114118
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
115119
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -284,6 +288,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
284288
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
285289
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
286290
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
291+
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
287292
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
288293
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
289294
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

mongodb-community-operator/pkg/kube/podtemplatespec/podspec_template.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NOOP() Modification {
3939
}
4040

4141
// WithContainer applies the modifications to the container with the provided name
42-
func WithContainer(name string, containerfunc func(*corev1.Container)) Modification {
42+
func WithContainer(name string, funcs ...func(*corev1.Container)) Modification {
4343
return func(podTemplateSpec *corev1.PodTemplateSpec) {
4444
idx := findIndexByName(name, podTemplateSpec.Spec.Containers)
4545
if idx == notFound {
@@ -48,7 +48,9 @@ func WithContainer(name string, containerfunc func(*corev1.Container)) Modificat
4848
idx = len(podTemplateSpec.Spec.Containers) - 1
4949
}
5050
c := &podTemplateSpec.Spec.Containers[idx]
51-
containerfunc(c)
51+
for _, f := range funcs {
52+
f(c)
53+
}
5254
}
5355
}
5456

@@ -67,7 +69,7 @@ func WithContainerByIndex(index int, funcs ...func(container *corev1.Container))
6769
}
6870

6971
// WithInitContainer applies the modifications to the init container with the provided name
70-
func WithInitContainer(name string, containerfunc func(*corev1.Container)) Modification {
72+
func WithInitContainer(name string, funcs ...func(*corev1.Container)) Modification {
7173
return func(podTemplateSpec *corev1.PodTemplateSpec) {
7274
idx := findIndexByName(name, podTemplateSpec.Spec.InitContainers)
7375
if idx == notFound {
@@ -76,7 +78,9 @@ func WithInitContainer(name string, containerfunc func(*corev1.Container)) Modif
7678
idx = len(podTemplateSpec.Spec.InitContainers) - 1
7779
}
7880
c := &podTemplateSpec.Spec.InitContainers[idx]
79-
containerfunc(c)
81+
for _, f := range funcs {
82+
f(c)
83+
}
8084
}
8185
}
8286

pkg/util/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const (
8989
BackupDaemonContainerName = "mongodb-backup-daemon"
9090
DatabaseContainerName = "mongodb-enterprise-database"
9191
AgentContainerName = "mongodb-agent"
92+
AgentContainerUtilitiesName = "mongodb-agent-operator-utilities"
9293
InitOpsManagerContainerName = "mongodb-kubernetes-init-ops-manager"
9394
PvcNameData = "data"
9495
PvcMountPathData = "/data"

scripts/dev/print_operator_env.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ MDB_SEARCH_COMMUNITY_REPO_URL=\"${MDB_SEARCH_COMMUNITY_REPO_URL}\"
9999
if [[ "${MDB_MAX_CONCURRENT_RECONCILES:-""}" != "" ]]; then
100100
echo "MDB_MAX_CONCURRENT_RECONCILES=${MDB_MAX_CONCURRENT_RECONCILES}"
101101
fi
102+
103+
if [[ "${OPERATOR_NAME:-""}" != "" ]]; then
104+
echo "OPERATOR_NAME=${OPERATOR_NAME}"
105+
fi
102106
}
103107

104108
print_operator_env

0 commit comments

Comments
 (0)