Skip to content
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

feat: guarantee to avoid bad master ip on Sentinel #1289

Merged

Conversation

husnialhamdani
Copy link
Contributor

@husnialhamdani husnialhamdani commented Mar 19, 2025

Description

Guarantee to avoid bad master ip on Sentinel, in edge/worse cases, usually we are facing replication instance pointing to master 0.0.0.0

Fixes #ISSUE

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • Tests have been added/modified and all tests pass.
  • Functionality/bugs have been confirmed to be unchanged or fixed.
  • I have performed a self-review of my own code.
  • Documentation has been updated or added where necessary.

Additional Context

@husnialhamdani
Copy link
Contributor Author

Please review and advise @drivebyer @shubham-cmyk

@husnialhamdani husnialhamdani force-pushed the avoid-bad-master-ip-on-sentinel branch from 76080a7 to 9788ad4 Compare March 19, 2025 10:13
@husnialhamdani
Copy link
Contributor Author

the CI/Go Test is failing due to the new way of not updating the Sts when the value is nil (which is expected),
any idea @shubham-cmyk @drivebyer ?

--- FAIL: Test_getSentinelEnvVariable (0.00s)
    --- FAIL: Test_getSentinelEnvVariable/When_RedisSentinelConfig_is_not_nil (0.00s)
        redis-sentinel_test.go:390: getSentinelEnvVariable() = &[], want &[{MASTER_GROUP_NAME master nil} {IP  nil} {PORT 6379 nil} {QUORUM 2 nil} {DOWN_AFTER_MILLISECONDS 30000 nil} {PARALLEL_SYNCS 1 nil} {FAILOVER_TIMEOUT 180000 nil} {RESOLVE_HOSTNAMES no nil} {ANNOUNCE_HOSTNAMES no nil}]
        redis-sentinel_test.go:391: 
            	Error Trace:	/home/runner/work/redis-operator/redis-operator/pkg/k8sutils/redis-sentinel_test.go:[39](https://github.com/OT-CONTAINER-KIT/redis-operator/actions/runs/13944486211/job/39028434397?pr=1286#step:5:40)1
            	Error:      	Received unexpected error:
            	            	failed to get master IP/hostname
            	Test:       	Test_getSentinelEnvVariable/When_RedisSentinelConfig_is_not_nil
FAIL

@shubham-cmyk
Copy link
Member

getRedisReplicationMasterIP(ctx, client, cr, dcl)

This block is returning empty IP

@shubham-cmyk
Copy link
Member

shubham-cmyk commented Mar 19, 2025

Okay you have to just create a pod.
Create that under the

tests/testdata/sentinel/pod.yaml

Write one yaml that could match the sentinel pod metadata that we check.
Make sure to include the IP on that.
Later you have to pass that into dynamicfakeclient.

Take Help from here

you can also put this this converter code into testutils/redis-sentinel/

Signed-off-by: Husni Alhamdani <dhanielluis@gmail.com>
Signed-off-by: Husni Alhamdani <dhanielluis@gmail.com>
Signed-off-by: Husni Alhamdani <dhanielluis@gmail.com>
Signed-off-by: Husni Alhamdani <dhanielluis@gmail.com>
Signed-off-by: Husni Alhamdani <dhanielluis@gmail.com>
@husnialhamdani husnialhamdani force-pushed the avoid-bad-master-ip-on-sentinel branch from d50451c to 5cb5b4f Compare March 24, 2025 15:22
},
},
)
if got, err := getSentinelEnvVariable(ctx, tt.args.client, tt.args.cr, dynamicClient); !reflect.DeepEqual(got, tt.want) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the getSentinelEnvVariable is calling getRedisReplicationMasterPod function that using redis client (it's looking for response of "master"), but it never happens,

I was trying to add some client fake, but not sure how to go further, please check @drivebyer @shubham-cmyk

Copy link
Collaborator

Choose a reason for hiding this comment

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

I introduce gomonkey to fix it

drivebyer and others added 2 commits March 26, 2025 11:43
Copy link

codecov bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 35.00000% with 13 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@0b66815). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pkg/k8sutils/redis-sentinel.go 35.00% 11 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1289   +/-   ##
=======================================
  Coverage        ?   33.62%           
=======================================
  Files           ?       55           
  Lines           ?     6087           
  Branches        ?        0           
=======================================
  Hits            ?     2047           
  Misses          ?     3854           
  Partials        ?      186           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@drivebyer drivebyer merged commit 2527568 into OT-CONTAINER-KIT:main Mar 26, 2025
29 of 30 checks passed
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.

3 participants