mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #94144 from gnufied/prevent-stale-pv-read
Reduce offline volume expansion flake
This commit is contained in:
commit
c7d6f796fe
@ -18,6 +18,7 @@ go_library(
|
||||
"//staging/src/k8s.io/api/authentication/v1:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package expand
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
@ -28,6 +29,7 @@ import (
|
||||
authenticationv1 "k8s.io/api/authentication/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@ -224,7 +226,7 @@ func (expc *expandController) syncHandler(key string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
pv, err := getPersistentVolume(pvc, expc.pvLister)
|
||||
pv, err := expc.getPersistentVolume(pvc)
|
||||
if err != nil {
|
||||
klog.V(5).Infof("Error getting Persistent Volume for PVC %q (uid: %q) from informer : %v", util.GetPersistentVolumeClaimQualifiedName(pvc), pvc.UID, err)
|
||||
return err
|
||||
@ -335,12 +337,12 @@ func (expc *expandController) runWorker() {
|
||||
}
|
||||
}
|
||||
|
||||
func getPersistentVolume(pvc *v1.PersistentVolumeClaim, pvLister corelisters.PersistentVolumeLister) (*v1.PersistentVolume, error) {
|
||||
func (expc *expandController) getPersistentVolume(pvc *v1.PersistentVolumeClaim) (*v1.PersistentVolume, error) {
|
||||
volumeName := pvc.Spec.VolumeName
|
||||
pv, err := pvLister.Get(volumeName)
|
||||
pv, err := expc.kubeClient.CoreV1().PersistentVolumes().Get(context.TODO(), volumeName, metav1.GetOptions{})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find PV %q in PV informer cache with error : %v", volumeName, err)
|
||||
return nil, fmt.Errorf("failed to get PV %q: %v", volumeName, err)
|
||||
}
|
||||
|
||||
return pv.DeepCopy(), nil
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@ -147,6 +147,11 @@ func TestSyncHandler(t *testing.T) {
|
||||
return nil, nil
|
||||
})
|
||||
|
||||
if test.pv != nil {
|
||||
fakeKubeClient.AddReactor("get", "persistentvolumes", func(action coretesting.Action) (bool, runtime.Object, error) {
|
||||
return true, test.pv, nil
|
||||
})
|
||||
}
|
||||
fakeKubeClient.AddReactor("patch", "persistentvolumeclaims", func(action coretesting.Action) (bool, runtime.Object, error) {
|
||||
if action.GetSubresource() == "status" {
|
||||
patchActionaction, _ := action.(coretesting.PatchAction)
|
||||
|
@ -42,6 +42,12 @@ const (
|
||||
resizePollInterval = 2 * time.Second
|
||||
// total time to wait for cloudprovider or file system resize to finish
|
||||
totalResizeWaitPeriod = 10 * time.Minute
|
||||
|
||||
// resizedPodStartupTimeout defines time we should wait for pod that uses offline
|
||||
// resized volume to startup. This time is higher than default PodStartTimeout because
|
||||
// typically time to detach and then attach a volume is amortized in this time duration.
|
||||
resizedPodStartupTimeout = 10 * time.Minute
|
||||
|
||||
// time to wait for PVC conditions to sync
|
||||
pvcConditionSyncPeriod = 2 * time.Minute
|
||||
)
|
||||
@ -214,7 +220,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte
|
||||
SeLinuxLabel: e2epv.SELinuxLabel,
|
||||
NodeSelection: l.config.ClientNodeSelection,
|
||||
}
|
||||
l.pod2, err = e2epod.CreateSecPodWithNodeSelection(f.ClientSet, &podConfig, framework.PodStartTimeout)
|
||||
l.pod2, err = e2epod.CreateSecPodWithNodeSelection(f.ClientSet, &podConfig, resizedPodStartupTimeout)
|
||||
defer func() {
|
||||
err = e2epod.DeletePodWithWait(f.ClientSet, l.pod2)
|
||||
framework.ExpectNoError(err, "while cleaning up pod before exiting resizing test")
|
||||
|
Loading…
Reference in New Issue
Block a user