This repository has been archived by the owner on Jul 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Baxter
committed
May 24, 2017
1 parent
9d5c6b0
commit cb6b2f5
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestDeleteAPI(t *testing.T) { | ||
apiPods, err := client.CoreV1().Pods("kube-system").List(metav1.ListOptions{LabelSelector: "k8s-app=kube-apiserver"}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// delete any api-server pods | ||
for i, pod := range apiPods.Items { | ||
err := client.CoreV1().Pods("kube-system").Delete(pod.ObjectMeta.Name, &metav1.DeleteOptions{}) | ||
if err != nil { | ||
// TODO: if HA we should be able to successfully | ||
// delete all. Until then just log if we can't delete | ||
// something that isn't the first pod. | ||
if i == 0 { | ||
t.Fatalf("error deleting api-server pod: %v", err) | ||
} else { | ||
t.Logf("error deleting api-server pod: %v", err) | ||
} | ||
} | ||
} | ||
|
||
// wait for api-server to go down by waiting until listing pods returns | ||
// errors. This is potentially error prone, but without waiting for the | ||
// apiserver to go down the next step will return sucess before the | ||
// apiserver is ever destroyed. | ||
waitDestroy := func() error { | ||
_, err := client.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: "k8s-app=kube-apiserver"}) | ||
if err == nil { | ||
return fmt.Errorf("waiting for apiserver to go down: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
if err := retry(100, 500*time.Millisecond, waitDestroy); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// wait until api server is back up | ||
waitAPI := func() error { | ||
_, err := client.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: "k8s-app=kube-apiserver"}) | ||
if err != nil { | ||
return fmt.Errorf("waiting for apiserver to return: %v", err) | ||
} | ||
return nil | ||
} | ||
if err := retry(30, 10*time.Second, waitAPI); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |