Skip to content

Commit

Permalink
Add integration test for DNS functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Jan 10, 2019
1 parent 10003b0 commit da69d83
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 45 deletions.
8 changes: 5 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ required = [

[[constraint]]
name = "github.com/dlespiau/kube-test-harness"
branch = "kubernetes-1.11"
branch = "master"

[[constraint]]
name = "github.com/awslabs/goformation"
Expand Down
123 changes: 82 additions & 41 deletions integration/creategetdelete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
"time"

awseks "github.com/aws/aws-sdk-go/service/eks"
harness "github.com/dlespiau/kube-test-harness"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/clientcmd"

api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha3"

harness "github.com/dlespiau/kube-test-harness"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -100,45 +99,6 @@ var _ = Describe("(Integration) Create, Get, Scale & Delete", func() {
Expect(config.CurrentContext).To(ContainSubstring(region))
})

Context("and we create a deployment using kubectl", func() {
var (
err error
test *harness.Test
)

BeforeEach(func() {
test, err = newKubeTest()
Expect(err).ShouldNot(HaveOccurred())
test.CreateNamespace(test.Namespace)
})

AfterEach(func() {
test.Close()
})

It("should deploy the service to the cluster", func() {
d := test.CreateDeploymentFromFile(test.Namespace, "podinfo.yaml")
test.WaitForDeploymentReady(d, 1*time.Minute)

pods := test.ListPodsFromDeployment(d)
Expect(len(pods.Items)).To(Equal(2))

// For each pod of the Deployment, check we receive a sensible response to a
// GET request on /version.
for _, pod := range pods.Items {
Expect(pod.Namespace).To(Equal(test.Namespace))

req := test.PodProxyGet(&pod, "", "/version")
fmt.Fprintf(GinkgoWriter, "url = %#v", req.URL())

var js interface{}
test.PodProxyGetJSON(&pod, "", "/version", &js)

Expect(js.(map[string]interface{})).To(HaveKeyWithValue("version", "1.0.1"))
}
})
})

Context("and listing clusters", func() {
It("should return the previously created cluster", func() {
cmdSession := eksctl("get", "clusters", "--region", region)
Expand Down Expand Up @@ -194,6 +154,61 @@ var _ = Describe("(Integration) Create, Get, Scale & Delete", func() {
Expect(len(nodes.Items)).To(Equal(3))
})

Context("and we create a deployment using kubectl", func() {
var (
err error
test *harness.Test
)

BeforeEach(func() {
test, err = newKubeTest()
Expect(err).ShouldNot(HaveOccurred())
test.CreateNamespace(test.Namespace)
})

AfterEach(func() {
test.Close()
})

It("should deploy the service to the cluster", func() {
d := test.CreateDeploymentFromFile(test.Namespace, "podinfo.yaml")
test.WaitForDeploymentReady(d, 1*time.Minute)

pods := test.ListPodsFromDeployment(d)
Expect(len(pods.Items)).To(Equal(2))

// For each pod of the Deployment, check we receive a sensible response to a
// GET request on /version.
for _, pod := range pods.Items {
Expect(pod.Namespace).To(Equal(test.Namespace))

req := test.PodProxyGet(&pod, "", "/version")
fmt.Fprintf(GinkgoWriter, "url = %#v", req.URL())

var js interface{}
test.PodProxyGetJSON(&pod, "", "/version", &js)

Expect(js.(map[string]interface{})).To(HaveKeyWithValue("version", "1.0.1"))
}
})

It("should have functional DNS", func() {
test, err := newKubeTest()
Expect(err).ShouldNot(HaveOccurred())
defer test.Close()

d := test.CreateDaemonSetFromFile(test.Namespace, "dns-test.yaml")

test.WaitForDaemonSetReady(d, 3*time.Minute)

{
ds, err := test.GetDaemonSet(test.Namespace, d.Name)
Expect(err).ShouldNot(HaveOccurred())
fmt.Fprintf(GinkgoWriter, "ds.Status = %#v", ds.Status)
}
})
})

Context("and delete the second nodegroup", func() {
It("should not return an error", func() {
eksctl("delete", "nodegroup",
Expand All @@ -220,6 +235,32 @@ var _ = Describe("(Integration) Create, Get, Scale & Delete", func() {
})
})

Context("and scale the initial nodegroup back to 1 node", func() {
It("should not return an error", func() {
eksctl("scale", "nodegroup",
"--verbose", "4",
"--cluster", clusterName,
"--region", region,
"--nodes", "1",
"--name", initNG,
)
})

It("should make it 1 nodes total", func() {
test, err := newKubeTest()
Expect(err).ShouldNot(HaveOccurred())
defer test.Close()

test.WaitForNodesReady(1, commonTimeout)

nodes := test.ListNodes((metav1.ListOptions{
LabelSelector: api.NodeGroupNameLabel + "=" + initNG,
}))

Expect(len(nodes.Items)).To(Equal(1))
})
})

Context("and deleting the cluster", func() {
It("should not return an error", func() {
if !doDelete {
Expand Down
31 changes: 31 additions & 0 deletions integration/dns-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
run: dns-test
name: dns-test
spec:
selector:
matchLabels:
run: dns-test
template:
metadata:
creationTimestamp: null
labels:
run: dns-test
spec:
containers:
- image: tutum/dnsutils
name: dns-test
stdin: true
tty: true
readinessProbe:
initialDelaySeconds: 0
periodSeconds: 3
failureThreshold: 3
timeoutSeconds: 1
exec:
command:
- nslookup
- kubernetes.default.svc.cluster.local.

145 changes: 145 additions & 0 deletions vendor/github.com/dlespiau/kube-test-harness/daemonset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da69d83

Please sign in to comment.