- 
                Notifications
    
You must be signed in to change notification settings  - Fork 23
 
CLOUDP-353160 [Search] Implement gRPC and mTLS #527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            15 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3ec055e
              
                [Search] Implement gRPC and mTLS
              
              
                fealebenpae 6593b18
              
                Merge remote-tracking branch 'origin/master' into fealebenpae/search-…
              
              
                fealebenpae b791c36
              
                fix external tests and snippets
              
              
                fealebenpae 53e9334
              
                try fix enterprise tests
              
              
                fealebenpae cdc55d4
              
                update unit tests for wireproto annotation
              
              
                fealebenpae 83e9b33
              
                bump version of mongod in external snippets
              
              
                fealebenpae 14bedcf
              
                try fix external tests take 2
              
              
                fealebenpae 8dc3d81
              
                cheat linter
              
              
                fealebenpae f4a1a34
              
                remove searchCoordinator polyfill from external snippets
              
              
                fealebenpae 75c83de
              
                update the port in external snippets
              
              
                fealebenpae 83d91a0
              
                remove upgrade test
              
              
                fealebenpae ab1718f
              
                expand on the wireproto override
              
              
                fealebenpae cb83dbc
              
                changelog
              
              
                fealebenpae 326ad85
              
                Merge branch 'master' into fealebenpae/search-grpc
              
              
                fealebenpae aa0dc82
              
                rename force-wireproto annotation
              
              
                fealebenpae File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            7 changes: 7 additions & 0 deletions
          
          7 
        
  changelog/20251030_feature_update_mongodb_search_to_use_grpc_and_mtls_for.md
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| kind: feature | ||
| date: 2025-10-30 | ||
| --- | ||
| 
     | 
||
| * **MongoDBSearch**: Switch to gRPC and mTLS for internal communication | ||
| Since MCK 1.4 the `mongod` and `mongot` processess communicated using the MongoDB Wire Protocol and used keyfile authentication. This release switches that to gRPC with mTLS authentication. gRPC will allow for load-balancing search queries against multiple `mongot` processes in the future, and mTLS decouples the internal cluster authentication mode and credentials among `mongod` processes from the connection to the `mongot` process. The Operator will automatically enable gRPC for existing and new workloads, and will enable mTLS authentication if both Database Server and `MongoDBSearch` resource are configured for TLS. | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -3,6 +3,7 @@ package operator | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strconv" | ||
| "testing" | ||
| 
     | 
||
| "github.com/ghodss/yaml" | ||
| 
          
            
          
           | 
    @@ -100,6 +101,19 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong | |
| if search.Spec.LogLevel != "" { | ||
| logLevel = string(search.Spec.LogLevel) | ||
| } | ||
| 
     | 
||
| var wireprotoServer *mongot.ConfigWireproto | ||
| if search.IsWireprotoEnabled() { | ||
| wireprotoServer = &mongot.ConfigWireproto{ | ||
| Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotWireprotoPort()), | ||
| Authentication: &mongot.ConfigAuthentication{ | ||
| Mode: "keyfile", | ||
| KeyFile: searchcontroller.TempKeyfilePath, | ||
| }, | ||
| TLS: &mongot.ConfigWireprotoTLS{Mode: mongot.ConfigTLSModeDisabled}, | ||
| } | ||
| } | ||
| 
     | 
