Skip to content

Commit

Permalink
Merge pull request #123754 from dhenkel92/automated-cherry-pick-of-#1…
Browse files Browse the repository at this point in the history
…22056-upstream-release-1.27

Automated cherry pick of #122056: keep existing PDB conditions when updating status
  • Loading branch information
k8s-ci-robot committed Mar 8, 2024
2 parents 134fce2 + 0e0f113 commit 85c4ae7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/controller/disruption/disruption.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ func (dc *DisruptionController) updatePdbStatus(ctx context.Context, pdb *policy
DisruptionsAllowed: disruptionsAllowed,
DisruptedPods: disruptedPods,
ObservedGeneration: pdb.Generation,
Conditions: newPdb.Status.Conditions,
}

pdbhelper.UpdateDisruptionAllowedCondition(newPdb)
Expand Down
33 changes: 33 additions & 0 deletions pkg/controller/disruption/disruption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,39 @@ func TestStalePodDisruption(t *testing.T) {
}
}

func TestKeepExistingPDBConditionDuringSync(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

dc, ps := newFakeDisruptionController()

pdb, pdbName := newMinAvailablePodDisruptionBudget(t, intstr.FromInt(3))
pdb.Spec.Selector = &metav1.LabelSelector{}

pdb.Status.Conditions = append(pdb.Status.Conditions, metav1.Condition{
Type: "ExistingTestCondition",
Status: metav1.ConditionTrue,
Message: "This is a test condition",
Reason: "Test",
LastTransitionTime: metav1.Now(),
})

add(t, dc.pdbStore, pdb)
if err := dc.sync(ctx, pdbName); err != nil {
t.Fatalf("Failed to sync PDB: %v", err)
}
ps.VerifyPdbStatus(t, pdbName, 0, 0, 3, 0, map[string]metav1.Time{})

actualPDB := ps.Get(pdbName)
condition := apimeta.FindStatusCondition(actualPDB.Status.Conditions, "ExistingTestCondition")
if len(actualPDB.Status.Conditions) != 2 {
t.Fatalf("Expected 2 conditions, but got %d", len(actualPDB.Status.Conditions))
}
if condition == nil {
t.Fatalf("Expected ExistingTestCondition condition, but didn't find it")
}
}

// waitForCacheCount blocks until the given cache store has the desired number
// of items in it. This will return an error if the condition is not met after a
// 10 second timeout.
Expand Down

0 comments on commit 85c4ae7

Please sign in to comment.