Skip to content

Conversation

fmendez89
Copy link

@fmendez89 fmendez89 commented Aug 7, 2025

Description of the change

This PR improves the way the current Redis master pod is labeled by Sentinel by introducing synchronization and avoiding race conditions when multiple pods detect a failover. It adds the following changes:

  • A shared coordination mechanism using flock to avoid race conditions when labeling pods.
  • Skips relabeling if the master hasn't changed, preventing unnecessary updates.
  • Adds support for resolving the master pod name by IP when useHostnames is disabled.
  • Improves the label management logic by adding isMaster=true to the current master and removing app.kubernetes.io/role.

Benefits

  • Avoids concurrent relabeling issues across Sentinel instances.
  • Reduces unnecessary pod label updates.
  • Ensures correct label assignment in clusters with or without useHostnames.
  • Supports both IP and hostname-based master detection.
  • Aligns the master labeling logic with the actual Sentinel-detected master.

Possible drawbacks

  • Requires that the container has permission to use file locking (should be fine on most Linux distros).
  • Relies on a shared writable volume mounted at /etc/shared across pods.

Applicable issues

Fixes #29217

Additional information

This feature is particularly useful when using external services that rely on pod labels (e.g., a Service selector for the master role). It ensures the label is always up-to-date based on Sentinel decisions.

Checklist

  • Chart version bumped in Chart.yaml according to semver. This is not necessary when the changes only affect README.md files.
  • Variables are documented in the values.yaml and added to the README.md using readme-generator-for-helm
  • Title of the pull request follows this pattern [bitnami/redis] Add support to redis master service with useHostnames false
  • All commits signed off and in agreement of Developer Certificate of Origin (DCO)

@github-actions github-actions bot added redis triage Triage is needed labels Aug 7, 2025
@github-actions github-actions bot requested a review from javsalgar August 7, 2025 10:00
bitnami-bot and others added 2 commits August 7, 2025 10:05
Signed-off-by: Bitnami Bot <[email protected]>
…mes-false

Signed-off-by: Carlos Rodríguez Hernández <[email protected]>
@carrodher carrodher added verify Execute verification workflow for these changes in-progress labels Aug 7, 2025
@github-actions github-actions bot removed the triage Triage is needed label Aug 7, 2025
@github-actions github-actions bot removed the request for review from javsalgar August 7, 2025 13:42
@github-actions github-actions bot requested a review from juan131 August 7, 2025 13:42
Copy link
Contributor

@juan131 juan131 left a comment

Choose a reason for hiding this comment

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

Thanks so much for this great PR! Absolutely brilliant, please check my comments.

fmendez89 and others added 4 commits August 14, 2025 18:03
…of github.com:fmendez89/charts into redis-support-master-service-with-use-hostnames-false
Signed-off-by: Bitnami Bot <[email protected]>
Copy link
Contributor

@juan131 juan131 left a comment

Choose a reason for hiding this comment

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

Please ensure you merge the latest changes in the origin's main branch in your fork's branch and then, update the PR. Thanks in advance.

if [ -f "/etc/shared/current" ]; then
current_master=$(< /etc/shared/current)
[ -f /etc/shared/previous ] && previous_master=$(< /etc/shared/previous) || previous_master=""
Copy link
Contributor

Choose a reason for hiding this comment

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

Please split this in 2 lines:

Suggested change
[ -f /etc/shared/previous ] && previous_master=$(< /etc/shared/previous) || previous_master=""
previous_master=""
[ -f /etc/shared/previous ] && previous_master=$(< /etc/shared/previous)

Copy link
Author

Choose a reason for hiding this comment

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

sure, it's better that way

echo "Current master: $current_master"
if [ -n "$previous_master" ] && [ "$current_master" = "$previous_master" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the 1st condition redundant?

Suggested change
if [ -n "$previous_master" ] && [ "$current_master" = "$previous_master" ]; then
if [ "$current_master" = "$previous_master" ]; then

Copy link
Author

Choose a reason for hiding this comment

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

yes, good catch

echo "Current master: $current_master"
if [ -n "$previous_master" ] && [ "$current_master" = "$previous_master" ]; then
echo "Master ($current_master = $previous_master) has not changed, skipping label update and cleaning state"
Copy link
Contributor

Choose a reason for hiding this comment

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

In the previous echo you already displayed the variable value:

Suggested change
echo "Master ($current_master = $previous_master) has not changed, skipping label update and cleaning state"
echo "Master has not changed, skipping label update and cleaning state"

Copy link
Author

Choose a reason for hiding this comment

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

Ok, removing it

Copy link

github-actions bot commented Sep 3, 2025

This Pull Request has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thank you for your contribution.

@github-actions github-actions bot added the stale 15 days without activity label Sep 3, 2025
Copy link

github-actions bot commented Sep 9, 2025

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Pull Request. Do not hesitate to reopen it later if necessary.

@github-actions github-actions bot added the solved label Sep 9, 2025
@bitnami-bot bitnami-bot added stale 15 days without activity and removed stale 15 days without activity labels Sep 9, 2025
@bitnami-bot bitnami-bot closed this Sep 9, 2025
…of github.com:fmendez89/charts into redis-support-master-service-with-use-hostnames-false
@fmendez89
Copy link
Author

fmendez89 commented Sep 18, 2025

Hi @juan131, how can I reopen de PR to push the changes?

Signed-off-by: Fran Méndez <[email protected]>
@carrodher carrodher reopened this Sep 18, 2025
@github-actions github-actions bot added triage Triage is needed and removed solved labels Sep 18, 2025
@github-actions github-actions bot requested a review from javsalgar September 18, 2025 15:41
@github-actions github-actions bot removed the stale 15 days without activity label Sep 19, 2025
@carrodher
Copy link
Member

Thanks for your contribution! Could you please bump the chart version in the Chart.yaml? This is necessary to test the changes and cut a new release. Probably it was missing after the latest rebase.

@juan131 juan131 removed the triage Triage is needed label Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
redis verify Execute verification workflow for these changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bitnami/redis] Automatic labeling of master pod fails if useHostnames is set to false
5 participants