||
| return mongot.Config{ | ||
| SyncSource: mongot.ConfigSyncSource{ | ||
| ReplicaSet: mongot.ConfigReplicaSet{ | ||
| 
        
          
        
         | 
    @@ -115,14 +129,11 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong | |
| DataPath: searchcontroller.MongotDataPath, | ||
| }, | ||
| Server: mongot.ConfigServer{ | ||
| Wireproto: &mongot.ConfigWireproto{ | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we still keep a wireproto test as long as it is possible to enabled it?  | 
||
| Address: "0.0.0.0:27027", | ||
| Authentication: &mongot.ConfigAuthentication{ | ||
| Mode: "keyfile", | ||
| KeyFile: searchcontroller.TempKeyfilePath, | ||
| }, | ||
| TLS: mongot.ConfigTLS{Mode: mongot.ConfigTLSModeDisabled}, | ||
| Grpc: &mongot.ConfigGrpc{ | ||
| Address: fmt.Sprintf("0.0.0.0:%d", search.GetMongotGrpcPort()), | ||
| TLS: &mongot.ConfigGrpcTLS{Mode: mongot.ConfigTLSModeDisabled}, | ||
| }, | ||
| Wireproto: wireprotoServer, | ||
| }, | ||
| Metrics: mongot.ConfigMetrics{ | ||
| Enabled: true, | ||
| 
          
            
          
           | 
    @@ -168,35 +179,66 @@ func TestMongoDBSearchReconcile_MissingSource(t *testing.T) { | |
| 
     | 
||
| func TestMongoDBSearchReconcile_Success(t *testing.T) { | ||
| ctx := context.Background() | ||
| search := newMongoDBSearch("search", mock.TestNamespace, "mdb") | ||
| search.Spec.LogLevel = "WARN" | ||
| 
     | 
||
| mdbc := newMongoDBCommunity("mdb", mock.TestNamespace) | ||
| reconciler, c := newSearchReconciler(mdbc, search) | ||
| 
     | 
||
| res, err := reconciler.Reconcile( | ||
| ctx, | ||
| reconcile.Request{NamespacedName: types.NamespacedName{Name: search.Name, Namespace: search.Namespace}}, | ||
| ) | ||
| expected, _ := workflow.OK().ReconcileResult() | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, expected, res) | ||
| 
     | 
||
| svc := &corev1.Service{} | ||
| err = c.Get(ctx, search.SearchServiceNamespacedName(), svc) | ||
| assert.NoError(t, err) | ||
| tests := []struct { | ||
| name string | ||
| withWireproto bool | ||
| }{ | ||
| { | ||
| name: "grpc only (default)", | ||
| withWireproto: false, | ||
| }, | ||
| { | ||
| name: "grpc + wireproto via annotation", | ||
| withWireproto: true, | ||
| }, | ||
| } | ||
| 
     | 
||
| cm := &corev1.ConfigMap{} | ||
| err = c.Get(ctx, search.MongotConfigConfigMapNamespacedName(), cm) | ||
| assert.NoError(t, err) | ||
| expectedConfig := buildExpectedMongotConfig(search, mdbc) | ||
| configYaml, err := yaml.Marshal(expectedConfig) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, string(configYaml), cm.Data[searchcontroller.MongotConfigFilename]) | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| search := newMongoDBSearch("search", mock.TestNamespace, "mdb") | ||
| search.Spec.LogLevel = "WARN" | ||
| search.Annotations = map[string]string{ | ||
| searchv1.ForceWireprotoAnnotation: strconv.FormatBool(tc.withWireproto), | ||
| } | ||
| 
     | 
||
| sts := &appsv1.StatefulSet{} | ||
| err = c.Get(ctx, search.StatefulSetNamespacedName(), sts) | ||
| assert.NoError(t, err) | ||
| mdbc := newMongoDBCommunity("mdb", mock.TestNamespace) | ||
| reconciler, c := newSearchReconciler(mdbc, search) | ||
| 
     | 
||
| res, err := reconciler.Reconcile( | ||
| ctx, | ||
| reconcile.Request{NamespacedName: types.NamespacedName{Name: search.Name, Namespace: search.Namespace}}, | ||
| ) | ||
| expected, _ := workflow.OK().ReconcileResult() | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, expected, res) | ||
| 
     | 
||
| svc := &corev1.Service{} | ||
| err = c.Get(ctx, search.SearchServiceNamespacedName(), svc) | ||
| assert.NoError(t, err) | ||
| servicePortNames := []string{} | ||
| for _, port := range svc.Spec.Ports { | ||
| servicePortNames = append(servicePortNames, port.Name) | ||
| } | ||
| expectedPortNames := []string{"mongot-grpc", "metrics", "healthcheck"} | ||
| if tc.withWireproto { | ||
| expectedPortNames = append(expectedPortNames, "mongot-wireproto") | ||
| } | ||
| assert.ElementsMatch(t, expectedPortNames, servicePortNames) | ||
| 
     | 
||
| cm := &corev1.ConfigMap{} | ||
| err = c.Get(ctx, search.MongotConfigConfigMapNamespacedName(), cm) | ||
| assert.NoError(t, err) | ||
| expectedConfig := buildExpectedMongotConfig(search, mdbc) | ||
| configYaml, err := yaml.Marshal(expectedConfig) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, string(configYaml), cm.Data[searchcontroller.MongotConfigFilename]) | ||
| 
     | 
||
| sts := &appsv1.StatefulSet{} | ||
| err = c.Get(ctx, search.StatefulSetNamespacedName(), sts) | ||
| assert.NoError(t, err) | ||
| }) | ||
| } | ||
| } | ||
| 
     | 
||
| func checkSearchReconcileFailed( | ||
| 
          
            
          
           | 
    ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT!