Skip to content

Commit

Permalink
Merge pull request #2254 from kairen/add-ingress-test
Browse files Browse the repository at this point in the history
Add integration test for ingress addon
  • Loading branch information
r2d4 authored Dec 2, 2017
2 parents 3b997ad + e93a2f4 commit 8f55fb7
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hack/jenkins/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/e2e-${OS_ARCH} out/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/busybox.yaml testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/pvc.yaml testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/busybox-mount-test.yaml testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/nginx-pod-svc.yaml testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/nginx-ing.yaml testdata/

export MINIKUBE_WANTREPORTERRORPROMPT=False
sudo ./out/minikube-${OS_ARCH} delete || true
Expand Down
41 changes: 41 additions & 0 deletions test/integration/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net"
"net/url"
"path/filepath"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -68,6 +69,46 @@ func testDashboard(t *testing.T) {
}
}

func testIngressController(t *testing.T) {
t.Parallel()
minikubeRunner := NewMinikubeRunner(t)
kubectlRunner := util.NewKubectlRunner(t)

minikubeRunner.RunCommand("addons enable ingress", true)
if err := util.WaitForIngressControllerRunning(t); err != nil {
t.Fatalf("waiting for ingress-controller to be up: %s", err)
}

if err := util.WaitForIngressDefaultBackendRunning(t); err != nil {
t.Fatalf("waiting for default-http-backend to be up: %s", err)
}

ingressPath, _ := filepath.Abs("testdata/nginx-ing.yaml")
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", ingressPath}); err != nil {
t.Fatalf("creating nginx ingress resource: %s", err)
}

podPath, _ := filepath.Abs("testdata/nginx-pod-svc.yaml")
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {
t.Fatalf("creating nginx ingress resource: %s", err)
}

if err := util.WaitForNginxRunning(t); err != nil {
t.Fatalf("waiting for nginx to be up: %s", err)
}

expectedStr := "Welcome to nginx!"
runCmd := fmt.Sprintf("curl http://127.0.0.1:80 -H 'Host: nginx.example.com'")
sshCmdOutput, _ := minikubeRunner.SSH(runCmd)
if !strings.Contains(sshCmdOutput, expectedStr) {
t.Fatalf("ExpectedStr sshCmdOutput to be: %s. Output was: %s", expectedStr, sshCmdOutput)
}

defer kubectlRunner.RunCommand([]string{"delete", "-f", podPath})
defer kubectlRunner.RunCommand([]string{"delete", "-f", ingressPath})
minikubeRunner.RunCommand("addons disable ingress", true)
}

func testServicesList(t *testing.T) {
t.Parallel()
minikubeRunner := NewMinikubeRunner(t)
Expand Down
1 change: 1 addition & 0 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestFunctional(t *testing.T) {
if !strings.Contains(minikubeRunner.StartArgs, "--vm-driver=none") {
t.Run("EnvVars", testClusterEnv)
t.Run("SSH", testClusterSSH)
t.Run("IngressController", testIngressController)
// t.Run("Mounting", testMounting)
}
}
15 changes: 15 additions & 0 deletions test/integration/testdata/nginx-ing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
labels:
integration-test: ingress
spec:
rules:
- host: nginx.example.com
http:
paths:
- path: /
backend:
serviceName: nginx
servicePort: 80
31 changes: 31 additions & 0 deletions test/integration/testdata/nginx-pod-svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
name: nginx
namespace: default
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
labels:
run: nginx
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
sessionAffinity: None
type: ClusterIP
57 changes: 57 additions & 0 deletions test/integration/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,63 @@ func WaitForDashboardRunning(t *testing.T) error {
return nil
}

func WaitForIngressControllerRunning(t *testing.T) error {
client, err := commonutil.GetClient()
if err != nil {
return errors.Wrap(err, "getting kubernetes client")
}

if err := commonutil.WaitForRCToStabilize(client, "kube-system", "nginx-ingress-controller", time.Minute*10); err != nil {
return errors.Wrap(err, "waiting for ingress-controller RC to stabilize")
}

selector := labels.SelectorFromSet(labels.Set(map[string]string{"app": "nginx-ingress-controller"}))
if err := commonutil.WaitForPodsWithLabelRunning(client, "kube-system", selector); err != nil {
return errors.Wrap(err, "waiting for ingress-controller pods")
}

return nil
}

func WaitForIngressDefaultBackendRunning(t *testing.T) error {
client, err := commonutil.GetClient()
if err != nil {
return errors.Wrap(err, "getting kubernetes client")
}

if err := commonutil.WaitForRCToStabilize(client, "kube-system", "default-http-backend", time.Minute*10); err != nil {
return errors.Wrap(err, "waiting for default-http-backend RC to stabilize")
}

if err := commonutil.WaitForService(client, "kube-system", "default-http-backend", true, time.Millisecond*500, time.Minute*10); err != nil {
return errors.Wrap(err, "waiting for default-http-backend service to be up")
}

if err := commonutil.WaitForServiceEndpointsNum(client, "kube-system", "default-http-backend", 1, time.Second*3, time.Minute*10); err != nil {
return errors.Wrap(err, "waiting for one default-http-backend endpoint to be up")
}

return nil
}

func WaitForNginxRunning(t *testing.T) error {
client, err := commonutil.GetClient()

if err != nil {
return errors.Wrap(err, "getting kubernetes client")
}

selector := labels.SelectorFromSet(labels.Set(map[string]string{"run": "nginx"}))
if err := commonutil.WaitForPodsWithLabelRunning(client, "default", selector); err != nil {
return errors.Wrap(err, "waiting for nginx pods")
}

if err := commonutil.WaitForService(client, "default", "nginx", true, time.Millisecond*500, time.Minute*10); err != nil {
t.Errorf("Error waiting for nginx service to be up")
}
return nil
}

func Retry(t *testing.T, callback func() error, d time.Duration, attempts int) (err error) {
for i := 0; i < attempts; i++ {
err = callback()
Expand Down

0 comments on commit 8f55fb7

Please sign in to comment.