Skip to content

[Bug]: The Cluster "..." is invalid: spec.bootstrap: Invalid value: "": Too many bootstrap types specified #8136

Closed

Description

@MRocholl

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

1.26 (latest patch)

What version of Kubernetes are you using?

1.30

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

I am getting the same issue as in #8024 ..

I.e. the following message after an apply of the below manifest. The Cluster "..." is invalid: spec.bootstrap: Invalid value: "": Too many bootstrap types specified.

As I am not sure that this is the same issue, I chose to open a different one.

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  annotations:
    cnpg.io/skipEmptyWalArchiveCheck: enabled
  name: ...
  namespace: ...
spec:
  bootstrap:
    recovery:
      source: self
  externalClusters:
    - name: self
      plugin:
        name: barman-cloud.cloudnative-pg.io
        parameters:
          barmanObjectName: pg-backup-object-store
          serverName: to-be-replaced
  instances: 1
  monitoring:
    enablePodMonitor: true
  plugins:
    - isWALArchiver: true
      name: barman-cloud.cloudnative-pg.io
      parameters:
        barmanObjectName: pg-backup-object-store
        serverName: to-be-replaced
  storage:
    size: 500Mi

The cluster already exits. I am only adding the bootstrap: section here.
Is this maybe a matter of how the initdb /bootstrap section is handled if not set explicitly at first?

Ive got a different pg-cluster within the same cluster, where the same approach worked like a charm.
If there is a typo that my 2 hours of staring at this manifest did not reveal, please feel free to close this.

Thank you in advance.

Cluster resource

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  annotations:
    cnpg.io/skipEmptyWalArchiveCheck: enabled
  name: ...
  namespace: ...
spec:
  bootstrap:
    recovery:
      source: self
  externalClusters:
    - name: self
      plugin:
        name: barman-cloud.cloudnative-pg.io
        parameters:
          barmanObjectName: pg-backup-object-store
          serverName: to-be-replaced
  instances: 1
  monitoring:
    enablePodMonitor: true
  plugins:
    - isWALArchiver: true
      name: barman-cloud.cloudnative-pg.io
      parameters:
        barmanObjectName: pg-backup-object-store
        serverName: to-be-replaced
  storage:
    size: 500Mi

Relevant log output

The Cluster "api-pg" is invalid: spec.bootstrap: Invalid value: "": Too many bootstrap types specified

Code of Conduct

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

Activity

  1. added
    triage
    on Jul 25, 2025
  2. dosubot commented on Jul 25, 2025

    @dosubot

    Hi @MRocholl! I'm Dosu and I’m helping the cloudnative-pg team.

    This error happens because the bootstrap section in a CloudNativePG Cluster resource is only meant to be set at creation time. Once the cluster is initialized, adding or modifying the bootstrap section is not supported and will trigger a validation error like "Too many bootstrap types specified"—even if you only specify one method. This is enforced by both the CRD and the operator's validation logic, and is documented as intentional behavior to prevent conflicting bootstrap operations on an already-initialized cluster. There are no typos in your manifest; the issue is due to this immutability constraint, not user error. For more details, see the CloudNativePG documentation on bootstrap and the discussion in issue #8024.

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about cloudnative-pg Share Dosu with your team

  3. MRocholl commented on Jul 25, 2025

    @MRocholl
    Author

    This: Is this maybe a matter of how the initdb /bootstrap section is handled if not set explicitly at first?

    I just set initdb explicitly:

      bootstrap:
        initdb:
           database: app
           owner: app

    and then reapplied the original manifest. and it works.
    Im gonna leave this open, as this seems like unclear behavior to me. @dosu Your answer does not address this behavior.

  4. dosubot commented on Jul 25, 2025

    @dosubot

    Yes, this is about how the bootstrap section is handled by default. If you don't set a bootstrap method at creation, CloudNativePG implicitly defaults to initdb with standard settings. This means the cluster is already considered to have been bootstrapped with initdb, even if you never wrote it explicitly in the manifest.

    When you later add an explicit initdb block that matches the default, it doesn't create a conflict—you're just making the implicit default explicit, so the operator accepts it. But if you try to add a different bootstrap method (like recovery) after creation, the validation logic sees this as specifying more than one bootstrap method, which is not allowed and triggers the "too many bootstrap types specified" error. This behavior comes from the way the controller applies defaults and validates the manifest, not from an explicit immutability rule in the CRD or webhook.

    You can see this logic in the code: if no bootstrap is set, it defaults to initdb; only one method is allowed at a time, and the validation counts non-nil methods to enforce this rule (source, source).

    So, the effect you saw is a result of how defaulting and validation interact, not a documented or intentional feature—just an emergent property of the implementation.

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about cloudnative-pg Share Dosu with your team

  5. MRocholl commented on Jul 25, 2025

    @MRocholl
    Author

    @dosu That does not explain why the two different ways to define a cluster 1. rely on default inditdb and 2. specify an explict initdb
    will NOT allow the cluster to be updated with a recovery section for (implicit initdb) 1 but will do so for (explicit initdb) 2.

  6. dosubot commented on Jul 25, 2025

    @dosubot

    This difference comes from how CloudNativePG applies defaults and validates updates. When you create a cluster without specifying bootstrap, the operator internally defaults to initdb—but this is not stored explicitly in the resource. If you later try to add a different bootstrap method (like recovery), the validation logic sees both the implicit default and your new method, counts more than one, and blocks the change as "too many bootstrap types specified" (source, source).

    If you explicitly set initdb in your manifest, then later switch to recovery, the webhook compares the old and new states (both with explicit bootstrap blocks) and may allow the change if it doesn't interpret it as a conflicting semantic change. This subtlety is a side effect of how the webhook applies defaults and compares the "old" and "new" objects during updates—not an intentional user-facing policy, but an artifact of the implementation. The key is that the operator always applies defaults before validating, so the presence or absence of explicit fields in your manifest can affect how updates are validated, even if the effective configuration is the same (source).

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about cloudnative-pg Share Dosu with your team

  7. MRocholl commented on Jul 25, 2025

    @MRocholl
    Author

    @dosu from a user perspective this is unexpected behavior. I.e. Seems like a bug to me.

  8. dosubot commented on Jul 25, 2025

    @dosubot

    You're right—this is unexpected and confusing from a user perspective. The difference in behavior between implicit and explicit bootstrap handling isn't clearly documented and has tripped up others as well. It's not officially labeled a bug, but it's an emergent property of how CloudNativePG applies defaults and validates updates: when you don't specify a bootstrap method, the operator internally defaults to initdb, but this isn't visible in your manifest. Later, if you try to add a different bootstrap method (like recovery), the validation logic sees both the implicit default and your new method, and blocks the change as "too many bootstrap types specified"—even though you only see one in your YAML. This subtlety is a side effect of the defaulting and validation logic, not an intentional feature, and maintainers have acknowledged that similar defaulting behavior can be confusing and may not align with user expectations or documentation (example, example).

    There's no official documentation or release note that directly addresses this, so your feedback highlights a real gap in clarity.

    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

  9. mnencia commented on Jul 25, 2025

    @mnencia
    Member

    This issue is a duplicate of #8024, which was fixed in #8025. We have just released version 1.26.1, which includes this fix.

  10. MRocholl commented on Jul 25, 2025

    @MRocholl
    Author

    @mnencia At a second look, I fail to see how this is a duplicate. The issue is not with multiple boostrap methods but a single one.
    Please see the last message from dosu. #8025 does not address this as far as I can see.

  11. mnencia commented on Jul 25, 2025

    @mnencia
    Member

    When you created the cluster without specifying any bootstrap method, the operator's defaulting webhook automatically added spec.bootstrap.initdb. This happens after kubectl stores your original manifest in kubectl.kubernetes.io/last-applied-configuration. Later, when you apply the updated manifest that introduces spec.bootstrap.recovery, kubectl apply merges the new manifest with the existing resource. Since the stored configuration doesn't contain the initdb method, kubectl doesn't know it has to remove it, so it merges the applied object with the current one and ends up with two bootstrap methods.

    The validating webhook rejects that configuration because only one bootstrap method can be set at a time. That's why you see the "spec.bootstrap: Forbidden: Only one bootstrap method can be specified at a time" error (or "spec.bootstrap: Invalid value:" ": Too many bootstrap types specified" with the previous version).

    To switch to recovery, you must first remove the defaulted initdb section, either via kubectl edit or kubectl patch. An alternative is to explicitly set bootstrap.initdb in the original manifest (even if left empty), then replace it with recovery in a subsequent apply. This ensures kubectl apply sees the change and removes the initdb section, preventing the conflict.

    I'm going to close this issue as this is standard Kubernetes behavior when there is a defaulting webhook, and CNPG cannot change this.

  12. MRocholl commented on Jul 26, 2025

    @MRocholl
    Author

    Thank you for clarifying the issue. That explains it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions