mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
Merge pull request #8706 from lavalamp/e2e-timeout
Use e2e framework in more tests
This commit is contained in:
commit
e52e299de2
@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
@ -38,25 +37,15 @@ var dnsServiceLableSelector = labels.Set{
|
||||
}.AsSelector()
|
||||
|
||||
var _ = Describe("DNS", func() {
|
||||
var c *client.Client
|
||||
// Use this in tests. They're unique for each test to prevent name collisions.
|
||||
var testNamespace string
|
||||
f := NewFramework("dns")
|
||||
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
c, err = loadClient()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
ns, err := createTestingNS("dns", c)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
testNamespace = ns.Name
|
||||
})
|
||||
It("should provide DNS for the cluster", func() {
|
||||
if providerIs("vagrant") {
|
||||
By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)")
|
||||
return
|
||||
}
|
||||
|
||||
podClient := c.Pods(api.NamespaceDefault)
|
||||
podClient := f.Client.Pods(api.NamespaceDefault)
|
||||
|
||||
By("Waiting for DNS Service to be Running")
|
||||
dnsPods, err := podClient.List(dnsServiceLableSelector, fields.Everything())
|
||||
@ -66,7 +55,7 @@ var _ = Describe("DNS", func() {
|
||||
if len(dnsPods.Items) != 1 {
|
||||
Failf("Unexpected number of pods (%d) matches the label selector %v", len(dnsPods.Items), dnsServiceLableSelector.String())
|
||||
}
|
||||
expectNoError(waitForPodRunning(c, dnsPods.Items[0].Name))
|
||||
expectNoError(waitForPodRunning(f.Client, dnsPods.Items[0].Name))
|
||||
|
||||
// All the names we need to be able to resolve.
|
||||
// TODO: Spin up a separate test service and test that dns works for that service.
|
||||
@ -99,7 +88,7 @@ var _ = Describe("DNS", func() {
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "dns-test-" + string(util.NewUUID()),
|
||||
Namespace: testNamespace,
|
||||
Namespace: f.Namespace.Name,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
@ -138,7 +127,7 @@ var _ = Describe("DNS", func() {
|
||||
}
|
||||
|
||||
By("submitting the pod to kubernetes")
|
||||
podClient = c.Pods(testNamespace)
|
||||
podClient = f.Client.Pods(f.Namespace.Name)
|
||||
defer func() {
|
||||
By("deleting the pod")
|
||||
defer GinkgoRecover()
|
||||
@ -148,7 +137,7 @@ var _ = Describe("DNS", func() {
|
||||
Failf("Failed to create %s pod: %v", pod.Name, err)
|
||||
}
|
||||
|
||||
expectNoError(waitForPodRunningInNamespace(c, pod.Name, testNamespace))
|
||||
expectNoError(f.WaitForPodRunning(pod.Name))
|
||||
|
||||
By("retrieving the pod")
|
||||
pod, err = podClient.Get(pod.Name)
|
||||
@ -165,10 +154,10 @@ var _ = Describe("DNS", func() {
|
||||
for _, name := range namesToResolve {
|
||||
for _, proto := range []string{"udp", "tcp"} {
|
||||
testCase := fmt.Sprintf("%s@%s", proto, name)
|
||||
_, err := c.Get().
|
||||
_, err := f.Client.Get().
|
||||
Prefix("proxy").
|
||||
Resource("pods").
|
||||
Namespace(testNamespace).
|
||||
Namespace(f.Namespace.Name).
|
||||
Name(pod.Name).
|
||||
Suffix("results", testCase).
|
||||
Do().Raw()
|
||||
|
@ -22,22 +22,13 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
)
|
||||
|
||||
var _ = Describe("emptyDir", func() {
|
||||
var (
|
||||
c *client.Client
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
c, err = loadClient()
|
||||
expectNoError(err)
|
||||
})
|
||||
f := NewFramework("emptydir")
|
||||
|
||||
It("volume on tmpfs should have the correct mode", func() {
|
||||
volumePath := "/test-volume"
|
||||
@ -50,7 +41,7 @@ var _ = Describe("emptyDir", func() {
|
||||
fmt.Sprintf("--fs_type=%v", volumePath),
|
||||
fmt.Sprintf("--file_mode=%v", volumePath),
|
||||
}
|
||||
testContainerOutput("emptydir r/w on tmpfs", c, pod, []string{
|
||||
f.TestContainerOutput("emptydir r/w on tmpfs", pod, []string{
|
||||
"mount type of \"/test-volume\": tmpfs",
|
||||
"mode of file \"/test-volume\": dtrwxrwxrwx", // we expect the sticky bit (mode flag t) to be set for the dir
|
||||
})
|
||||
@ -69,7 +60,7 @@ var _ = Describe("emptyDir", func() {
|
||||
fmt.Sprintf("--rw_new_file=%v", filePath),
|
||||
fmt.Sprintf("--file_mode=%v", filePath),
|
||||
}
|
||||
testContainerOutput("emptydir r/w on tmpfs", c, pod, []string{
|
||||
f.TestContainerOutput("emptydir r/w on tmpfs", pod, []string{
|
||||
"mount type of \"/test-volume\": tmpfs",
|
||||
"mode of file \"/test-volume/test-file\": -rw-r--r--",
|
||||
"content of file \"/test-volume/test-file\": mount-tester new file",
|
||||
|
@ -94,3 +94,8 @@ func (f *Framework) afterEach() {
|
||||
func (f *Framework) WaitForPodRunning(podName string) error {
|
||||
return waitForPodRunningInNamespace(f.Client, podName, f.Namespace.Name)
|
||||
}
|
||||
|
||||
// Runs the given pod and verifies that its output matches the desired output.
|
||||
func (f *Framework) TestContainerOutput(scenarioName string, pod *api.Pod, expectedOutput []string) {
|
||||
testContainerOutputInNamespace(scenarioName, f.Client, pod, expectedOutput, f.Namespace.Name)
|
||||
}
|
||||
|
@ -20,33 +20,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
)
|
||||
|
||||
var _ = Describe("Secrets", func() {
|
||||
var c *client.Client
|
||||
var ns string
|
||||
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
c, err = loadClient()
|
||||
expectNoError(err)
|
||||
ns_, err := createTestingNS("secrets", c)
|
||||
ns = ns_.Name
|
||||
expectNoError(err)
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
// Clean up the namespace if a non-default one was used
|
||||
if ns != api.NamespaceDefault {
|
||||
By("Cleaning up the namespace")
|
||||
err := c.Namespaces().Delete(ns)
|
||||
expectNoError(err)
|
||||
}
|
||||
})
|
||||
f := NewFramework("secrets")
|
||||
|
||||
It("should be consumable from pods", func() {
|
||||
name := "secret-test-" + string(util.NewUUID())
|
||||
@ -55,7 +35,7 @@ var _ = Describe("Secrets", func() {
|
||||
|
||||
secret := &api.Secret{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Namespace: ns,
|
||||
Namespace: f.Namespace.Name,
|
||||
Name: name,
|
||||
},
|
||||
Data: map[string][]byte{
|
||||
@ -68,12 +48,12 @@ var _ = Describe("Secrets", func() {
|
||||
By(fmt.Sprintf("Creating secret with name %s", secret.Name))
|
||||
defer func() {
|
||||
By("Cleaning up the secret")
|
||||
if err := c.Secrets(ns).Delete(secret.Name); err != nil {
|
||||
if err := f.Client.Secrets(f.Namespace.Name).Delete(secret.Name); err != nil {
|
||||
Failf("unable to delete secret %v: %v", secret.Name, err)
|
||||
}
|
||||
}()
|
||||
var err error
|
||||
if secret, err = c.Secrets(ns).Create(secret); err != nil {
|
||||
if secret, err = f.Client.Secrets(f.Namespace.Name).Create(secret); err != nil {
|
||||
Failf("unable to create test secret %s: %v", secret.Name, err)
|
||||
}
|
||||
|
||||
@ -112,9 +92,9 @@ var _ = Describe("Secrets", func() {
|
||||
},
|
||||
}
|
||||
|
||||
testContainerOutputInNamespace("consume secrets", c, pod, []string{
|
||||
testContainerOutputInNamespace("consume secrets", f.Client, pod, []string{
|
||||
"content of file \"/etc/secret-volume/data-1\": value-1",
|
||||
"mode of file \"/etc/secret-volume/data-1\": -r--r--r--",
|
||||
}, ns)
|
||||
}, f.Namespace.Name)
|
||||
})
|
||||
})
|
||||
|
@ -32,26 +32,7 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("ServiceAccounts", func() {
|
||||
var c *client.Client
|
||||
var ns string
|
||||
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
c, err = loadClient()
|
||||
expectNoError(err)
|
||||
ns_, err := createTestingNS("service-accounts", c)
|
||||
ns = ns_.Name
|
||||
expectNoError(err)
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
// Clean up the namespace if a non-default one was used
|
||||
if ns != api.NamespaceDefault {
|
||||
By("Cleaning up the namespace")
|
||||
err := c.Namespaces().Delete(ns)
|
||||
expectNoError(err)
|
||||
}
|
||||
})
|
||||
f := NewFramework("svcaccounts")
|
||||
|
||||
It("should mount an API token into pods", func() {
|
||||
var tokenName string
|
||||
@ -61,7 +42,7 @@ var _ = Describe("ServiceAccounts", func() {
|
||||
expectNoError(wait.Poll(time.Millisecond*500, time.Second*10, func() (bool, error) {
|
||||
By("getting the auto-created API token")
|
||||
tokenSelector := fields.SelectorFromSet(map[string]string{client.SecretType: string(api.SecretTypeServiceAccountToken)})
|
||||
secrets, err := c.Secrets(ns).List(labels.Everything(), tokenSelector)
|
||||
secrets, err := f.Client.Secrets(f.Namespace.Name).List(labels.Everything(), tokenSelector)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -94,8 +75,8 @@ var _ = Describe("ServiceAccounts", func() {
|
||||
},
|
||||
}
|
||||
|
||||
testContainerOutputInNamespace("consume service account token", c, pod, []string{
|
||||
f.TestContainerOutput("consume service account token", pod, []string{
|
||||
fmt.Sprintf(`content of file "%s/%s": %s`, serviceaccount.DefaultAPITokenMountPath, api.ServiceAccountTokenKey, tokenContent),
|
||||
}, ns)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user