mirror of https://github.com/k3s-io/k3s
Merge pull request #57676 from hzxuzhonghu/volume-resize-map-opt
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. optimize volumeResizeMap lock **What this PR does / why we need it**: volumeResizeMap implements VolumeResizeMap interface, but has several useless lock section and one too large critical section. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```pull/6/head
commit
d61eff6c19
|
@ -52,7 +52,7 @@ type volumeResizeMap struct {
|
||||||
// kube client for making API calls
|
// kube client for making API calls
|
||||||
kubeClient clientset.Interface
|
kubeClient clientset.Interface
|
||||||
// for guarding access to pvcrs map
|
// for guarding access to pvcrs map
|
||||||
sync.RWMutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// PVCWithResizeRequest struct defines data structure that stores state needed for
|
// PVCWithResizeRequest struct defines data structure that stores state needed for
|
||||||
|
@ -103,9 +103,6 @@ func (resizeMap *volumeResizeMap) AddPVCUpdate(pvc *v1.PersistentVolumeClaim, pv
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeMap.Lock()
|
|
||||||
defer resizeMap.Unlock()
|
|
||||||
|
|
||||||
pvcSize := pvc.Spec.Resources.Requests[v1.ResourceStorage]
|
pvcSize := pvc.Spec.Resources.Requests[v1.ResourceStorage]
|
||||||
pvcStatusSize := pvc.Status.Capacity[v1.ResourceStorage]
|
pvcStatusSize := pvc.Status.Capacity[v1.ResourceStorage]
|
||||||
|
|
||||||
|
@ -121,6 +118,9 @@ func (resizeMap *volumeResizeMap) AddPVCUpdate(pvc *v1.PersistentVolumeClaim, pv
|
||||||
ExpectedSize: pvcSize,
|
ExpectedSize: pvcSize,
|
||||||
PersistentVolume: pv,
|
PersistentVolume: pv,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resizeMap.Lock()
|
||||||
|
defer resizeMap.Unlock()
|
||||||
resizeMap.pvcrs[types.UniquePVCName(pvc.UID)] = pvcRequest
|
resizeMap.pvcrs[types.UniquePVCName(pvc.UID)] = pvcRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,18 +141,15 @@ func (resizeMap *volumeResizeMap) GetPVCsWithResizeRequest() []*PVCWithResizeReq
|
||||||
// DeletePVC removes given pvc object from list of pvcs that needs resizing.
|
// DeletePVC removes given pvc object from list of pvcs that needs resizing.
|
||||||
// deleting a pvc in this map doesn't affect operations that are already inflight.
|
// deleting a pvc in this map doesn't affect operations that are already inflight.
|
||||||
func (resizeMap *volumeResizeMap) DeletePVC(pvc *v1.PersistentVolumeClaim) {
|
func (resizeMap *volumeResizeMap) DeletePVC(pvc *v1.PersistentVolumeClaim) {
|
||||||
resizeMap.Lock()
|
|
||||||
defer resizeMap.Unlock()
|
|
||||||
pvcUniqueName := types.UniquePVCName(pvc.UID)
|
pvcUniqueName := types.UniquePVCName(pvc.UID)
|
||||||
glog.V(5).Infof("Removing PVC %v from resize map", pvcUniqueName)
|
glog.V(5).Infof("Removing PVC %v from resize map", pvcUniqueName)
|
||||||
|
resizeMap.Lock()
|
||||||
|
defer resizeMap.Unlock()
|
||||||
delete(resizeMap.pvcrs, pvcUniqueName)
|
delete(resizeMap.pvcrs, pvcUniqueName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkAsResized marks a pvc as fully resized
|
// MarkAsResized marks a pvc as fully resized
|
||||||
func (resizeMap *volumeResizeMap) MarkAsResized(pvcr *PVCWithResizeRequest, newSize resource.Quantity) error {
|
func (resizeMap *volumeResizeMap) MarkAsResized(pvcr *PVCWithResizeRequest, newSize resource.Quantity) error {
|
||||||
resizeMap.Lock()
|
|
||||||
defer resizeMap.Unlock()
|
|
||||||
|
|
||||||
emptyCondition := []v1.PersistentVolumeClaimCondition{}
|
emptyCondition := []v1.PersistentVolumeClaimCondition{}
|
||||||
|
|
||||||
err := resizeMap.updatePVCCapacityAndConditions(pvcr, newSize, emptyCondition)
|
err := resizeMap.updatePVCCapacityAndConditions(pvcr, newSize, emptyCondition)
|
||||||
|
@ -165,9 +162,6 @@ func (resizeMap *volumeResizeMap) MarkAsResized(pvcr *PVCWithResizeRequest, newS
|
||||||
|
|
||||||
// UpdatePVSize updates just pv size after cloudprovider resizing is successful
|
// UpdatePVSize updates just pv size after cloudprovider resizing is successful
|
||||||
func (resizeMap *volumeResizeMap) UpdatePVSize(pvcr *PVCWithResizeRequest, newSize resource.Quantity) error {
|
func (resizeMap *volumeResizeMap) UpdatePVSize(pvcr *PVCWithResizeRequest, newSize resource.Quantity) error {
|
||||||
resizeMap.Lock()
|
|
||||||
defer resizeMap.Unlock()
|
|
||||||
|
|
||||||
oldPv := pvcr.PersistentVolume
|
oldPv := pvcr.PersistentVolume
|
||||||
pvClone := oldPv.DeepCopy()
|
pvClone := oldPv.DeepCopy()
|
||||||
|
|
||||||
|
@ -201,7 +195,6 @@ func (resizeMap *volumeResizeMap) UpdatePVSize(pvcr *PVCWithResizeRequest, newSi
|
||||||
}
|
}
|
||||||
|
|
||||||
func (resizeMap *volumeResizeMap) updatePVCCapacityAndConditions(pvcr *PVCWithResizeRequest, newSize resource.Quantity, pvcConditions []v1.PersistentVolumeClaimCondition) error {
|
func (resizeMap *volumeResizeMap) updatePVCCapacityAndConditions(pvcr *PVCWithResizeRequest, newSize resource.Quantity, pvcConditions []v1.PersistentVolumeClaimCondition) error {
|
||||||
|
|
||||||
claimClone := pvcr.PVC.DeepCopy()
|
claimClone := pvcr.PVC.DeepCopy()
|
||||||
|
|
||||||
claimClone.Status.Capacity[v1.ResourceStorage] = newSize
|
claimClone.Status.Capacity[v1.ResourceStorage] = newSize
|
||||||
|
|
Loading…
Reference in New Issue