Skip to content

SCF-830: Added state management for cluster hibernation#17

Open
adshin21 wants to merge 8 commits into
scalefield_v18from
scalefield_v18-SCF-830-cluster-hibernation
Open

SCF-830: Added state management for cluster hibernation#17
adshin21 wants to merge 8 commits into
scalefield_v18from
scalefield_v18-SCF-830-cluster-hibernation

Conversation

@adshin21

Copy link
Copy Markdown

No description provided.

@coveralls

coveralls commented May 13, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 27944349215

Warning

No base build found for commit d16504e on scalefield_v18.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 45.038%

Details

  • Patch coverage: 72 uncovered changes across 6 files (265 of 337 lines covered, 78.64%).

Uncovered Changes

File Changed Covered %
pkg/cluster/lifecycle.go 250 215 86.0%
pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go 16 1 6.25%
pkg/cluster/cluster.go 55 47 85.45%
pkg/apis/acid.zalan.do/v1/util.go 6 0 0.0%
pkg/util/k8sutil/k8sutil.go 6 0 0.0%
pkg/cluster/sync.go 4 2 50.0%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 15718
Covered Lines: 7079
Line Coverage: 45.04%
Coverage Strength: 16.48 hits per line

💛 - Coveralls

@adshin21 adshin21 marked this pull request as ready for review May 21, 2026 07:26
@adshin21 adshin21 requested a review from hughcapet as a code owner May 21, 2026 07:26
@serdardalgic serdardalgic requested a review from ants May 22, 2026 09:20

@serdardalgic serdardalgic left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Some minor issues @adshin21. After that, I would like to review it again.

Comment thread pkg/cluster/lifecycle.go
if c.Statefulset == nil || c.Statefulset.Spec.Replicas == nil {
return nil
}
return c.Statefulset.Spec.Replicas

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
return c.Statefulset.Spec.Replicas
return c.Statefulset.Status.Replicas

Shouldn't this be Status as you want to get the current replica count of the StatefulSet?

Comment thread pkg/cluster/cluster.go
Comment on lines +1027 to +1035
// Handle lifecycle transitions (hibernate/wake-up)
handled, err := c.handleHibernateAndWakeUp(newSpec)
if err != nil {
return err
}
if handled {
return nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can move this section before the SetPostgresCRDStatus call, I think.

Now, you're setting Updating before the lifecycle detection. That's why the manageHibernateState function call inside the handleHibernateAndWakeUp function is receiving status: "Updating", instead of "Stopped". That's why you're using the isWakingUp logic in detectLifecycleTransition function, right?

AFAICS, The "persist" functions persistHibernateTransition and persistWakeUpTransition do not depend on the "Updating" write, as they call UpdatePostgresCR first to get a fresh ResourceVersion to update.

So, my suggestion is:

	blocked, err := c.blockLifecycleUpdate(newSpec)
...
	handled, err := c.handleHibernateAndWakeUp(newSpec) // moved up
...
	newSpec.Status.PostgresClusterStatus = acidv1.ClusterStatusUpdating
...
	newSpec, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), newSpec) // does the normal update path

After that, you should be able to clean up the isWakingUp logic and have a cleaner detectLifecycleTransition function.

Comment thread pkg/cluster/lifecycle.go
const (
LifecycleActionNone LifecycleAction = iota
LifecycleActionHibernate // Running -> Stopping (initiate hibernate)
LifecycleActionStoppingCompleted // Stopping -> Stopped (pods fully terminated)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are you using LifecycleActionStoppingCompleted ? If not, please remove it.

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