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.

@github-actions
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
@github-actions
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
@ZebcoWeb
Copy link

ZebcoWeb commented Oct 8, 2025

Any updates?

@carrodher
Copy link
Member

The chart version present in the Chart.yaml should be bumped

@fmendez89
Copy link
Author

Any updates?

Sorry @ZebcoWeb, I haven't had time the last weeks. I wanted to test the scripts on our staging environment before merging. I don't want to mess with the deployments of the entire world, mine's it's enough. Although, if you want to try them or have already, please let me know.
I'm looking forward to try them next week. So you can expect this PR to be merged soon if everything is working fine.

@ZebcoWeb
Copy link

Hi @fmendez89,
I had to use your own branch directly because I needed this update, and I can say that after 2 weeks of testing, it works well. And I'm still waiting for it to be merged into the main repository.

@fmendez89
Copy link
Author

Hi @fmendez89, I had to use your own branch directly because I needed this update, and I can say that after 2 weeks of testing, it works well. And I'm still waiting for it to be merged into the main repository.

Wow, nice! thanks for the feedback. I'll try to push the changes this weekend then.

@carrodher carrodher removed the request for review from javsalgar October 25, 2025 07:40
@fmendez89
Copy link
Author

Bumped chart version, I believe that's it, let me know if anything else is needed.

Signed-off-by: Bitnami Bot <[email protected]>
@fmendez89 fmendez89 requested a review from juan131 October 28, 2025 09:01
Comment on lines +822 to +832
push-master-label.sh: |
#!/bin/bash
# https://download.redis.io/redis-stable/sentinel.conf
{{- if .Values.useHostnames }}
echo "${6/.*}" > /etc/shared/current
echo "${4/.*}" > /etc/shared/previous
{{- else }}
echo "$6" > /etc/shared/current
echo "$4" > /etc/shared/previous
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please correct me if I'm wrong but this change in the indentation is unexpected:

Suggested change
push-master-label.sh: |
#!/bin/bash
# https://download.redis.io/redis-stable/sentinel.conf
{{- if .Values.useHostnames }}
echo "${6/.*}" > /etc/shared/current
echo "${4/.*}" > /etc/shared/previous
{{- else }}
echo "$6" > /etc/shared/current
echo "$4" > /etc/shared/previous
{{- end }}
push-master-label.sh: |
#!/bin/bash
# https://download.redis.io/redis-stable/sentinel.conf
{{- if .Values.useHostnames }}
echo "${6/.*}" > /etc/shared/current
echo "${4/.*}" > /etc/shared/previous
{{- else }}
echo "$6" > /etc/shared/current
echo "$4" > /etc/shared/previous
{{- end }}

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

6 participants