Skip to content

Commit 1705244

Browse files
committed
initial code
1 parent 7f580ac commit 1705244

File tree

7 files changed

+52
-9
lines changed

7 files changed

+52
-9
lines changed

controllers/operator/construct/database_construction.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ type DatabaseStatefulSetOptions struct {
105105
StsType StsType
106106
AdditionalMongodConfig *mdbv1.AdditionalMongodConfig
107107

108-
InitDatabaseNonStaticImage string
109-
DatabaseNonStaticImage string
108+
// InitDatabaseImage is the image used for the init container as well as for the static binary holder
109+
InitDatabaseImage string
110+
DatabaseNonStaticImage string
110111
MongodbImage string
111112
AgentImage string
112113

@@ -674,7 +675,7 @@ func buildMongoDBPodTemplateSpec(opts DatabaseStatefulSetOptions, mdb databaseSt
674675
volumes := []corev1.Volume{scriptsVolume}
675676
volumeMounts := []corev1.VolumeMount{databaseScriptsVolumeMount}
676677

677-
initContainerModifications := []func(*corev1.Container){buildDatabaseInitContainer(opts.InitDatabaseNonStaticImage)}
678+
initContainerModifications := []func(*corev1.Container){buildDatabaseInitContainer(opts.InitDatabaseImage)}
678679
databaseContainerModifications := []func(*corev1.Container){container.Apply(
679680
container.WithName(util.DatabaseContainerName),
680681
container.WithImage(opts.DatabaseNonStaticImage),
@@ -783,7 +784,19 @@ func sharedDatabaseConfiguration(opts DatabaseStatefulSetOptions, mdb databaseSt
783784
)
784785

785786
staticMongodModification := podtemplatespec.NOOP()
787+
agentUtilitiesModification := podtemplatespec.NOOP()
786788
if architectures.IsRunningStaticArchitecture(mdb.GetAnnotations()) {
789+
// agentUtilities
790+
agentUtilitiesModification = podtemplatespec.WithContainerByIndex(2,
791+
container.Apply(
792+
container.WithArgs([]string{"tail -F -n0 /dev/null"}),
793+
container.WithResourceRequirements(buildRequirementsFromPodSpec(*opts.PodSpec)),
794+
container.WithPorts([]corev1.ContainerPort{{ContainerPort: opts.ServicePort}}),
795+
container.WithImagePullPolicy(corev1.PullPolicy(env.ReadOrPanic(util.AutomationAgentImagePullPolicy))), // nolint:forbidigo
796+
container.WithEnvs(logConfigurationToEnvVars(opts.AgentConfig.StartupParameters, opts.AdditionalMongodConfig)...),
797+
configureContainerSecurityContext,
798+
),
799+
)
787800
// The mongod
788801
staticMongodModification = podtemplatespec.WithContainerByIndex(1,
789802
container.Apply(
@@ -805,7 +818,7 @@ func sharedDatabaseConfiguration(opts DatabaseStatefulSetOptions, mdb databaseSt
805818
container.WithEnvs(staticContainersEnvVars(mdb)...),
806819
container.WithEnvs(readinessEnvironmentVariablesToEnvVars(opts.AgentConfig.ReadinessProbe.EnvironmentVariables)...),
807820
container.WithArgs([]string{}),
808-
container.WithCommand([]string{"/opt/scripts/agent-launcher.sh"}),
821+
container.WithCommand([]string{"/opt/scripts/agent-launcher-shim.sh"}),
809822
configureContainerSecurityContext,
810823
),
811824
)
@@ -818,10 +831,9 @@ func sharedDatabaseConfiguration(opts DatabaseStatefulSetOptions, mdb databaseSt
818831
configurePodSpecSecurityContext,
819832
podtemplatespec.WithAffinity(opts.Name, PodAntiAffinityLabelKey, 100),
820833
podtemplatespec.WithTopologyKey(opts.PodSpec.GetTopologyKeyOrDefault(), 0),
821-
// The Agent
822834
agentModification,
823-
// AgentLoggingMongodConfig if static container
824-
staticMongodModification,
835+
staticMongodModification, // non static noop
836+
agentUtilitiesModification, // non static noop
825837
)
826838
}
827839

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=

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"

0 commit comments

Comments
 (0)