Skip to content

CLOUDP-93590: Service name configurable #616

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 6 commits into from
Jul 6, 2021

Conversation

FlorentinaSimlinger
Copy link
Contributor

@FlorentinaSimlinger FlorentinaSimlinger commented Jul 5, 2021

All Submissions:

  • Have you opened an Issue before filing this PR?
  • Have you signed our CLA?
  • Have you signed all of your commits?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Put closes #XXXX in your comment to auto-close the issue that your PR fixes (if such).

Tested by adding
statefulSet:
spec:
serviceName: database
to the custom resource yaml file and running make run to observe that the serviceName field now contains database and by setting the service name in statefulset_arbitrary_config_test.go and checking the name is correctly set in mongodbtests.go

@FlorentinaSimlinger FlorentinaSimlinger changed the title Cloudp 93590 service name configurable CLOUDP 93590: Service name configurable Jul 5, 2021
@FlorentinaSimlinger FlorentinaSimlinger changed the title CLOUDP 93590: Service name configurable CLOUDP-93590: Service name configurable Jul 5, 2021
Copy link
Contributor

@irajdeep irajdeep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality looks good -- added some comments.

Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Had a few small comments/suggestions

@@ -523,8 +523,12 @@ func (m MongoDBCommunity) Hosts() []string {
}

// ServiceName returns the name of the Service that should be created for
// this resource
// this resource which is either the default name resourcename-svc or the user defined name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I don't think implementation details necessarily need to be included in the docstring. The new text added is re-stating the body of the function. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

@@ -289,6 +289,19 @@ func BasicFunctionality(mdb *mdbv1.MongoDBCommunity) func(*testing.T) {
}
}

// ServiceWithNameExists checks whether a service with the name serviceName exists
func ServiceWithNameExists(mdb *mdbv1.MongoDBCommunity, serviceName string) func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] we are introducing a dependency on *mdbv1.MongoDBCommunity when in realsity all we actually care about is the namespace. This signature could be (namespace, serviceName string) or even (nsName types.NamespacedName)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should happen more often in functions, I think mongodbtests.go has quite a few such examples -- e.g StatefulSetHasOwnerReference ...

tester, err := mongotester.FromResource(t, mdb)
if err != nil {
t.Fatal(err)
}

t.Run("Create MongoDB Resource", mongodbtests.CreateMongoDBResource(&mdb, ctx))
t.Run("Basic tests", mongodbtests.BasicFunctionality(&mdb))
t.Run("Test setting Service Name", mongodbtests.ServiceWithNameExists(&mdb, serviceName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are now only testing the service creation when it is specified in the StatefulSetSpec override, we could add this to the BasicTests tests which are run in every test to make sure the service name is as expected when not overriding through sts override. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean adding a call to ServiceWithNameExists to BasicFunctionality and call it with m.Name + "-svc"?

Copy link
Contributor

@bznein bznein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall implementation LGTM, I have only one main question here: what happens if a user here creates two resources with the same name service name?

I guess this is the user's responsibility so no need to implement weird logic to cover this case, but is there maybe a clean way to identify this situation?

Other two minor things:

  • We should add it to the release notes doc
  • We could maybe provide an example in the samples directory

@irajdeep
Copy link
Contributor

irajdeep commented Jul 5, 2021

what happens if a user here creates two resources with the same name service name?

How would that be possible? you mean create the service manually?

@bznein
Copy link
Contributor

bznein commented Jul 5, 2021

what happens if a user here creates two resources with the same name service name?

How would that be possible? you mean create the service manually?

I mean creating two resources and use the same value for both in .Spec.StatefulSetConfiguration.SpecWrapper.Spec.ServiceName.

@irajdeep
Copy link
Contributor

irajdeep commented Jul 5, 2021

I mean creating two resources and use the same value for both in .Spec.StatefulSetConfiguration.SpecWrapper.Spec.ServiceName

In this case, the reconcile should just fail and report it to status -- which is what will happen currently.

@bznein
Copy link
Contributor

bznein commented Jul 5, 2021

I mean creating two resources and use the same value for both in .Spec.StatefulSetConfiguration.SpecWrapper.Spec.ServiceName

In this case, the reconcile should just fail and report it to status -- which is what will happen currently.

SGTM!

Comment on lines +37 to +38
customServiceName := "database"
mdb.Spec.StatefulSetConfiguration.SpecWrapper.Spec.ServiceName = customServiceName
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the parameter to customServiceName to make it clearer to the reader that this is a name that is set by the user. Happy to revert if original parameter name is preferred.

Copy link
Contributor

@irajdeep irajdeep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@FlorentinaSimlinger FlorentinaSimlinger force-pushed the CLOUDP-93590_service_name_configurable branch from 15b2a6f to f554508 Compare July 6, 2021 12:48
Copy link
Contributor

@bznein bznein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@FlorentinaSimlinger FlorentinaSimlinger merged commit 26b755f into master Jul 6, 2021
@FlorentinaSimlinger FlorentinaSimlinger deleted the CLOUDP-93590_service_name_configurable branch July 6, 2021 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants