Skip to content

feat: support configurable PodDisruptionBudget#422

Merged
miparnisari merged 3 commits into
authzed:mainfrom
davidxia:feat/configurable-pdb
May 28, 2026
Merged

feat: support configurable PodDisruptionBudget#422
miparnisari merged 3 commits into
authzed:mainfrom
davidxia:feat/configurable-pdb

Conversation

@davidxia
Copy link
Copy Markdown
Contributor

@davidxia davidxia commented May 10, 2026

Summary

Resolves #414.

Adds a new pdb config object on SpiceDBCluster to give users control over the PodDisruptionBudget:

  • pdb.disabled (bool, default false): when true, the operator deletes any existing PDB owned by the cluster and stops creating one
  • pdb.maxUnavailable (integer or percentage string, e.g. "2" or "50%"): sets the PDB's maxUnavailable field; defaults to 1 when neither field is set (preserving existing behavior)
  • pdb.minAvailable (integer or percentage string): sets the PDB's minAvailable field; mutually exclusive with pdb.maxUnavailable

Example usage

# Disable PDB
spec:
  config:
    pdb:
      disabled: true

# Allow 50% of pods to be unavailable during disruptions
spec:
  config:
    pdb:
      maxUnavailable: "50%"

# Require at least 3 pods to always be available
spec:
  config:
    pdb:
      minAvailable: "3"

Test plan

  • All existing unit tests pass
  • New unit tests added for: disabled PDB, custom maxUnavailable (integer and percentage), custom minAvailable, and validation error when both are set
  • go test ./pkg/... passes

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 10, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@davidxia
Copy link
Copy Markdown
Contributor Author

davidxia commented May 10, 2026

I have read the CLA Document and I hereby sign the CLA

@davidxia
Copy link
Copy Markdown
Contributor Author

recheck

authzedbot added a commit to authzed/cla that referenced this pull request May 10, 2026
@davidxia davidxia force-pushed the feat/configurable-pdb branch 2 times, most recently from 3d8de88 to 11adb58 Compare May 10, 2026 23:30
Copy link
Copy Markdown
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

One small change, otherwise this looks good! Thanks for the contribution!

FYI full customization of the PDB is possible with the patches feature, but I can see why we'd want these to have shortcuts.

// If PDB is disabled, delete any existing PDB and skip creation
if cfg.PDB.Disabled {
for _, pdb := range pdbComponent.List(ctx, CtxClusterNN.MustValue(ctx)) {
nn := types.NamespacedName{Name: pdb.Name, Namespace: pdb.Namespace}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we also verify a match on the component labels too? metadata.LabelsForComponent(clusterName, metadata.ComponentPDBLabel). This way we can be sure to only delete a PDB that was operator created, and not one that happened to have a name that matches

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yup, updated below

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could a test be written that covers this? i see in https://app.codecov.io/github/authzed/spicedb-operator/blob/main/pkg%2Fcontroller%2Fcontroller.go#L531 that ensurePdb has almost zero coverage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see ensurePdb() on main doesn't have any test coverage right now. So I tried to add coverage for at least my changes here.

I added TestEnsurePDB() in controller_test.go. The test logic isn't as nice as TestCredentialSecretsForCluster because ensurePDB()'s function signature isn't as testable as credentialSecretsForCluster()'s. But I don't want to increase the scope of this PR by changing ensurePDB()'s function signature.

How does it look? How can I get an updated coverage report?

@davidxia davidxia force-pushed the feat/configurable-pdb branch from 11adb58 to c4bd31a Compare May 13, 2026 12:39
@davidxia
Copy link
Copy Markdown
Contributor Author

Thanks, I didn't see the patches functionality.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 28, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.92%. Comparing base (cdb0fa2) to head (e24bc7e).

Files with missing lines Patch % Lines
pkg/controller/controller.go 61.11% 4 Missing and 3 partials ⚠️
pkg/config/config.go 94.44% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #422      +/-   ##
==========================================
+ Coverage   66.29%   67.92%   +1.63%     
==========================================
  Files          30       30              
  Lines        2572     2619      +47     
==========================================
+ Hits         1705     1779      +74     
+ Misses        753      725      -28     
- Partials      114      115       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@davidxia
Copy link
Copy Markdown
Contributor Author

Anything I can do to help move this along?

Adds three new SpiceDBCluster config fields:
- `pdbDisabled` (bool): disables PDB creation entirely; any existing PDB
  owned by the cluster is deleted on the next reconcile
- `pdbMaxUnavailable` (int or percentage string, e.g. "2" or "50%"):
  sets the PDB's maxUnavailable field; defaults to 1 when neither field is set
- `pdbMinAvailable` (int or percentage string): sets the PDB's minAvailable
  field; mutually exclusive with pdbMaxUnavailable

Fixes authzed#414

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@davidxia davidxia force-pushed the feat/configurable-pdb branch from 1da0e19 to 86ab60e Compare May 28, 2026 13:20
@davidxia davidxia requested review from ecordell and miparnisari May 28, 2026 13:25
Comment thread pkg/controller/controller_test.go Outdated
Signed-off-by: David Xia <david@davidxia.com>
@miparnisari miparnisari enabled auto-merge May 28, 2026 17:30
miparnisari
miparnisari previously approved these changes May 28, 2026
Signed-off-by: David Xia <david@davidxia.com>
auto-merge was automatically disabled May 28, 2026 17:46

Head branch was pushed to by a user without write access

@davidxia
Copy link
Copy Markdown
Contributor Author

@miparnisari thanks, fixed a blocking golint violation

@miparnisari miparnisari enabled auto-merge May 28, 2026 17:48
Copy link
Copy Markdown
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution!

@miparnisari miparnisari added this pull request to the merge queue May 28, 2026
Merged via the queue into authzed:main with commit 8367340 May 28, 2026
20 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 28, 2026
@davidxia davidxia deleted the feat/configurable-pdb branch May 28, 2026 20:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support configurable PodDisruptionBudget?

4 participants