Skip to content

Commit 26b755f

Browse files
CLOUDP-93590: Service name configurable (#616)
1 parent 6b4162c commit 26b755f

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

api/v1/mongodbcommunity_types.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,12 @@ func (m MongoDBCommunity) Hosts() []string {
524524
return hosts
525525
}
526526

527-
// ServiceName returns the name of the Service that should be created for
528-
// this resource
527+
// ServiceName returns the name of the Service that should be created for this resource
529528
func (m MongoDBCommunity) ServiceName() string {
529+
serviceName := m.Spec.StatefulSetConfiguration.SpecWrapper.Spec.ServiceName
530+
if serviceName != "" {
531+
return serviceName
532+
}
530533
return m.Name + "-svc"
531534
}
532535

config/samples/arbitrary_statefulset_configuration/mongodb.com_v1_custom_volume_cr.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ spec:
2323

2424
statefulSet:
2525
spec:
26+
# Name for the service object created by the operator
2627
serviceName: example-openshift-mongodb-svc
2728
selector: {}
2829
# Specifies a size for the data volume different from the default 10Gi

docs/RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Support SHA-1 as an authentication method.
99
- Upgraded `mongodbcommunity.mongodbcommunity.mongodb.com` CRD to `v1` from `v1beta1`
1010
* Users upgrading their CRD from v1beta1 to v1 need to set: `spec.preserveUnknownFields` to `false` in the CRD file `config/crd/bases/mongodbcommunity.mongodb.com_mongodbcommunity.yaml` before applying the CRD to the cluster.
11+
- Made service name configurable in mongdb custom resource with statefulSet.spec.serviceName
1112

1213
## Updated Image Tags
1314

test/e2e/mongodbtests/mongodbtests.go

+13
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,19 @@ func BasicFunctionality(mdb *mdbv1.MongoDBCommunity) func(*testing.T) {
289289
}
290290
}
291291

292+
// ServiceWithNameExists checks whether a service with the name serviceName exists
293+
func ServiceWithNameExists(serviceName string, namespace string) func(t *testing.T) {
294+
return func(t *testing.T) {
295+
serviceNamespacedName := types.NamespacedName{Name: serviceName, Namespace: namespace}
296+
srv := corev1.Service{}
297+
err := e2eutil.TestClient.Get(context.TODO(), serviceNamespacedName, &srv)
298+
if err != nil {
299+
t.Fatal(err)
300+
}
301+
t.Logf("Service with name %s exists", serviceName)
302+
}
303+
}
304+
292305
// DeletePod will delete a pod that belongs to this MongoDB resource's StatefulSet
293306
func DeletePod(mdb *mdbv1.MongoDBCommunity, podNum int) func(*testing.T) {
294307
return func(t *testing.T) {

test/e2e/statefulset_arbitrary_config/statefulset_arbitrary_config_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ func TestStatefulSetArbitraryConfig(t *testing.T) {
3434

3535
mdb.Spec.StatefulSetConfiguration.SpecWrapper.Spec.Template.Spec.Containers[1].ReadinessProbe = &corev1.Probe{TimeoutSeconds: 100}
3636

37+
customServiceName := "database"
38+
mdb.Spec.StatefulSetConfiguration.SpecWrapper.Spec.ServiceName = customServiceName
39+
3740
tester, err := mongotester.FromResource(t, mdb)
3841
if err != nil {
3942
t.Fatal(err)
4043
}
4144

4245
t.Run("Create MongoDB Resource", mongodbtests.CreateMongoDBResource(&mdb, ctx))
4346
t.Run("Basic tests", mongodbtests.BasicFunctionality(&mdb))
47+
t.Run("Test setting Service Name", mongodbtests.ServiceWithNameExists(customServiceName, mdb.Namespace))
4448
t.Run("Test Basic Connectivity", tester.ConnectivitySucceeds())
4549
t.Run("AutomationConfig has the correct version", mongodbtests.AutomationConfigVersionHasTheExpectedVersion(&mdb, 1))
4650
t.Run("Container has been merged by name", mongodbtests.StatefulSetContainerConditionIsTrue(&mdb, "mongodb-agent", func(container corev1.Container) bool {

0 commit comments

Comments
 (0)