Skip to content

Changed the order of CreateOrUpdate functions #1623

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 2 commits into from
Sep 30, 2024
Merged

Conversation

lsierant
Copy link
Collaborator

This PR changes the way we do CreateOrUpdate functions.

It was: Get the Update if exists else Create.
For some cases after the resource was created in the same reconcile event, another execution will again hit into Create case as the informer caches weren't yet refreshed. And that resulted in errors.

@lsierant lsierant changed the title Changed the order or CreateOrUpdate functions Changed the order of CreateOrUpdate functions Sep 28, 2024
@lsierant lsierant merged commit a6075d4 into master Sep 30, 2024
49 of 50 checks passed
@lsierant lsierant deleted the fix-create-or-update branch September 30, 2024 08:32
if apiErrors.IsNotFound(err) {
return getUpdateCreator.CreateConfigMap(ctx, cm)
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i am a bit late to the party but we could have saved the else and just return, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

When I see such if/else I always wonder if I should leave a comment
Should we try to be consistent in the whole codebase about that ?
We use both currently

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should add a linter for that and we should be fine. Problem: mco doesn't have that linter configured

fealebenpae pushed a commit to mongodb/mongodb-kubernetes that referenced this pull request Apr 10, 2025
This patch contains a number of improvements tried in order to deflake
e2e tests. Overally result is quite successful: [100% green
EVG](https://spruce.mongodb.com/version/66f81d4d24506900071e3563/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC)
and progress with
[flakes](https://ui.honeycomb.io/mongodb-4b/environments/production/result/8p2zFkfJ2Pz)

Changes:
- deleting kind clusters before creating kind clusters; controllable by
new DELETE_KIND_NETWORK env, which is true only in EVG run (set in
evg-private-context only). This one is actually of a dubious value as
we're doing docker prune in teardown already. But it's useful also for
our own evg hosts as we've never cleared docker network once created.
- setting the subnet for docker network explicitly to 172.18.0.0/16. We
hardcode usage of this subnet locally, and docker network in evg started
to assign subnets on different IPs. That's why sometimes our
"interconnected" tests were passing - when docker network created in evg
got lucky subnet (172.18)!
- added ttl and refresh to coredns config map - cannot harm, not sure if
helps
- changed the order of CreateOrUpdate to always update first and if 404
then create. Previously we had get first which was susceptible to not
refreshed informers and CreateOrUpdate was going directly to Create
which was failing. Details in [PR in
MCO](mongodb/mongodb-kubernetes-operator#1623)
fealebenpae pushed a commit to mongodb/mongodb-kubernetes that referenced this pull request Apr 21, 2025
This patch contains a number of improvements tried in order to deflake
e2e tests. Overally result is quite successful: [100% green
EVG](https://spruce.mongodb.com/version/66f81d4d24506900071e3563/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC)
and progress with
[flakes](REDACTED)

Changes:
- deleting kind clusters before creating kind clusters; controllable by
new DELETE_KIND_NETWORK env, which is true only in EVG run (set in
evg-private-context only). This one is actually of a dubious value as
we're doing docker prune in teardown already. But it's useful also for
our own evg hosts as we've never cleared docker network once created.
- setting the subnet for docker network explicitly to 172.18.0.0/16. We
hardcode usage of this subnet locally, and docker network in evg started
to assign subnets on different IPs. That's why sometimes our
"interconnected" tests were passing - when docker network created in evg
got lucky subnet (172.18)!
- added ttl and refresh to coredns config map - cannot harm, not sure if
helps
- changed the order of CreateOrUpdate to always update first and if 404
then create. Previously we had get first which was susceptible to not
refreshed informers and CreateOrUpdate was going directly to Create
which was failing. Details in [PR in
MCO](mongodb/mongodb-kubernetes-operator#1623)
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.

6 participants