mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Avoid mutation of PVC in stateful set controller shared cache
Change-Id: Ieb8e443e460150d16524ca1c1fb3770f546b2c28
This commit is contained in:
parent
2e3055863d
commit
ed18ab54ba
@ -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)
|
return fmt.Errorf("Could not retrieve claim %s not found for %s when checking PVC deletion policy: %w", claimName, pod.Name, err)
|
||||||
default:
|
default:
|
||||||
if !claimOwnerMatchesSetAndPod(claim, set, pod) {
|
if !claimOwnerMatchesSetAndPod(claim, set, pod) {
|
||||||
|
claim = claim.DeepCopy() // Make a copy so we don't mutate the shared cache.
|
||||||
needsUpdate := updateClaimOwnerRefForSetAndPod(claim, set, pod)
|
needsUpdate := updateClaimOwnerRefForSetAndPod(claim, set, pod)
|
||||||
if needsUpdate {
|
if needsUpdate {
|
||||||
err := spc.objectMgr.UpdateClaim(claim)
|
err := spc.objectMgr.UpdateClaim(claim)
|
||||||
|
@ -536,6 +536,11 @@ func TestStatefulPodControlUpdatePodClaimForRetentionPolicy(t *testing.T) {
|
|||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||||
claimLister := corelisters.NewPersistentVolumeClaimLister(indexer)
|
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 := newStatefulSet(3)
|
||||||
set.GetObjectMeta().SetUID("set-123")
|
set.GetObjectMeta().SetUID("set-123")
|
||||||
pod := newStatefulSetPod(set, 0)
|
pod := newStatefulSetPod(set, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user