2016-06-02 17:49:40 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 2016 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 integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-10-29 08:30:20 +00:00
|
|
|
"net"
|
|
|
|
"net/url"
|
2017-12-01 10:40:30 +00:00
|
|
|
"path/filepath"
|
2016-07-07 21:32:26 +00:00
|
|
|
"strings"
|
2016-06-02 17:49:40 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2017-08-23 18:33:00 +00:00
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
2017-09-08 02:49:42 +00:00
|
|
|
pkgutil "k8s.io/minikube/pkg/util"
|
2016-06-02 17:49:40 +00:00
|
|
|
"k8s.io/minikube/test/integration/util"
|
|
|
|
)
|
|
|
|
|
2016-12-05 22:49:52 +00:00
|
|
|
func testAddons(t *testing.T) {
|
|
|
|
t.Parallel()
|
2017-09-08 02:49:42 +00:00
|
|
|
client, err := pkgutil.GetClient()
|
2017-08-23 18:33:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not get kubernetes client: %s", err)
|
2016-06-02 17:49:40 +00:00
|
|
|
}
|
2017-08-23 18:33:00 +00:00
|
|
|
selector := labels.SelectorFromSet(labels.Set(map[string]string{"component": "kube-addon-manager"}))
|
2017-09-08 02:49:42 +00:00
|
|
|
if err := pkgutil.WaitForPodsWithLabelRunning(client, "kube-system", selector); err != nil {
|
2017-08-23 18:33:00 +00:00
|
|
|
t.Errorf("Error waiting for addon manager to be up")
|
2016-06-02 17:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 22:49:52 +00:00
|
|
|
func testDashboard(t *testing.T) {
|
|
|
|
t.Parallel()
|
2017-09-08 22:09:52 +00:00
|
|
|
minikubeRunner := NewMinikubeRunner(t)
|
2016-06-02 17:49:40 +00:00
|
|
|
|
2017-08-23 18:33:00 +00:00
|
|
|
if err := util.WaitForDashboardRunning(t); err != nil {
|
|
|
|
t.Fatalf("waiting for dashboard to be up: %s", err)
|
2016-06-02 17:49:40 +00:00
|
|
|
}
|
2016-10-29 08:30:20 +00:00
|
|
|
|
|
|
|
dashboardURL := minikubeRunner.RunCommand("dashboard --url", true)
|
|
|
|
u, err := url.Parse(strings.TrimSpace(dashboardURL))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to parse dashboard URL %s: %v", dashboardURL, err)
|
|
|
|
}
|
|
|
|
if u.Scheme != "http" {
|
|
|
|
t.Fatalf("wrong scheme in dashboard URL, expected http, actual %s", u.Scheme)
|
|
|
|
}
|
|
|
|
_, port, err := net.SplitHostPort(u.Host)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to split dashboard host %s: %v", u.Host, err)
|
|
|
|
}
|
|
|
|
if port != "30000" {
|
|
|
|
t.Fatalf("Dashboard is exposed on wrong port, expected 30000, actual %s", port)
|
|
|
|
}
|
2016-06-02 17:49:40 +00:00
|
|
|
}
|
2016-12-03 21:02:06 +00:00
|
|
|
|
2017-12-01 10:40:30 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
podName := "nginx"
|
|
|
|
args := []string{"run", podName, "--image=nginx:alpine", "--port=80", "--restart=Never"}
|
|
|
|
if _, err := kubectlRunner.RunCommand(args); err != nil {
|
|
|
|
t.Fatalf("failed to create nginx pods: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
args = []string{"expose", "pod", podName, "--target-port=80"}
|
|
|
|
if _, err := kubectlRunner.RunCommand(args); err != nil {
|
|
|
|
t.Fatalf("failed to create nginx service: %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", "pod", podName})
|
|
|
|
defer kubectlRunner.RunCommand([]string{"delete", "svc", podName})
|
|
|
|
defer kubectlRunner.RunCommand([]string{"delete", "-f", ingressPath})
|
|
|
|
minikubeRunner.RunCommand("addons disable ingress", true)
|
|
|
|
}
|
|
|
|
|
2016-12-05 22:49:52 +00:00
|
|
|
func testServicesList(t *testing.T) {
|
|
|
|
t.Parallel()
|
2017-09-08 22:09:52 +00:00
|
|
|
minikubeRunner := NewMinikubeRunner(t)
|
2016-12-03 21:02:06 +00:00
|
|
|
|
2016-12-05 22:49:52 +00:00
|
|
|
checkServices := func() error {
|
|
|
|
output := minikubeRunner.RunCommand("service list", false)
|
|
|
|
if !strings.Contains(output, "kubernetes") {
|
2017-08-23 15:51:14 +00:00
|
|
|
return fmt.Errorf("Error, kubernetes service missing from output %s", output)
|
2016-12-03 21:02:06 +00:00
|
|
|
}
|
2016-12-05 22:49:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-08-23 15:51:14 +00:00
|
|
|
if err := util.Retry(t, checkServices, 2*time.Second, 5); err != nil {
|
2016-12-05 22:49:52 +00:00
|
|
|
t.Fatalf(err.Error())
|
2016-12-03 21:02:06 +00:00
|
|
|
}
|
|
|
|
}
|