Skip to content

Commit c7d6f79

Browse files
authored
Merge pull request kubernetes#94144 from gnufied/prevent-stale-pv-read
Reduce offline volume expansion flake
2 parents 0d723d4 + 4614817 commit c7d6f79

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

pkg/controller/volume/expand/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ go_library(
1818
"//staging/src/k8s.io/api/authentication/v1:go_default_library",
1919
"//staging/src/k8s.io/api/core/v1:go_default_library",
2020
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
21+
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
2122
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
2223
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
2324
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",

pkg/controller/volume/expand/expand_controller.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package expand
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"net"
2223
"time"
@@ -28,6 +29,7 @@ import (
2829
authenticationv1 "k8s.io/api/authentication/v1"
2930
v1 "k8s.io/api/core/v1"
3031
"k8s.io/apimachinery/pkg/api/errors"
32+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3133
"k8s.io/apimachinery/pkg/types"
3234
"k8s.io/apimachinery/pkg/util/runtime"
3335
"k8s.io/apimachinery/pkg/util/wait"
@@ -224,7 +226,7 @@ func (expc *expandController) syncHandler(key string) error {
224226
return err
225227
}
226228

227-
pv, err := getPersistentVolume(pvc, expc.pvLister)
229+
pv, err := expc.getPersistentVolume(pvc)
228230
if err != nil {
229231
klog.V(5).Infof("Error getting Persistent Volume for PVC %q (uid: %q) from informer : %v", util.GetPersistentVolumeClaimQualifiedName(pvc), pvc.UID, err)
230232
return err
@@ -335,12 +337,12 @@ func (expc *expandController) runWorker() {
335337
}
336338
}
337339

338-
func getPersistentVolume(pvc *v1.PersistentVolumeClaim, pvLister corelisters.PersistentVolumeLister) (*v1.PersistentVolume, error) {
340+
func (expc *expandController) getPersistentVolume(pvc *v1.PersistentVolumeClaim) (*v1.PersistentVolume, error) {
339341
volumeName := pvc.Spec.VolumeName
340-
pv, err := pvLister.Get(volumeName)
342+
pv, err := expc.kubeClient.CoreV1().PersistentVolumes().Get(context.TODO(), volumeName, metav1.GetOptions{})
341343

342344
if err != nil {
343-
return nil, fmt.Errorf("failed to find PV %q in PV informer cache with error : %v", volumeName, err)
345+
return nil, fmt.Errorf("failed to get PV %q: %v", volumeName, err)
344346
}
345347

346348
return pv.DeepCopy(), nil

pkg/controller/volume/expand/expand_controller_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"regexp"
2424
"testing"
2525

26-
"k8s.io/api/core/v1"
26+
v1 "k8s.io/api/core/v1"
2727
storagev1 "k8s.io/api/storage/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/apimachinery/pkg/runtime"
@@ -147,6 +147,11 @@ func TestSyncHandler(t *testing.T) {
147147
return nil, nil
148148
})
149149

150+
if test.pv != nil {
151+
fakeKubeClient.AddReactor("get", "persistentvolumes", func(action coretesting.Action) (bool, runtime.Object, error) {
152+
return true, test.pv, nil
153+
})
154+
}
150155
fakeKubeClient.AddReactor("patch", "persistentvolumeclaims", func(action coretesting.Action) (bool, runtime.Object, error) {
151156
if action.GetSubresource() == "status" {
152157
patchActionaction, _ := action.(coretesting.PatchAction)

test/e2e/storage/testsuites/volume_expand.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ const (
4242
resizePollInterval = 2 * time.Second
4343
// total time to wait for cloudprovider or file system resize to finish
4444
totalResizeWaitPeriod = 10 * time.Minute
45+
46+
// resizedPodStartupTimeout defines time we should wait for pod that uses offline
47+
// resized volume to startup. This time is higher than default PodStartTimeout because
48+
// typically time to detach and then attach a volume is amortized in this time duration.
49+
resizedPodStartupTimeout = 10 * time.Minute
50+
4551
// time to wait for PVC conditions to sync
4652
pvcConditionSyncPeriod = 2 * time.Minute
4753
)
@@ -214,7 +220,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte
214220
SeLinuxLabel: e2epv.SELinuxLabel,
215221
NodeSelection: l.config.ClientNodeSelection,
216222
}
217-
l.pod2, err = e2epod.CreateSecPodWithNodeSelection(f.ClientSet, &podConfig, framework.PodStartTimeout)
223+
l.pod2, err = e2epod.CreateSecPodWithNodeSelection(f.ClientSet, &podConfig, resizedPodStartupTimeout)
218224
defer func() {
219225
err = e2epod.DeletePodWithWait(f.ClientSet, l.pod2)
220226
framework.ExpectNoError(err, "while cleaning up pod before exiting resizing test")

0 commit comments

Comments
 (0)