Skip to content

Commit bad8a51

Browse files
committed
Read PV object from apiserver to prevent flake
1 parent 1c548c3 commit bad8a51

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
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)

0 commit comments

Comments
 (0)