@@ -63,15 +63,18 @@ const (
6363 mongodbImageEnv = "MONGODB_IMAGE"
6464 mongodbRepoUrl = "MONGODB_REPO_URL"
6565 mongodbToolsVersionEnv = "MONGODB_TOOLS_VERSION"
66+ headlessAgentEnv = "HEADLESS_AGENT"
67+ podNamespaceEnv = "POD_NAMESPACE"
68+ automationConfigEnv = "AUTOMATION_CONFIG_MAP"
6669
67- AutomationConfigKey = "automation -config"
70+ AutomationConfigKey = "cluster -config.json "
6871 agentName = "mongodb-agent"
6972 mongodbName = "mongod"
7073 versionUpgradeHookName = "mongod-posthook"
7174 dataVolumeName = "data-volume"
7275 versionManifestFilePath = "/usr/local/version_manifest.json"
7376 readinessProbePath = "/var/lib/mongodb-mms-automation/probes/readinessprobe"
74- clusterFilePath = "/var/lib/automation/config/automation -config"
77+ clusterFilePath = "/var/lib/automation/config/cluster -config.json "
7578 operatorServiceAccountName = "mongodb-kubernetes-operator"
7679 agentHealthStatusFilePathValue = "/var/log/mongodb-mms-automation/healthstatus/agent-health-status.json"
7780
@@ -185,7 +188,7 @@ func (r *ReplicaSetReconciler) Reconcile(request reconcile.Request) (reconcile.R
185188 if err := r .ensureAutomationConfig (mdb ); err != nil {
186189 return status .Update (r .client .Status (), & mdb ,
187190 statusOptions ().
188- withMessage (Error , fmt .Sprintf ("error creating automation config config map : %s" , err )).
191+ withMessage (Error , fmt .Sprintf ("error creating automation config secret : %s" , err )).
189192 withFailedPhase (),
190193 )
191194 }
@@ -249,6 +252,7 @@ func (r *ReplicaSetReconciler) Reconcile(request reconcile.Request) (reconcile.R
249252 if ! ready {
250253 return status .Update (r .client .Status (), & mdb ,
251254 statusOptions ().
255+ withMembers (int (currentSts .Status .ReadyReplicas )).
252256 withMessage (Info , fmt .Sprintf ("StatefulSet %s/%s is not yet ready, retrying in 10 seconds" , mdb .Namespace , mdb .Name )).
253257 withPendingPhase (10 ),
254258 )
@@ -356,7 +360,7 @@ func (r *ReplicaSetReconciler) isStatefulSetReady(mdb mdbv1.MongoDB, existingSta
356360 //some issues with nil/empty maps not being compared correctly otherwise
357361 areEqual := bytes .Equal (stsCopyBytes , stsBytes )
358362
359- isReady := statefulset .IsReady (* existingStatefulSet , mdb .Spec . Members )
363+ isReady := statefulset .IsReady (* existingStatefulSet , mdb .ReplicasThisReconciliation () )
360364 if existingStatefulSet .Spec .UpdateStrategy .Type == appsv1 .OnDeleteStatefulSetStrategyType && ! isReady {
361365 r .log .Info ("StatefulSet has left ready state, version upgrade in progress" )
362366 annotations := map [string ]string {
@@ -492,6 +496,7 @@ func buildService(mdb mdbv1.MongoDB) corev1.Service {
492496 SetServiceType (corev1 .ServiceTypeClusterIP ).
493497 SetClusterIP ("None" ).
494498 SetPort (27017 ).
499+ SetPublishNotReadyAddresses (true ).
495500 Build ()
496501}
497502
@@ -519,17 +524,17 @@ func (r ReplicaSetReconciler) buildAutomationConfigSecret(mdb mdbv1.MongoDB) (co
519524
520525 authModification , err := scram .EnsureScram (r .client , mdb .ScramCredentialsNamespacedName (), mdb )
521526 if err != nil {
522- return corev1.Secret {}, err
527+ return corev1.Secret {}, errors . Errorf ( "could not ensure scram credentials: %s" , err )
523528 }
524529
525530 tlsModification , err := getTLSConfigModification (r .client , mdb )
526531 if err != nil {
527- return corev1.Secret {}, err
532+ return corev1.Secret {}, errors . Errorf ( "could not configure TLS modification: %s" , err )
528533 }
529534
530535 currentAC , err := getCurrentAutomationConfig (r .client , mdb )
531536 if err != nil {
532- return corev1.Secret {}, err
537+ return corev1.Secret {}, errors . Errorf ( "could not read existing automation config: %s" , err )
533538 }
534539
535540 ac , err := buildAutomationConfig (
@@ -540,11 +545,11 @@ func (r ReplicaSetReconciler) buildAutomationConfigSecret(mdb mdbv1.MongoDB) (co
540545 tlsModification ,
541546 )
542547 if err != nil {
543- return corev1.Secret {}, err
548+ return corev1.Secret {}, fmt . Errorf ( "could not build automation config: %s" , err )
544549 }
545550 acBytes , err := json .Marshal (ac )
546551 if err != nil {
547- return corev1.Secret {}, err
552+ return corev1.Secret {}, fmt . Errorf ( "could not marshal automation config: %s" , err )
548553 }
549554
550555 return secret .Builder ().
@@ -590,7 +595,7 @@ func isChangingVersion(mdb mdbv1.MongoDB) bool {
590595 return false
591596}
592597
593- func mongodbAgentContainer (volumeMounts []corev1.VolumeMount ) container.Modification {
598+ func mongodbAgentContainer (automationConfigSecretName string , volumeMounts []corev1.VolumeMount ) container.Modification {
594599 return container .Apply (
595600 container .WithName (agentName ),
596601 container .WithImage (os .Getenv (agentImageEnv )),
@@ -609,6 +614,23 @@ func mongodbAgentContainer(volumeMounts []corev1.VolumeMount) container.Modifica
609614 },
610615 ),
611616 container .WithEnvs (
617+ corev1.EnvVar {
618+ Name : headlessAgentEnv ,
619+ Value : "true" ,
620+ },
621+ corev1.EnvVar {
622+ Name : podNamespaceEnv ,
623+ ValueFrom : & corev1.EnvVarSource {
624+ FieldRef : & corev1.ObjectFieldSelector {
625+ APIVersion : "v1" ,
626+ FieldPath : "metadata.namespace" ,
627+ },
628+ },
629+ },
630+ corev1.EnvVar {
631+ Name : automationConfigEnv ,
632+ Value : automationConfigSecretName ,
633+ },
612634 corev1.EnvVar {
613635 Name : agentHealthStatusFilePathEnv ,
614636 Value : agentHealthStatusFilePathValue ,
@@ -705,7 +727,7 @@ func buildStatefulSetModificationFunction(mdb mdbv1.MongoDB) statefulset.Modific
705727 podtemplatespec .WithVolume (hooksVolume ),
706728 podtemplatespec .WithVolume (automationConfigVolume ),
707729 podtemplatespec .WithServiceAccount (operatorServiceAccountName ),
708- podtemplatespec .WithContainer (agentName , mongodbAgentContainer ([]corev1.VolumeMount {agentHealthStatusVolumeMount , automationConfigVolumeMount , dataVolume })),
730+ podtemplatespec .WithContainer (agentName , mongodbAgentContainer (mdb . AutomationConfigSecretName (), []corev1.VolumeMount {agentHealthStatusVolumeMount , automationConfigVolumeMount , dataVolume })),
709731 podtemplatespec .WithContainer (mongodbName , mongodbContainer (mdb .Spec .Version , []corev1.VolumeMount {mongodHealthStatusVolumeMount , dataVolume , hooksVolumeMount })),
710732 podtemplatespec .WithInitContainer (versionUpgradeHookName , versionUpgradeHookInit ([]corev1.VolumeMount {hooksVolumeMount })),
711733 buildTLSPodSpecModification (mdb ),
0 commit comments