Skip to content

Commit 9906c42

Browse files
committed
Adjusted schema syntax for optionals
1 parent 43002af commit 9906c42

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

controllers/operator/mongodbsearch_controller_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package operator
33
import (
44
"context"
55
"fmt"
6+
"k8s.io/utils/ptr"
67
"testing"
78

89
"github.com/ghodss/yaml"
@@ -79,17 +80,17 @@ func buildExpectedMongotConfig(search *searchv1.MongoDBSearch, mdbc *mdbcv1.Mong
7980
HostAndPort: fmt.Sprintf("%s.%s.svc.cluster.local:%d", mdbc.Name+"-svc", search.Namespace, 27017),
8081
Username: "__system",
8182
PasswordFile: "/tmp/keyfile",
82-
TLS: false,
83-
ReadPreference: "secondaryPreferred",
83+
TLS: ptr.To(false),
84+
ReadPreference: ptr.To("secondaryPreferred"),
8485
},
8586
},
8687
Storage: mongot.ConfigStorage{
8788
DataPath: "/mongot/data/config.yml",
8889
},
8990
Server: mongot.ConfigServer{
90-
Wireproto: mongot.ConfigWireproto{
91+
Wireproto: &mongot.ConfigWireproto{
9192
Address: "0.0.0.0:27027",
92-
Authentication: mongot.ConfigAuthentication{
93+
Authentication: &mongot.ConfigAuthentication{
9394
Mode: "keyfile",
9495
KeyFile: "/tmp/keyfile",
9596
},

controllers/search_controller/mongodbsearch_reconcile_helper.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/sha256"
66
"encoding/base32"
77
"fmt"
8+
"k8s.io/utils/ptr"
89
"strings"
910

1011
"github.com/blang/semver"
@@ -210,21 +211,20 @@ func createMongotConfig(search *searchv1.MongoDBSearch, db SearchSourceDBResourc
210211
return mongot.Config{
211212
SyncSource: mongot.ConfigSyncSource{
212213
ReplicaSet: mongot.ConfigReplicaSet{
213-
HostAndPort: fmt.Sprintf("%s.%s.svc.cluster.local:%d", db.DatabaseServiceName(), db.GetNamespace(), db.DatabasePort()),
214-
Username: "__system",
215-
PasswordFile: "/tmp/keyfile",
216-
TLS: false,
217-
// TODO check
218-
ReadPreference: "secondaryPreferred",
214+
HostAndPort: fmt.Sprintf("%s.%s.svc.cluster.local:%d", db.DatabaseServiceName(), db.GetNamespace(), db.DatabasePort()),
215+
Username: "__system",
216+
PasswordFile: "/tmp/keyfile",
217+
TLS: ptr.To(false),
218+
ReadPreference: ptr.To("secondaryPreferred"),
219219
},
220220
},
221221
Storage: mongot.ConfigStorage{
222222
DataPath: "/mongot/data/config.yml",
223223
},
224224
Server: mongot.ConfigServer{
225-
Wireproto: mongot.ConfigWireproto{
225+
Wireproto: &mongot.ConfigWireproto{
226226
Address: "0.0.0.0:27027",
227-
Authentication: mongot.ConfigAuthentication{
227+
Authentication: &mongot.ConfigAuthentication{
228228
Mode: "keyfile",
229229
KeyFile: "/tmp/keyfile",
230230
},

mongodb-community-operator/pkg/mongot/mongot_config.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,42 @@ type ConfigSyncSource struct {
1414
}
1515

1616
type ConfigReplicaSet struct {
17-
HostAndPort string `json:"hostAndPort"`
18-
Username string `json:"username"`
19-
PasswordFile string `json:"passwordFile"`
20-
TLS bool `json:"tls"`
21-
ReadPreference string `json:"readPreference"`
17+
HostAndPort string `json:"hostAndPort"`
18+
Username string `json:"username"`
19+
PasswordFile string `json:"passwordFile"`
20+
TLS *bool `json:"tls,omitempty"`
21+
ReadPreference *string `json:"readPreference,omitempty"`
2222
}
2323

2424
type ConfigStorage struct {
2525
DataPath string `json:"dataPath"`
2626
}
2727

2828
type ConfigServer struct {
29-
Wireproto ConfigWireproto `json:"wireproto"`
29+
Wireproto *ConfigWireproto `json:"wireproto,omitempty"`
3030
}
3131

3232
type ConfigWireproto struct {
33-
Address string `json:"address"`
34-
Authentication ConfigAuthentication `json:"authentication"`
35-
TLS ConfigTLS `json:"tls"`
33+
Address string `json:"address"`
34+
Authentication *ConfigAuthentication `json:"authentication,omitempty"`
35+
TLS ConfigTLS `json:"tls"`
3636
}
3737

3838
type ConfigAuthentication struct {
3939
Mode string `json:"mode"`
4040
KeyFile string `json:"keyFile"`
4141
}
4242

43+
type ConfigTLSMode string
44+
45+
const (
46+
ConfigTLSModeTLS ConfigTLSMode = "TLS"
47+
ConfigTLSModeDisabled ConfigTLSMode = "Disabled"
48+
)
49+
4350
type ConfigTLS struct {
44-
Mode string `json:"mode"`
51+
Mode ConfigTLSMode `json:"mode"`
52+
CertificateKeyFile *string `json:"certificateKeyFile,omitempty"`
4553
}
4654

4755
type ConfigMetrics struct {

0 commit comments

Comments
 (0)