mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #114870 from mattcary/mutation
Avoid mutation of PVC in stateful set controller shared cache
This commit is contained in:
commit
901c1de5ea
@ -241,6 +241,7 @@ func (spc *StatefulPodControl) UpdatePodClaimForRetentionPolicy(set *apps.Statef
|
||||
return fmt.Errorf("Could not retrieve claim %s not found for %s when checking PVC deletion policy: %w", claimName, pod.Name, err)
|
||||
default:
|
||||
if !claimOwnerMatchesSetAndPod(claim, set, pod) {
|
||||
claim = claim.DeepCopy() // Make a copy so we don't mutate the shared cache.
|
||||
needsUpdate := updateClaimOwnerRefForSetAndPod(claim, set, pod)
|
||||
if needsUpdate {
|
||||
err := spc.objectMgr.UpdateClaim(claim)
|
||||
|
@ -536,6 +536,11 @@ func TestStatefulPodControlUpdatePodClaimForRetentionPolicy(t *testing.T) {
|
||||
fakeClient := &fake.Clientset{}
|
||||
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
claimLister := corelisters.NewPersistentVolumeClaimLister(indexer)
|
||||
fakeClient.AddReactor("update", "persistentvolumeclaims", func(action core.Action) (bool, runtime.Object, error) {
|
||||
update := action.(core.UpdateAction)
|
||||
indexer.Update(update.GetObject())
|
||||
return true, update.GetObject(), nil
|
||||
})
|
||||
set := newStatefulSet(3)
|
||||
set.GetObjectMeta().SetUID("set-123")
|
||||
pod := newStatefulSetPod(set, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user