Fix shard render when the last backend is removed #1015
Merged
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.
Backend template rendering is the most CPU consumption of the reconciliation process, so sharding backends reduces haproxy ingress processing on workloads with thousands of services. Once sharding, haproxy ingress can update only the shards whose backends were changed since the last update.
When a full reconciliation happens, usually triggered by changing a global config, all the resources need to be parsed again, and this happen by clearing the state and building it again from scratch. This building process clears old states, removing from the controller the ability to find shards that had backends and doesn't have anymore. Since the file continues on the disk, the backend is registered on HAProxy, although it's not referenced anymore.
This is likely not to happen with ingress resources because the removal of a service triggers a partial parsing, which preserves the old state and old shards are always found, despite of being empty or not. However, if a global is changed exactly at the same time of a service removal, the backend of that service should leak if it's the last one of a backend shard. When using gateway API this is more likely to happen because currently gateway API uses full reconciliation.