k3s/test/e2e_node/kubelet_test.go

83 lines
2.3 KiB
Go
Raw Normal View History

2015-11-10 23:42:07 +00:00
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e_node
import (
2015-11-20 23:59:31 +00:00
"bytes"
2015-11-10 23:42:07 +00:00
"fmt"
2015-11-20 23:59:31 +00:00
"time"
2015-11-10 23:42:07 +00:00
. "github.com/onsi/ginkgo"
2015-11-20 23:59:31 +00:00
. "github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
2015-11-10 23:42:07 +00:00
)
var _ = Describe("Kubelet", func() {
2015-11-20 23:59:31 +00:00
var cl *client.Client
2015-11-10 23:42:07 +00:00
BeforeEach(func() {
2015-11-20 23:59:31 +00:00
// Setup the apiserver client
cl = client.NewOrDie(&client.Config{Host: *apiServerAddress})
2015-11-10 23:42:07 +00:00
})
2015-11-20 23:59:31 +00:00
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",
},
},
},
2015-11-10 23:42:07 +00:00
}
2015-11-20 23:59:31 +00:00
_, err := cl.Pods(api.NamespaceDefault).Create(pod)
Expect(err).To(BeNil(), fmt.Sprintf("Error creating Pod %v", err))
})
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))
2015-11-10 23:42:07 +00:00
})
})
})
})