mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #14372 from markturansky/remove_flaky_test
Fixed code issues related to hasty test refactor
This commit is contained in:
commit
2d69baf920
@ -54,59 +54,6 @@ func TestPersistentVolumeRecycler(t *testing.T) {
|
|||||||
recycler.Run()
|
recycler.Run()
|
||||||
defer recycler.Stop()
|
defer recycler.Stop()
|
||||||
|
|
||||||
// This PV will be claimed, released, and recycled.
|
|
||||||
pv := &api.PersistentVolume{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "fake-pv"},
|
|
||||||
Spec: api.PersistentVolumeSpec{
|
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "foo"}},
|
|
||||||
Capacity: api.ResourceList{api.ResourceName(api.ResourceStorage): resource.MustParse("10G")},
|
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
|
|
||||||
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
pvc := &api.PersistentVolumeClaim{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "fake-pvc"},
|
|
||||||
Spec: api.PersistentVolumeClaimSpec{
|
|
||||||
Resources: api.ResourceRequirements{Requests: api.ResourceList{api.ResourceName(api.ResourceStorage): resource.MustParse("5G")}},
|
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
watch, _ := testClient.PersistentVolumes().Watch(labels.Everything(), fields.Everything(), "0")
|
|
||||||
defer watch.Stop()
|
|
||||||
|
|
||||||
_, _ = testClient.PersistentVolumes().Create(pv)
|
|
||||||
_, _ = testClient.PersistentVolumeClaims(api.NamespaceDefault).Create(pvc)
|
|
||||||
|
|
||||||
// wait until the binder pairs the volume and claim
|
|
||||||
waitForPersistentVolumePhase(watch, api.VolumeBound)
|
|
||||||
|
|
||||||
// deleting a claim releases the volume, after which it can be recycled
|
|
||||||
if err := testClient.PersistentVolumeClaims(api.NamespaceDefault).Delete(pvc.Name); err != nil {
|
|
||||||
t.Errorf("error deleting claim %s", pvc.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
waitForPersistentVolumePhase(watch, api.VolumeReleased)
|
|
||||||
waitForPersistentVolumePhase(watch, api.VolumeAvailable)
|
|
||||||
|
|
||||||
// end of Recycler test.
|
|
||||||
// Deleter test begins now.
|
|
||||||
// tests are serial because running masters concurrently that delete keys may cause similar tests to time out
|
|
||||||
|
|
||||||
deleteAllEtcdKeys()
|
|
||||||
binderClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Default.Version()})
|
|
||||||
recyclerClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Default.Version()})
|
|
||||||
testClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Default.Version()})
|
|
||||||
|
|
||||||
binder := volumeclaimbinder.NewPersistentVolumeClaimBinder(binderClient, 1*time.Second)
|
|
||||||
binder.Run()
|
|
||||||
defer binder.Stop()
|
|
||||||
|
|
||||||
recycler, _ := volumeclaimbinder.NewPersistentVolumeRecycler(recyclerClient, 1*time.Second, []volume.VolumePlugin{&volume.FakeVolumePlugin{"plugin-name", volume.NewFakeVolumeHost("/tmp/fake", nil, nil)}})
|
|
||||||
recycler.Run()
|
|
||||||
defer recycler.Stop()
|
|
||||||
|
|
||||||
// This PV will be claimed, released, and recycled.
|
// This PV will be claimed, released, and recycled.
|
||||||
pv := &api.PersistentVolume{
|
pv := &api.PersistentVolume{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "fake-pv"},
|
ObjectMeta: api.ObjectMeta{Name: "fake-pv"},
|
||||||
@ -114,7 +61,7 @@ func TestPersistentVolumeRecycler(t *testing.T) {
|
|||||||
PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "/tmp/foo"}},
|
PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "/tmp/foo"}},
|
||||||
Capacity: api.ResourceList{api.ResourceName(api.ResourceStorage): resource.MustParse("10G")},
|
Capacity: api.ResourceList{api.ResourceName(api.ResourceStorage): resource.MustParse("10G")},
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
|
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
|
||||||
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete,
|
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,6 +87,31 @@ func TestPersistentVolumeRecycler(t *testing.T) {
|
|||||||
t.Errorf("error deleting claim %s", pvc.Name)
|
t.Errorf("error deleting claim %s", pvc.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
waitForPersistentVolumePhase(w, api.VolumeReleased)
|
||||||
|
waitForPersistentVolumePhase(w, api.VolumeAvailable)
|
||||||
|
|
||||||
|
// end of Recycler test.
|
||||||
|
// Deleter test begins now.
|
||||||
|
// tests are serial because running masters concurrently that delete keys may cause similar tests to time out
|
||||||
|
|
||||||
|
deleteAllEtcdKeys()
|
||||||
|
|
||||||
|
// change the reclamation policy of the PV for the next test
|
||||||
|
pv.Spec.PersistentVolumeReclaimPolicy = api.PersistentVolumeReclaimDelete
|
||||||
|
|
||||||
|
w, _ = testClient.PersistentVolumes().Watch(labels.Everything(), fields.Everything(), "0")
|
||||||
|
defer w.Stop()
|
||||||
|
|
||||||
|
_, _ = testClient.PersistentVolumes().Create(pv)
|
||||||
|
_, _ = testClient.PersistentVolumeClaims(api.NamespaceDefault).Create(pvc)
|
||||||
|
|
||||||
|
waitForPersistentVolumePhase(w, api.VolumeBound)
|
||||||
|
|
||||||
|
// deleting a claim releases the volume, after which it can be recycled
|
||||||
|
if err := testClient.PersistentVolumeClaims(api.NamespaceDefault).Delete(pvc.Name); err != nil {
|
||||||
|
t.Errorf("error deleting claim %s", pvc.Name)
|
||||||
|
}
|
||||||
|
|
||||||
waitForPersistentVolumePhase(w, api.VolumeReleased)
|
waitForPersistentVolumePhase(w, api.VolumeReleased)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user