Skip to content

Commit c8b66fe

Browse files
committed
Merge branch 'master' into maciejk/use-ar-related-versions
# Conflicts: # scripts/release/atomic_pipeline.py # scripts/release/pipeline_main.py
2 parents d047de5 + 3e482c3 commit c8b66fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+784
-837
lines changed

.evergreen.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,6 @@ tasks:
462462
skip_tags: ubuntu,release
463463

464464
- name: build_agent_images_ubi
465-
depends_on:
466-
- name: build_init_database_image_ubi
467-
variant: init_test_run
468465
commands:
469466
- func: clone
470467
- func: setup_building_host
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Changing container setup of static architecture
3+
kind: fix
4+
date: 2025-08-06
5+
---
6+
7+
* This change fixes the current complex and difficult-to-maintain architecture for stateful set containers, which relies on an "agent matrix" to map operator and agent versions which led to a sheer amount of images.
8+
* We solve this by shifting to a 3-container setup. This new design eliminates the need for the operator-version/agent-version matrix by adding one additional container containing all required binaries. This architecture maps to what we already do with the mongodb-database container.

controllers/operator/common_controller.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
"github.com/mongodb/mongodb-kubernetes/pkg/util/architectures"
4848
"github.com/mongodb/mongodb-kubernetes/pkg/util/env"
4949
"github.com/mongodb/mongodb-kubernetes/pkg/util/stringutil"
50-
"github.com/mongodb/mongodb-kubernetes/pkg/util/versionutil"
5150
"github.com/mongodb/mongodb-kubernetes/pkg/vault"
5251
)
5352

@@ -684,9 +683,7 @@ func (r *ReconcileCommonController) getAgentVersion(conn om.Connection, omVersio
684683
return "", err
685684
} else {
686685
log.Debugf("Using agent version %s", agentVersion)
687-
currentOperatorVersion := versionutil.StaticContainersOperatorVersion()
688-
log.Debugf("Using Operator version: %s", currentOperatorVersion)
689-
return agentVersion + "_" + currentOperatorVersion, nil
686+
return agentVersion, nil
690687
}
691688
}
692689

controllers/operator/construct/appdb_construction.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func appDbPodSpec(initContainerImage string, om om.MongoDBOpsManager) podtemplat
122122
construct.AgentName,
123123
container.WithResourceRequirements(buildRequirementsFromPodSpec(*appdbPodSpec)),
124124
)
125+
scriptsVolumeMount := statefulset.CreateVolumeMount("agent-scripts", "/opt/scripts", statefulset.WithReadOnly(false))
126+
hooksVolumeMount := statefulset.CreateVolumeMount("hooks", "/hooks", statefulset.WithReadOnly(false))
125127

126128
initUpdateFunc := podtemplatespec.NOOP()
127129
if !architectures.IsRunningStaticArchitecture(om.Annotations) {
@@ -130,8 +132,6 @@ func appDbPodSpec(initContainerImage string, om om.MongoDBOpsManager) podtemplat
130132
// volumes of different containers.
131133
initUpdateFunc = func(templateSpec *corev1.PodTemplateSpec) {
132134
templateSpec.Spec.InitContainers = []corev1.Container{}
133-
scriptsVolumeMount := statefulset.CreateVolumeMount("agent-scripts", "/opt/scripts", statefulset.WithReadOnly(false))
134-
hooksVolumeMount := statefulset.CreateVolumeMount("hooks", "/hooks", statefulset.WithReadOnly(false))
135135
podtemplatespec.WithInitContainer(InitAppDbContainerName, buildAppDBInitContainer(initContainerImage, []corev1.VolumeMount{scriptsVolumeMount, hooksVolumeMount}))(templateSpec)
136136
}
137137
}
@@ -233,6 +233,12 @@ func CAConfigMapName(appDb om.AppDBSpec, log *zap.SugaredLogger) string {
233233
// and volumemounts for TLS.
234234
func tlsVolumes(appDb om.AppDBSpec, podVars *env.PodEnvVars, log *zap.SugaredLogger) podtemplatespec.Modification {
235235
volumesToAdd, volumeMounts := getTLSVolumesAndVolumeMounts(appDb, podVars, log)
236+
237+
// Add agent API key volume mount if not using vault and monitoring is enabled
238+
if !vault.IsVaultSecretBackend() && ShouldEnableMonitoring(podVars) {
239+
volumeMounts = append(volumeMounts, statefulset.CreateVolumeMount(AgentAPIKeyVolumeName, AgentAPIKeySecretPath))
240+
}
241+
236242
volumesFunc := func(spec *corev1.PodTemplateSpec) {
237243
for _, v := range volumesToAdd {
238244
podtemplatespec.WithVolume(v)(spec)
@@ -380,7 +386,7 @@ func AppDbStatefulSet(opsManager om.MongoDBOpsManager, podVars *env.PodEnvVars,
380386
externalDomain := appDb.GetExternalDomainForMemberCluster(scaler.MemberClusterName())
381387

382388
if ShouldEnableMonitoring(podVars) {
383-
monitoringModification = addMonitoringContainer(*appDb, *podVars, opts, externalDomain, log)
389+
monitoringModification = addMonitoringContainer(*appDb, *podVars, opts, externalDomain, architectures.IsRunningStaticArchitecture(opsManager.Annotations), log)
384390
} else {
385391
// Otherwise, let's remove for now every podTemplateSpec related to monitoring
386392
// We will apply them when enabling monitoring
@@ -390,7 +396,7 @@ func AppDbStatefulSet(opsManager om.MongoDBOpsManager, podVars *env.PodEnvVars,
390396
}
391397

392398
// We copy the Automation Agent command from community and add the agent startup parameters
393-
automationAgentCommand := construct.AutomationAgentCommand(true, opsManager.Spec.AppDB.GetAgentLogLevel(), opsManager.Spec.AppDB.GetAgentLogFile(), opsManager.Spec.AppDB.GetAgentMaxLogFileDurationHours())
399+
automationAgentCommand := construct.AutomationAgentCommand(architectures.IsRunningStaticArchitecture(opsManager.Annotations), true, opsManager.Spec.AppDB.GetAgentLogLevel(), opsManager.Spec.AppDB.GetAgentLogFile(), opsManager.Spec.AppDB.GetAgentMaxLogFileDurationHours())
394400
idx := len(automationAgentCommand) - 1
395401
automationAgentCommand[idx] += appDb.AutomationAgent.StartupParameters.ToCommandLineArgs()
396402

@@ -403,13 +409,10 @@ func AppDbStatefulSet(opsManager om.MongoDBOpsManager, podVars *env.PodEnvVars,
403409
MountPath: "/var/lib/automation/config/acVersion",
404410
}
405411

406-
// Here we ask to craete init containers which also creates required volumens.
412+
// Here we ask to create init containers which also creates required volumes.
407413
// Note that we provide empty images for init containers. They are not important
408-
// at this stage beucase later we will define our own init containers for non-static architecture.
409-
mod := construct.BuildMongoDBReplicaSetStatefulSetModificationFunction(&opsManager.Spec.AppDB, scaler, opts.MongodbImage, opts.AgentImage, "", "", true)
410-
if architectures.IsRunningStaticArchitecture(opsManager.Annotations) {
411-
mod = construct.BuildMongoDBReplicaSetStatefulSetModificationFunction(&opsManager.Spec.AppDB, scaler, opts.MongodbImage, opts.AgentImage, "", "", false)
412-
}
414+
// at this stage because later we will define our own init containers for non-static architecture.
415+
mod := construct.BuildMongoDBReplicaSetStatefulSetModificationFunction(&opsManager.Spec.AppDB, scaler, opts.MongodbImage, opts.AgentImage, "", "", !architectures.IsRunningStaticArchitecture(opsManager.Annotations), opts.InitAppDBImage)
413416

414417
sts := statefulset.New(
415418
mod,
@@ -493,7 +496,7 @@ func getVolumeMountIndexByName(mounts []corev1.VolumeMount, name string) int {
493496
// addMonitoringContainer returns a podtemplatespec modification that adds the monitoring container to the AppDB Statefulset.
494497
// Note that this replicates some code from the functions that do this for the base AppDB Statefulset. After many iterations
495498
// this was deemed to be an acceptable compromise to make code clearer and more maintainable.
496-
func addMonitoringContainer(appDB om.AppDBSpec, podVars env.PodEnvVars, opts AppDBStatefulSetOptions, externalDomain *string, log *zap.SugaredLogger) podtemplatespec.Modification {
499+
func addMonitoringContainer(appDB om.AppDBSpec, podVars env.PodEnvVars, opts AppDBStatefulSetOptions, externalDomain *string, isStatic bool, log *zap.SugaredLogger) podtemplatespec.Modification {
497500
var monitoringAcVolume corev1.Volume
498501
var monitoringACFunc podtemplatespec.Modification
499502

@@ -516,7 +519,7 @@ func addMonitoringContainer(appDB om.AppDBSpec, podVars env.PodEnvVars, opts App
516519
}
517520
// Construct the command by concatenating:
518521
// 1. The base command - from community
519-
command := construct.MongodbUserCommandWithAPIKeyExport
522+
command := construct.GetMongodbUserCommandWithAPIKeyExport(isStatic)
520523
command += "agent/mongodb-agent"
521524
command += " -healthCheckFilePath=" + monitoringAgentHealthStatusFilePathValue
522525
command += " -serveStatusPort=5001"

controllers/operator/construct/construction_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ func TestBuildStatefulSet_PersistentFlagStatic(t *testing.T) {
2828
mdb := mdbv1.NewReplicaSetBuilder().SetPersistent(nil).Build()
2929
set := DatabaseStatefulSet(*mdb, ReplicaSetOptions(GetPodEnvOptions()), zap.S())
3030
assert.Len(t, set.Spec.VolumeClaimTemplates, 1)
31-
assert.Len(t, set.Spec.Template.Spec.Containers[0].VolumeMounts, 7)
31+
assert.Len(t, set.Spec.Template.Spec.Containers[0].VolumeMounts, 8)
3232
assert.Len(t, set.Spec.Template.Spec.Containers[1].VolumeMounts, 7)
3333

3434
mdb = mdbv1.NewReplicaSetBuilder().SetPersistent(util.BooleanRef(true)).Build()
3535
set = DatabaseStatefulSet(*mdb, ReplicaSetOptions(GetPodEnvOptions()), zap.S())
3636
assert.Len(t, set.Spec.VolumeClaimTemplates, 1)
37-
assert.Len(t, set.Spec.Template.Spec.Containers[0].VolumeMounts, 7)
37+
assert.Len(t, set.Spec.Template.Spec.Containers[0].VolumeMounts, 8)
3838
assert.Len(t, set.Spec.Template.Spec.Containers[1].VolumeMounts, 7)
3939

4040
// If no persistence is set then we still mount init scripts
4141
mdb = mdbv1.NewReplicaSetBuilder().SetPersistent(util.BooleanRef(false)).Build()
4242
set = DatabaseStatefulSet(*mdb, ReplicaSetOptions(GetPodEnvOptions()), zap.S())
4343
assert.Len(t, set.Spec.VolumeClaimTemplates, 0)
44-
assert.Len(t, set.Spec.Template.Spec.Containers[0].VolumeMounts, 7)
44+
assert.Len(t, set.Spec.Template.Spec.Containers[0].VolumeMounts, 8)
4545
assert.Len(t, set.Spec.Template.Spec.Containers[1].VolumeMounts, 7)
4646
}
4747

@@ -111,6 +111,7 @@ func TestBuildStatefulSet_PersistentVolumeClaimSingleStatic(t *testing.T) {
111111
{Name: util.PvcNameData, MountPath: util.PvcMountPathData, SubPath: util.PvcNameData},
112112
{Name: util.PvcNameData, MountPath: util.PvcMountPathJournal, SubPath: util.PvcNameJournal},
113113
{Name: util.PvcNameData, MountPath: util.PvcMountPathLogs, SubPath: util.PvcNameLogs},
114+
{Name: PvcNameDatabaseScripts, MountPath: PvcMountPathScripts, ReadOnly: false},
114115
})
115116
}
116117

0 commit comments

Comments
 (0)