Skip to content

[Bug]: Status field in the Cluster PluginStatus entries flaps due to continual overwrite #11385

Closed

Description

@sharifmshaker

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

[email protected]

Version

1.30.0

What version of Kubernetes are you using?

1.36

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

updatePluginsStatus (internal/controller/cluster_plugins.go)
runs early in the loop. It rebuilds the whole PluginStatus slice from plugin
metadata and never carries .Status across:

cluster.Status.PluginStatus = make([]apiv1.PluginStatus, len(metadataList))
for i, entry := range metadataList {
    cluster.Status.PluginStatus[i].Name = entry.Name
    // … Version and the capability lists …
    // .Status is silently dropped
}
if reflect.DeepEqual(oldCluster.Status.PluginStatus, cluster.Status.PluginStatus) {
    return nil
}
return r.Client.Status().Patch(ctx, cluster, client.MergeFrom(oldCluster))

The old slice carries .Status and the rebuilt one does not, so DeepEqual
differs and it patches the cleared status out.

setStatusPluginHook (internal/controller/plugins.go) runs at the
end of the same loop, writes the plugin's status back without comparing it to
what is already there, and requeues unconditionally:

cli.Status().Patch(ctx, cluster, client.MergeFrom(origCluster))
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil   // unconditional

Each write wakes the other. Neither ever converges.

Reproduction

Hitting this bug requires a plugin that implements the cluster status update RPC. In order to get a minimal reproduction of the issue I was hitting during my own plugin experimentation I had Claude Opus 5 generate a simple plugin implementing this status functionality. This plugin is as well as some helper scripts for testing it can be found in this project https://github.com/sharifmshaker/cnpg-plugin-status-error-repro.

Running this plugin, I can simply use the command kubectl get cluster with a watch to see the plugin status flapping with status: '{"repro":"cnpg-plugin-status-flap"}' on the cluster.

> kubectl get cluster -n repro -o yaml pg-source -w | yq .status.pluginStatus
- capabilities:
    - TYPE_OPERATOR_SERVICE
  name: status-flapper
  operatorCapabilities:
    - TYPE_SET_STATUS_IN_CLUSTER
  version: 0.1.0
---
- capabilities:
    - TYPE_OPERATOR_SERVICE
  name: status-flapper
  operatorCapabilities:
    - TYPE_SET_STATUS_IN_CLUSTER
  status: '{"repro":"cnpg-plugin-status-flap"}'
  version: 0.1.0
---
- capabilities:
    - TYPE_OPERATOR_SERVICE
  name: status-flapper
  operatorCapabilities:
    - TYPE_SET_STATUS_IN_CLUSTER
  version: 0.1.0
---
- capabilities:
    - TYPE_OPERATOR_SERVICE
  name: status-flapper
  operatorCapabilities:
    - TYPE_SET_STATUS_IN_CLUSTER
  status: '{"repro":"cnpg-plugin-status-flap"}'
  version: 0.1.0
---
- capabilities:
    - TYPE_OPERATOR_SERVICE
  name: status-flapper
  operatorCapabilities:
    - TYPE_SET_STATUS_IN_CLUSTER
  version: 0.1.0
—

Cluster resource

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"postgresql.cnpg.io/v1","kind":"Cluster","metadata":{"annotations":{},"name":"pg-source","namespace":"repro"},"spec":{"imagePullPolicy":"IfNotPresent","instances":1,"plugins":[{"name":"status-flapper"}],"resources":{"requests":{"cpu":"100m","memory":"256Mi"}},"storage":{"size":"256Mi"}}}
  creationTimestamp: "2026-08-29T16:20:18Z"
  generation: 1
  name: pg-source
  namespace: repro
  resourceVersion: "13502"
  uid: 19a8e333-9c98-4cd9-bc90-88612ca44c12
