Skip to content

[Bug]: double switchover on configuration upgrade #6956

Description

@fcanovai

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.

I have read the troubleshooting guide

  • I have read the troubleshooting guide and I think this is a new bug.

I am running a supported version of CloudNativePG

  • I have read the troubleshooting guide and I think this is a new bug.

Contact Details

No response

Version

trunk (main)

What version of Kubernetes are you using?

1.32

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

In a cluster with PrimaryUpgradeMethod: true, there is a nonzero probability that an update of a parameter that requires a restart triggers two switchovers, first restarting the primary, and later the newly promoted instance.

This can happen if an event happens after the primary has applied the new configuration while the other instances have not.

Cluster resource

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    bug 🐛
    triage
    on Feb 24, 2025
  2. fcanovai commented on Feb 24, 2025

    @fcanovai
    ContributorAuthor

    Applying the cluster-example.yaml with an instance controller that is forced to wait can be used to trigger the issue editing the clusters while the replicas are waiting

    diff --git a/docs/src/samples/cluster-example.yaml b/docs/src/samples/cluster-example.yaml
    index fb331362f..f4a5903dd 100644
    --- a/docs/src/samples/cluster-example.yaml
    +++ b/docs/src/samples/cluster-example.yaml
    @@ -4,6 +4,7 @@ metadata:
       name: cluster-example
     spec:
       instances: 3
    +  primaryUpdateMethod: switchover
     
       storage:
         size: 1Gi
    diff --git a/internal/management/controller/instance_controller.go b/internal/management/controller/instance_controller.go
    index c1386796c..3036e73c1 100644
    --- a/internal/management/controller/instance_controller.go
    +++ b/internal/management/controller/instance_controller.go
    @@ -222,6 +222,12 @@ func (r *InstanceReconciler) Reconcile(
            restarted = restarted || restartedInplace
     
            if reloadNeeded && !restarted {
    +               // Wait one minute before reloading PostgreSQL to trigger the bug
    +               if r.instance.GetPodName() != cluster.Status.CurrentPrimary {
    +                       contextLogger.Info("WAITING ONE MINUTE")
    +                       time.Sleep(1*time.Minute)
    +               }
    +
                    contextLogger.Info("reloading the instance")
                    if err = r.instance.Reload(ctx); err != nil {
                            return reconcile.Result{}, fmt.Errorf("while reloading the instance: %w", err)
    
  3. removed
    triage
    on Feb 24, 2025
  4. added this to the milestone on Feb 24, 2025
  5. jsilvela commented on Mar 5, 2025

    @jsilvela
    Contributor

    Just want to make double-sure now that I'm testing Leo's fix:
    @fcanovai in the description I see

    In a cluster with PrimaryUpgradeMethod: true,

    This is rather PrimaryUpdateMethod: switchover, right?

  6. added a commit that references this issue on Mar 6, 2025
    e9352ac
  7. added 2 commits that reference this issue on Mar 6, 2025
    e6ecae0
    74aa88b
  8. added a commit that references this issue on Mar 6, 2025
    12f653a
  9. added a commit that references this issue on Mar 7, 2025
    8669af5
  10. modified the milestones: , 1.26.0 on Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛

Type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions