mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Converted TestKubeletSendsEvent to native ginkgo syntax #4220
This commit is contained in:
parent
cfe96c08b9
commit
5013375242
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -24,22 +25,28 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/golang/glog"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestKubeletSendsEvent checks that kubelets and scheduler send events about pods scheduling and running.
|
var _ = Describe("Events", func() {
|
||||||
func TestKubeletSendsEvent(c *client.Client) bool {
|
var c *client.Client
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
c = loadClientOrDie()
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should be sent by kubelets and the scheduler about pods scheduling and running", func() {
|
||||||
provider := testContext.provider
|
provider := testContext.provider
|
||||||
if len(provider) > 0 && provider != "gce" && provider != "gke" && provider != "aws" {
|
if len(provider) > 0 && provider != "gce" && provider != "gke" && provider != "aws" {
|
||||||
glog.Infof("skipping TestKubeletSendsEvent on cloud provider %s", provider)
|
By(fmt.Sprintf("skipping TestKubeletSendsEvent on cloud provider %s", provider))
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
podClient := c.Pods(api.NamespaceDefault)
|
podClient := c.Pods(api.NamespaceDefault)
|
||||||
|
|
||||||
|
By("creating the pod")
|
||||||
name := "send-events-" + string(util.NewUUID())
|
name := "send-events-" + string(util.NewUUID())
|
||||||
value := strconv.Itoa(time.Now().Nanosecond())
|
value := strconv.Itoa(time.Now().Nanosecond())
|
||||||
pod := &api.Pod{
|
pod := &api.Pod{
|
||||||
@ -60,27 +67,34 @@ func TestKubeletSendsEvent(c *client.Client) bool {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
By("submitting the pod to kubernetes")
|
||||||
_, err := podClient.Create(pod)
|
_, err := podClient.Create(pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to create pod: %v", err)
|
Fail(fmt.Sprintf("Failed to create pod: %v", err))
|
||||||
return false
|
|
||||||
}
|
|
||||||
defer podClient.Delete(pod.Name)
|
|
||||||
waitForPodRunning(c, pod.Name)
|
|
||||||
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
|
||||||
if len(pods.Items) != 1 {
|
|
||||||
glog.Errorf("Failed to find the correct pod")
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
By("deleting the pod")
|
||||||
|
defer GinkgoRecover()
|
||||||
|
podClient.Delete(pod.Name)
|
||||||
|
}()
|
||||||
|
|
||||||
|
By("waiting for the pod to start running")
|
||||||
|
waitForPodRunning(c, pod.Name)
|
||||||
|
|
||||||
|
By("verifying the pod is in kubernetes")
|
||||||
|
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
||||||
|
Expect(len(pods.Items)).To(Equal(1))
|
||||||
|
|
||||||
|
By("retrieving the pod")
|
||||||
podWithUid, err := podClient.Get(pod.Name)
|
podWithUid, err := podClient.Get(pod.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to get pod: %v", err)
|
Fail(fmt.Sprintf("Failed to get pod: %v", err))
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
fmt.Printf("%+v\n", podWithUid)
|
||||||
|
|
||||||
// Check for scheduler event about the pod.
|
// Check for scheduler event about the pod.
|
||||||
glog.Infof("%+v", podWithUid)
|
By("checking for scheduler event about the pod")
|
||||||
events, err := c.Events(api.NamespaceDefault).List(
|
events, err := c.Events(api.NamespaceDefault).List(
|
||||||
labels.Everything(),
|
labels.Everything(),
|
||||||
labels.Set{
|
labels.Set{
|
||||||
@ -91,16 +105,13 @@ func TestKubeletSendsEvent(c *client.Client) bool {
|
|||||||
}.AsSelector(),
|
}.AsSelector(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("Error while listing events:", err)
|
Fail(fmt.Sprintf("Error while listing events:", err))
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
if len(events.Items) == 0 {
|
Expect(len(events.Items)).ToNot(BeZero(), "scheduler events from running pod")
|
||||||
glog.Error("Didn't see any scheduler events even though pod was running.")
|
fmt.Println("Saw scheduler event for our pod.")
|
||||||
return false
|
|
||||||
}
|
|
||||||
glog.Info("Saw scheduler event for our pod.")
|
|
||||||
|
|
||||||
// Check for kubelet event about the pod.
|
// Check for kubelet event about the pod.
|
||||||
|
By("checking for kubelet event about the pod")
|
||||||
events, err = c.Events(api.NamespaceDefault).List(
|
events, err = c.Events(api.NamespaceDefault).List(
|
||||||
labels.Everything(),
|
labels.Everything(),
|
||||||
labels.Set{
|
labels.Set{
|
||||||
@ -111,21 +122,9 @@ func TestKubeletSendsEvent(c *client.Client) bool {
|
|||||||
}.AsSelector(),
|
}.AsSelector(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("Error while listing events:", err)
|
Fail(fmt.Sprintf("Error while listing events:", err))
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
if len(events.Items) == 0 {
|
Expect(len(events.Items)).ToNot(BeZero(), "kubelet events from running pod")
|
||||||
glog.Error("Didn't see any kubelet events even though pod was running.")
|
fmt.Println("Saw kubelet event for our pod.")
|
||||||
return false
|
|
||||||
}
|
|
||||||
glog.Info("Saw kubelet event for our pod.")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Describe("TestKubeletSendsEvent", func() {
|
|
||||||
It("should pass", func() {
|
|
||||||
// TODO: Instead of OrDie, client should Fail the test if there's a problem.
|
|
||||||
// In general tests should Fail() instead of glog.Fatalf().
|
|
||||||
Expect(TestKubeletSendsEvent(loadClientOrDie())).To(BeTrue())
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user