spec:
  affinity:
    podAntiAffinityType: preferred
  bootstrap:
    initdb:
      database: app
      encoding: UTF8
      localeCType: C
      localeCollate: C
      owner: app
  enablePDB: true
  enableSuperuserAccess: false
  failoverDelay: 0
  imageName: ghcr.io/cloudnative-pg/postgresql:18.6-system-trixie
  imagePullPolicy: IfNotPresent
  instances: 1
  logLevel: info
  maxSyncReplicas: 0
  minSyncReplicas: 0
  monitoring:
    customQueriesConfigMap:
    - key: queries
      name: cnpg-default-monitoring
    disableDefaultQueries: false
    enablePodMonitor: false
  plugins:
  - enabled: true
    isWALArchiver: false
    name: status-flapper
  postgresGID: 26
  postgresUID: 26
  postgresql:
    parameters:
      archive_mode: "on"
      archive_timeout: 5min
      dynamic_shared_memory_type: posix
      full_page_writes: "on"
      log_destination: csvlog
      log_directory: /controller/log
      log_filename: postgres
      log_rotation_age: "0"
      log_rotation_size: "0"
      log_truncate_on_rotation: "false"
      logging_collector: "on"
      max_parallel_workers: "32"
      max_replication_slots: "32"
      max_worker_processes: "32"
      shared_memory_type: mmap
      shared_preload_libraries: ""
      ssl_max_protocol_version: TLSv1.3
      ssl_min_protocol_version: TLSv1.3
      wal_keep_size: 512MB
      wal_level: logical
      wal_log_hints: "on"
      wal_receiver_timeout: 5s
      wal_sender_timeout: 5s
    syncReplicaElectionConstraint:
      enabled: false
  primaryUpdateMethod: restart
  primaryUpdateStrategy: unsupervised
  probes:
    liveness:
      isolationCheck:
        connectionTimeout: 1000
        enabled: true
        requestTimeout: 1000
  replicationSlots:
    highAvailability:
      enabled: true
      slotPrefix: _cnpg_
    synchronizeReplicas:
      enabled: true
    updateInterval: 30
  resources:
    requests:
      cpu: 100m
      memory: 256Mi
  smartShutdownTimeout: 180
  startDelay: 3600
  stopDelay: 1800
  storage:
    resizeInUseVolumes: true
    size: 256Mi
  switchoverDelay: 3600
status:
  availableArchitectures:
  - goArch: arm64
    hash: 14e26aa23ae31a369ba36d04f962ca649f24f0e79c845a7c40c185a21725f1d2
  certificates:
    clientCASecret: pg-source-ca
    expirations:
      pg-source-ca: 2026-11-27 16:15:20 +0000 UTC
      pg-source-replication: 2026-11-27 16:15:20 +0000 UTC
      pg-source-server: 2026-11-27 16:15:20 +0000 UTC
    replicationTLSSecret: pg-source-replication
    serverAltDNSNames:
    - pg-source-rw
    - pg-source-rw.repro
    - pg-source-rw.repro.svc
    - pg-source-rw.repro.svc.cluster.local
    - pg-source-r
    - pg-source-r.repro
    - pg-source-r.repro.svc
    - pg-source-r.repro.svc.cluster.local
    - pg-source-ro
    - pg-source-ro.repro
    - pg-source-ro.repro.svc
    - pg-source-ro.repro.svc.cluster.local
    serverCASecret: pg-source-ca
    serverTLSSecret: pg-source-server
  cloudNativePGCommitHash: none
  cloudNativePGOperatorHash: 14e26aa23ae31a369ba36d04f962ca649f24f0e79c845a7c40c185a21725f1d2
  conditions:
  - lastTransitionTime: "2026-08-29T16:20:22Z"
    message: Cluster has been bootstrapped
    reason: BootstrapCompleted
    status: "True"
    type: Initialized
  - lastTransitionTime: "2026-08-29T16:50:24Z"
    message: A single, unique system ID was found across reporting instances.
    reason: Unique
    status: "True"
    type: ConsistentSystemID
  - lastTransitionTime: "2026-08-29T16:50:28Z"
    message: Cluster is Ready
    reason: ClusterIsReady
    status: "True"
    type: Ready
  - lastTransitionTime: "2026-08-29T16:21:30Z"
    message: Continuous archiving is working
    reason: ContinuousArchivingSuccess
    status: "True"
    type: ContinuousArchiving
  configMapResourceVersion:
    metrics:
      cnpg-default-monitoring: "4825"
  currentPrimary: pg-source-1
  currentPrimaryTimestamp: "2026-08-29T16:21:29.306681Z"
  healthyPVC:
  - pg-source-1
  image: ghcr.io/cloudnative-pg/postgresql:18.6-system-trixie
  instanceNames:
  - pg-source-1
  instances: 1
  instancesReportedState:
    pg-source-1:
      ip: 10.244.0.24
      isPrimary: true
      timeLineID: 1
  instancesStatus:
    healthy:
    - pg-source-1
  managedRolesStatus: {}
  operatorCertificateFingerprint: 0eab9f7d89389a8482e03eeecc1d743dd0894f060d280795fc69e86e5fb39aee
  pgDataImageInfo:
    image: ghcr.io/cloudnative-pg/postgresql:18.6-system-trixie
    majorVersion: 18
  phase: Cluster in healthy state
  pluginStatus:
  - capabilities:
    - TYPE_OPERATOR_SERVICE
    name: status-flapper
    operatorCapabilities:
    - TYPE_SET_STATUS_IN_CLUSTER
    version: 0.1.0
  poolerIntegrations:
    pgBouncerIntegration: {}
  pvcCount: 1
  readService: pg-source-r
  readyInstances: 1
  secretsResourceVersion:
    applicationSecretVersion: "4802"
    clientCaSecretVersion: "4799"
    replicationSecretVersion: "4801"
    serverCaSecretVersion: "4799"
    serverSecretVersion: "4800"
  selector: cnpg.io/cluster=pg-source,cnpg.io/podRole=instance
  switchReplicaClusterStatus: {}
  systemID: "7679489500628045853"
  targetPrimary: pg-source-1
  targetPrimaryTimestamp: "2026-08-29T16:20:21.348292Z"
  timelineID: 1
  topology:
    instances:
      pg-source-1: {}
    nodesUsed: 1
    successfullyExtracted: true
  writeService: pg-source-rw

Relevant log output

Code of Conduct

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

Activity

  1. added
    bug 🐛
    triage
    on Aug 29, 2026
  2. dosubot commented on Aug 29, 2026

    @dosubot

    Hi @sharifmshaker! I'm Dosu and I'm helping the CloudNativePG team.

    Your root-cause analysis is correct — I verified it against the current main branch code.

    updatePluginsStatus rebuilds the entire PluginStatus slice from pluginClient.MetadataList() on every reconcile, copying only Name, Version, and the capability lists. The .Status field [1] is never carried over from the previous value, so the new slice always has an empty .Status. Because reflect.DeepEqual then sees a difference from the old slice (which had .Status populated), it patches the cleared status to the API server.

    Later in the same loop, setStatusPluginHook calls SetStatusInCluster, writes .Status back in, patches again, and unconditionally requeues after 5 seconds — even if nothing changed. That requeue triggers updatePluginsStatus again [2], which wipes .Status again, and the cycle repeats indefinitely — exactly the flapping you reproduced.

    A related but distinct fix, PR #10421, addressed Phase oscillation between Healthy and FailurePlugin (#8582) by moving PhaseHealthy registration to the end of the reconciliation loop, but it did not touch the PluginStatus.Status carry-over problem.

    Two straightforward fixes could resolve this:

    1. updatePluginsStatus should preserve the existing .Status value (by plugin name) when rebuilding the slice, so the DeepEqual check won't see a spurious diff.
    2. setStatusPluginHook should compare the new status to the existing one and only patch + requeue when something actually changed.

    This is the same issue you filed as #11385. Hopefully this additional code-level confirmation helps move it toward a fix.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about cloudnative-pg with Dosu Add Dosu to your team

  3. added a commit that references this issue on Sep 9, 2026
    10f998b
  4. added 2 commits that reference this issue on Sep 9, 2026
    c56c4c8
    96e3993
  5. added a commit that references this issue on Sep 9, 2026
    5a74e4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions