mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 15:50:10 +00:00
removed flaky test. other integration tests (and many unit tests) also cover binding
This commit is contained in:
parent
ab07e320ec
commit
6dca2a4e7f
@ -37,180 +37,6 @@ func init() {
|
|||||||
requireEtcd()
|
requireEtcd()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentVolumeClaimBinder(t *testing.T) {
|
|
||||||
_, s := runAMaster(t)
|
|
||||||
defer s.Close()
|
|
||||||
|
|
||||||
deleteAllEtcdKeys()
|
|
||||||
binderClient := 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()
|
|
||||||
|
|
||||||
for _, volume := range createTestVolumes() {
|
|
||||||
_, err := testClient.PersistentVolumes().Create(volume)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
volumes, err := testClient.PersistentVolumes().List(labels.Everything(), fields.Everything())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
if len(volumes.Items) != 2 {
|
|
||||||
t.Errorf("expected 2 PVs, got %#v", len(volumes.Items))
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, claim := range createTestClaims() {
|
|
||||||
_, err := testClient.PersistentVolumeClaims(api.NamespaceDefault).Create(claim)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
claims, err := testClient.PersistentVolumeClaims(api.NamespaceDefault).List(labels.Everything(), fields.Everything())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
if len(claims.Items) != 3 {
|
|
||||||
t.Errorf("expected 3 PVCs, got %#v", len(claims.Items))
|
|
||||||
}
|
|
||||||
|
|
||||||
// the binder will eventually catch up and set status on Claims
|
|
||||||
watch, err := testClient.PersistentVolumeClaims(api.NamespaceDefault).Watch(labels.Everything(), fields.Everything(), "0")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Couldn't subscribe to PersistentVolumeClaims: %v", err)
|
|
||||||
}
|
|
||||||
defer watch.Stop()
|
|
||||||
|
|
||||||
// Wait for claim01 and claim02 to become bound
|
|
||||||
claim01Pending := true
|
|
||||||
claim02Pending := true
|
|
||||||
for claim01Pending || claim02Pending {
|
|
||||||
event := <-watch.ResultChan()
|
|
||||||
claim := event.Object.(*api.PersistentVolumeClaim)
|
|
||||||
if claim.Spec.VolumeName != "" && claim.Status.Phase != "Bound" {
|
|
||||||
if claim.Name == "claim01" {
|
|
||||||
claim01Pending = false
|
|
||||||
} else if claim.Name == "claim02" {
|
|
||||||
claim02Pending = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, claim := range createTestClaims() {
|
|
||||||
claim, err := testClient.PersistentVolumeClaims(api.NamespaceDefault).Get(claim.Name)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (claim.Name == "claim01" || claim.Name == "claim02") && claim.Spec.VolumeName == "" {
|
|
||||||
t.Errorf("Expected claim to be bound: %+v", claim)
|
|
||||||
}
|
|
||||||
if claim.Name == "claim03" && claim.Spec.VolumeName != "" {
|
|
||||||
t.Errorf("Expected claim03 to be unbound: %v", claim)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func createTestClaims() []*api.PersistentVolumeClaim {
|
|
||||||
return []*api.PersistentVolumeClaim{
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: "claim03",
|
|
||||||
Namespace: api.NamespaceDefault,
|
|
||||||
},
|
|
||||||
Spec: api.PersistentVolumeClaimSpec{
|
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
|
|
||||||
Resources: api.ResourceRequirements{
|
|
||||||
Requests: api.ResourceList{
|
|
||||||
api.ResourceName(api.ResourceStorage): resource.MustParse("500G"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: "claim01",
|
|
||||||
Namespace: api.NamespaceDefault,
|
|
||||||
},
|
|
||||||
Spec: api.PersistentVolumeClaimSpec{
|
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{api.ReadOnlyMany, api.ReadWriteOnce},
|
|
||||||
Resources: api.ResourceRequirements{
|
|
||||||
Requests: api.ResourceList{
|
|
||||||
api.ResourceName(api.ResourceStorage): resource.MustParse("8G"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: "claim02",
|
|
||||||
Namespace: api.NamespaceDefault,
|
|
||||||
},
|
|
||||||
Spec: api.PersistentVolumeClaimSpec{
|
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{api.ReadOnlyMany, api.ReadWriteOnce, api.ReadWriteMany},
|
|
||||||
Resources: api.ResourceRequirements{
|
|
||||||
Requests: api.ResourceList{
|
|
||||||
api.ResourceName(api.ResourceStorage): resource.MustParse("5G"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func createTestVolumes() []*api.PersistentVolume {
|
|
||||||
return []*api.PersistentVolume{
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
UID: "gce-pd-10",
|
|
||||||
Name: "gce003",
|
|
||||||
},
|
|
||||||
Spec: api.PersistentVolumeSpec{
|
|
||||||
Capacity: api.ResourceList{
|
|
||||||
api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
|
|
||||||
},
|
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
|
||||||
GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{
|
|
||||||
PDName: "gce123123123",
|
|
||||||
FSType: "foo",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{
|
|
||||||
api.ReadWriteOnce,
|
|
||||||
api.ReadOnlyMany,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
UID: "nfs-5",
|
|
||||||
Name: "nfs002",
|
|
||||||
},
|
|
||||||
Spec: api.PersistentVolumeSpec{
|
|
||||||
Capacity: api.ResourceList{
|
|
||||||
api.ResourceName(api.ResourceStorage): resource.MustParse("5G"),
|
|
||||||
},
|
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
|
||||||
Glusterfs: &api.GlusterfsVolumeSource{
|
|
||||||
EndpointsName: "andintheend",
|
|
||||||
Path: "theloveyoutakeisequaltotheloveyoumake",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
AccessModes: []api.PersistentVolumeAccessMode{
|
|
||||||
api.ReadWriteOnce,
|
|
||||||
api.ReadOnlyMany,
|
|
||||||
api.ReadWriteMany,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPersistentVolumeRecycler(t *testing.T) {
|
func TestPersistentVolumeRecycler(t *testing.T) {
|
||||||
_, s := runAMaster(t)
|
_, s := runAMaster(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user