@@ -2,6 +2,8 @@ package search_controller
22
33import (
44"context"
5+ "crypto/sha256"
6+ "encoding/base32"
57"fmt"
68"strings"
79
@@ -83,12 +85,13 @@ func (r *MongoDBSearchReconcileHelper) reconcile(ctx context.Context, log *zap.S
8385return workflow .Failed (err )
8486}
8587
86- if err := r .ensureMongotConfig (ctx , mongotConfig ); err != nil {
8788mongotConfig := createMongotConfig (r .mdbSearch , r .db )
89+ configHash , err := r .ensureMongotConfig (ctx , mongotConfig )
90+ if err != nil {
8891return workflow .Failed (err )
8992}
9093
91- if err := r .createOrUpdateStatefulSet (ctx , log ); err != nil {
94+ if err := r .createOrUpdateStatefulSet (ctx , log , configHash ); err != nil {
9295return workflow .Failed (err )
9396}
9497
@@ -99,11 +102,11 @@ func (r *MongoDBSearchReconcileHelper) reconcile(ctx context.Context, log *zap.S
99102return workflow .OK ()
100103}
101104
102- func (r * MongoDBSearchReconcileHelper ) createOrUpdateStatefulSet (ctx context.Context , log * zap.SugaredLogger ) error {
105+ func (r * MongoDBSearchReconcileHelper ) createOrUpdateStatefulSet (ctx context.Context , log * zap.SugaredLogger , mongotConfigHash string ) error {
103106stsName := r .mdbSearch .StatefulSetNamespacedName ()
104107sts := & appsv1.StatefulSet {ObjectMeta : metav1.ObjectMeta {Name : stsName .Name , Namespace : stsName .Namespace }}
105108op , err := controllerutil .CreateOrUpdate (ctx , r .client , sts , func () error {
106- stsModification := construct .CreateSearchStatefulSetFunc (r .mdbSearch , r .db )
109+ stsModification := construct .CreateSearchStatefulSetFunc (r .mdbSearch , r .db , mongotConfigHash )
107110stsModification (sts )
108111return nil
109112})
@@ -135,10 +138,10 @@ func (r *MongoDBSearchReconcileHelper) ensureSearchService(ctx context.Context,
135138return nil
136139}
137140
138- func (r * MongoDBSearchReconcileHelper ) ensureMongotConfig (ctx context.Context , mongotConfig mongot.Config ) error {
141+ func (r * MongoDBSearchReconcileHelper ) ensureMongotConfig (ctx context.Context , mongotConfig mongot.Config ) ( string , error ) {
139142configData , err := yaml .Marshal (mongotConfig )
140143if err != nil {
141- return err
144+ return "" , err
142145}
143146
144147cmName := r .mdbSearch .MongotConfigConfigMapNamespacedName ()
@@ -157,12 +160,13 @@ func (r *MongoDBSearchReconcileHelper) ensureMongotConfig(ctx context.Context, m
157160return controllerutil .SetOwnerReference (r .mdbSearch , cm , r .client .Scheme ())
158161})
159162if err != nil {
160- return err
163+ return "" , err
161164}
162165
163166zap .S ().Debugf ("Updated mongot config yaml config map: %v (%s) with the following configuration: %s" , cmName , op , string (configData ))
164167
165- return nil
168+ hashBytes := sha256 .Sum256 (configData )
169+ return base32 .StdEncoding .WithPadding (base32 .NoPadding ).EncodeToString (hashBytes [:]), nil
166170}
167171
168172func buildSearchHeadlessService (search * searchv1.MongoDBSearch ) corev1.Service {
0 commit comments