K8SPG-777 Fix the crash in ShouldCheckStandbyLag#1652
Conversation
Signed-off-by: Jakub Jaruszewski <jjaruszewski@man.poznan.pl>
There was a problem hiding this comment.
Pull request overview
Prevents operator crashes when PerconaPGCluster.spec.crVersion is empty by making version comparisons fall back to the operator’s build version, which is especially relevant for callers like the standby-lag polling goroutine that may not run Default().
Changes:
- Update
PerconaPGCluster.Version()to useversion.Version()whenspec.crVersionis unset.
| crVersion := cr.Spec.CRVersion | ||
| if crVersion == "" { | ||
| crVersion = version.Version() | ||
| } | ||
| return gover.Must(gover.NewVersion(crVersion)) |
There was a problem hiding this comment.
No, this only falls back with the assumption that the opeator will reconcile the cluster and set the version asynchronously. Falling back to version.Version() on non empty can introduce hard to find bugs. But a way to do it, would actually be a validation pattern on the CRD
| crVersion := cr.Spec.CRVersion | ||
| if crVersion == "" { | ||
| crVersion = version.Version() | ||
| } |
There was a problem hiding this comment.
This test case would only work on e2e tests
There was a problem hiding this comment.
we don't need to test ShouldCheckStandbyLag regression but it'd be great to add a simple unit test that covers PerconaPGCluster.Version() behavior
Signed-off-by: jjaruszewski <jjaruszewski@man.poznan.pl>
2bf8219 to
ed73169
Compare
Signed-off-by: jjaruszewski <jjaruszewski@man.poznan.pl>
Signed-off-by: jjaruszewski <jjaruszewski@man.poznan.pl>
3a00214 to
4901a83
Compare
commit: 4199c53 |
CHANGE DESCRIPTION
Problem:
In K8SPG-777 a problem was fixed where a cluster resource with empty crVersion would crash the operator, by the operator setting it to version.Version() early in the reconciliation loop.
However in K8SPG-374 #1407 an independent
pollAndRequeueStandbysgoroutine was introduced which lists clusters and callsShouldCheckStandbyLag()->CompareVersion("2.9.0"), but the coroutine does not call.Default()so the operator crashes.Solution:
Instead of making the goroutine call
cr.Default(), let's simply fallback to a version.Version() whencrVersionis not set since we know that operator will set it to that value and have test for itCHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
Config/Logging/Testability