-
Notifications
You must be signed in to change notification settings - Fork 161
K8SPSMDB-1466 improve MCS error handling to prevent operator crashes #2044
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
base: main
Are you sure you want to change the base?
Conversation
| // MCS is optional functionality - if discovery fails for any reason, | ||
| // mark it as unavailable and continue without crashing the operator | ||
| available = false | ||
| return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we need to log the error and inform users that MCS is not available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/mcs/register_test.go
Outdated
| ) | ||
|
|
||
| func TestIsAvailable(t *testing.T) { | ||
| // Test IsAvailable function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments are not necessary
pkg/mcs/register_test.go
Outdated
| if !IsAvailable() { | ||
| t.Error("Expected IsAvailable to return true when available is true") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't we using assert.True(t, IsAvailable()) and instead we use if statements for assertions?
pkg/mcs/register_test.go
Outdated
| } | ||
|
|
||
| func TestServiceExport(t *testing.T) { | ||
| // Test ServiceExport creation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed comment
pkg/mcs/register_test.go
Outdated
| if se.Name != name { | ||
| t.Errorf("Expected ServiceExport name to be %s, got: %s", name, se.Name) | ||
| } | ||
|
|
||
| if se.Namespace != namespace { | ||
| t.Errorf("Expected ServiceExport namespace to be %s, got: %s", namespace, se.Namespace) | ||
| } | ||
|
|
||
| if se.Labels["app"] != "test" { | ||
| t.Errorf("Expected ServiceExport label 'app' to be 'test', got: %s", se.Labels["app"]) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these could be assertions
| func TestServiceExportList(t *testing.T) { | ||
| // Test ServiceExportList creation | ||
| seList := ServiceExportList() | ||
|
|
||
| if seList.Kind != "ServiceExportList" { | ||
| t.Errorf("Expected ServiceExportList Kind to be 'ServiceExportList', got: %s", seList.Kind) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same approach with the other tests, we can drop comments and use assertions
pkg/mcs/register_test.go
Outdated
| func TestMCSSchemeGroupVersion(t *testing.T) { | ||
| // Test that MCSSchemeGroupVersion is initialized correctly | ||
| if MCSSchemeGroupVersion.Group != "" { | ||
| t.Errorf("Expected MCSSchemeGroupVersion.Group to be empty initially, got: %s", MCSSchemeGroupVersion.Group) | ||
| } | ||
| if MCSSchemeGroupVersion.Version != "" { | ||
| t.Errorf("Expected MCSSchemeGroupVersion.Version to be empty initially, got: %s", MCSSchemeGroupVersion.Version) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what we are testing here. Since we are not calling a function or something to affect the values, we are essentially asserting that they are empty. Is that what we want?
commit: 6293f90 |
CHANGE DESCRIPTION
Description
This PR fixes the issue where the Percona Server MongoDB Operator would crash when encountering errors during Multi-Cluster Services (MCS) discovery, specifically the "stale GroupVersion discovery" error.
Problem
The operator was crashing with the following error:
This occurred in the MCS registration process when
dc.ServerPreferredResources()failed, causing the entire operator pod to crash and restart.Solution
Register()function inpkg/mcs/register.goto handle any discovery error gracefullyNew Unit Tests in
pkg/mcs/register_test.goTestIsAvailable(): Tests MCS availability statusTestMCSSchemeGroupVersion(): Tests scheme group version initializationTestServiceExport(): Tests ServiceExport object creationTestServiceExportList(): Tests ServiceExportList object creationBenefits
Testing
Type of Change
Checklist
Related Issues
Fixes the operator crash issue when MCS discovery fails with "stale GroupVersion discovery" error.
Additional Notes
This fix ensures that MCS (Multi-Cluster Services) is treated as an optional feature. When MCS discovery fails for any reason, the operator gracefully marks MCS as unavailable and continues with normal MongoDB cluster operations. This makes the operator more resilient and prevents unnecessary pod restarts.