mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-05 10:05:47 +00:00
Initial Pod e2e test
This commit is contained in:
@@ -17,36 +17,65 @@ limitations under the License.
|
||||
package e2e_node
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
)
|
||||
|
||||
var _ = Describe("Kubelet", func() {
|
||||
var cl *client.Client
|
||||
BeforeEach(func() {
|
||||
// Setup the client to talk to the kubelet
|
||||
// Setup the apiserver client
|
||||
cl = client.NewOrDie(&client.Config{Host: *apiServerAddress})
|
||||
})
|
||||
|
||||
Describe("checking kubelet status", func() {
|
||||
Context("when retrieving the node status", func() {
|
||||
It("should have the container version", func() {
|
||||
Describe("pod scheduling", func() {
|
||||
Context("when scheduling a busybox command in a pod", func() {
|
||||
It("it should return succes", func() {
|
||||
pod := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "busybox",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
NodeName: *nodeName,
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "busybox",
|
||||
Name: "busybox",
|
||||
Command: []string{"echo", "'Hello World'"},
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := cl.Pods(api.NamespaceDefault).Create(pod)
|
||||
Expect(err).To(BeNil(), fmt.Sprintf("Error creating Pod %v", err))
|
||||
})
|
||||
|
||||
// TODO: This is just a place holder, write a real test here
|
||||
resp, err := http.Get(fmt.Sprintf("http://%s:%d/api/v2.0/attributes", *kubeletHost, *kubeletPort))
|
||||
if err != nil {
|
||||
glog.Errorf("Error: %v", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
glog.Errorf("Error: %v", err)
|
||||
return
|
||||
}
|
||||
glog.Infof("Resp: %s", body)
|
||||
It("it should print the output to logs", func() {
|
||||
errs := Retry(time.Minute*3, time.Second*2, cl, func(cl *client.Client) error {
|
||||
rc, err := cl.Pods(api.NamespaceDefault).GetLogs("busybox", &api.PodLogOptions{}).Stream()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rc.Close()
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(rc)
|
||||
Expect(buf.String()).To(Equal("'Hello World'\n"))
|
||||
return nil
|
||||
})
|
||||
Expect(errs).To(BeEmpty(), fmt.Sprintf("Failed to get Logs"))
|
||||
})
|
||||
|
||||
It("it should be possible to delete", func() {
|
||||
err := cl.Pods(api.NamespaceDefault).Delete("busybox", &api.DeleteOptions{})
|
||||
Expect(err).To(BeNil(), fmt.Sprintf("Error creating Pod %v", err))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user