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 (
|
2018-11-08 00:40:45 +00:00
|
|
|
"bufio"
|
2016-06-02 17:49:40 +00:00
|
|
|
"fmt"
|
2018-10-03 22:06:30 +00:00
|
|
|
"io/ioutil"
|
2016-10-29 08:30:20 +00:00
|
|
|
"net"
|
2018-10-03 22:06:30 +00:00
|
|
|
"net/http"
|
2016-10-29 08:30:20 +00:00
|
|
|
"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 {
|
2018-09-28 23:18:22 +00:00
|
|
|
t.Fatalf("Could not get kubernetes client: %v", 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:40:45 +00:00
|
|
|
func readLineWithTimeout(b *bufio.Reader, timeout time.Duration) (string, error) {
|
|
|
|
s := make(chan string)
|
|
|
|
e := make(chan error)
|
|
|
|
go func() {
|
|
|
|
read, err := b.ReadString('\n')
|
|
|
|
if err != nil {
|
|
|
|
e <- err
|
|
|
|
} else {
|
|
|
|
s <- read
|
|
|
|
}
|
|
|
|
close(s)
|
|
|
|
close(e)
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case line := <-s:
|
|
|
|
return line, nil
|
|
|
|
case err := <-e:
|
|
|
|
return "", err
|
|
|
|
case <-time.After(timeout):
|
|
|
|
return "", fmt.Errorf("timeout after %s", timeout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2018-10-03 22:12:40 +00:00
|
|
|
cmd, out := minikubeRunner.RunDaemon("dashboard --url")
|
2018-10-03 22:06:30 +00:00
|
|
|
defer func() {
|
|
|
|
err := cmd.Process.Kill()
|
2018-06-12 19:29:43 +00:00
|
|
|
if err != nil {
|
2018-11-08 00:40:45 +00:00
|
|
|
t.Logf("Failed to kill dashboard command: %v", err)
|
2018-06-12 19:29:43 +00:00
|
|
|
}
|
2018-10-03 22:06:30 +00:00
|
|
|
}()
|
|
|
|
|
2018-11-08 00:40:45 +00:00
|
|
|
s, err := readLineWithTimeout(out, 180*time.Second)
|
2018-10-03 22:06:30 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to read url: %v", err)
|
2016-06-02 17:49:40 +00:00
|
|
|
}
|
2016-10-29 08:30:20 +00:00
|
|
|
|
2018-10-03 22:06:30 +00:00
|
|
|
u, err := url.Parse(strings.TrimSpace(s))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to parse %q: %v", s, err)
|
2016-10-29 08:30:20 +00:00
|
|
|
}
|
2018-06-12 19:29:43 +00:00
|
|
|
|
2016-10-29 08:30:20 +00:00
|
|
|
if u.Scheme != "http" {
|
2018-10-03 22:06:30 +00:00
|
|
|
t.Errorf("got Scheme %s, expected http", u.Scheme)
|
2016-10-29 08:30:20 +00:00
|
|
|
}
|
2018-10-03 22:06:30 +00:00
|
|
|
host, _, err := net.SplitHostPort(u.Host)
|
2016-10-29 08:30:20 +00:00
|
|
|
if err != nil {
|
2018-10-03 22:06:30 +00:00
|
|
|
t.Fatalf("failed SplitHostPort: %v", err)
|
2018-10-03 05:25:45 +00:00
|
|
|
}
|
|
|
|
if host != "127.0.0.1" {
|
2018-10-03 22:06:30 +00:00
|
|
|
t.Errorf("got host %s, expected 127.0.0.1", host)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.Get(u.String())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed get: %v", err)
|
|
|
|
}
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to read http response body: %v", err)
|
|
|
|
}
|
|
|
|
t.Errorf("%s returned status code %d, expected %d.\nbody:\n%s", u, resp.StatusCode, http.StatusOK, body)
|
2016-10-29 08:30:20 +00:00
|
|
|
}
|
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 {
|
2018-09-28 23:18:22 +00:00
|
|
|
t.Fatalf("waiting for ingress-controller to be up: %v", err)
|
2017-12-01 10:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := util.WaitForIngressDefaultBackendRunning(t); err != nil {
|
2018-09-28 23:18:22 +00:00
|
|
|
t.Fatalf("waiting for default-http-backend to be up: %v", err)
|
2017-12-01 10:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ingressPath, _ := filepath.Abs("testdata/nginx-ing.yaml")
|
|
|
|
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", ingressPath}); err != nil {
|
2018-09-28 23:18:22 +00:00
|
|
|
t.Fatalf("creating nginx ingress resource: %v", err)
|
2017-12-01 10:40:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 19:28:47 +00:00
|
|
|
podPath, _ := filepath.Abs("testdata/nginx-pod-svc.yaml")
|
|
|
|
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {
|
2018-09-28 23:18:22 +00:00
|
|
|
t.Fatalf("creating nginx ingress resource: %v", err)
|
2017-12-01 10:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := util.WaitForNginxRunning(t); err != nil {
|
2018-09-28 23:18:22 +00:00
|
|
|
t.Fatalf("waiting for nginx to be up: %v", err)
|
2017-12-01 10:40:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 18:19:50 +00:00
|
|
|
checkIngress := func() error {
|
|
|
|
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) {
|
|
|
|
return fmt.Errorf("ExpectedStr sshCmdOutput to be: %s. Output was: %s", expectedStr, sshCmdOutput)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := util.Retry(t, checkIngress, 3*time.Second, 5); err != nil {
|
|
|
|
t.Fatalf(err.Error())
|
2017-12-01 10:40:30 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 18:57:48 +00:00
|
|
|
defer func() {
|
|
|
|
for _, p := range []string{podPath, ingressPath} {
|
|
|
|
if out, err := kubectlRunner.RunCommand([]string{"delete", "-f", p}); err != nil {
|
|
|
|
t.Logf("delete -f %s failed: %v\noutput: %s\n", p, err, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2017-12-01 10:40:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2018-12-07 23:27:22 +00:00
|
|
|
|
|
|
|
func testGvisor(t *testing.T) {
|
|
|
|
minikubeRunner := NewMinikubeRunner(t)
|
|
|
|
kubectlRunner := util.NewKubectlRunner(t)
|
|
|
|
minikubeRunner.RunCommand("addons enable gvisor", true)
|
|
|
|
|
|
|
|
t.Log("waiting for gvisor controller to come up")
|
|
|
|
if err := util.WaitForGvisorControllerRunning(t); err != nil {
|
|
|
|
t.Fatalf("waiting for gvisor controller to be up: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
untrustedPath, _ := filepath.Abs("testdata/nginx-untrusted.yaml")
|
|
|
|
t.Log("creating pod with untrusted workload annotation")
|
|
|
|
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", untrustedPath}); err != nil {
|
|
|
|
t.Fatalf("creating untrusted nginx resource: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("making sure untrusted workload is Running")
|
|
|
|
if err := util.WaitForUntrustedNginxRunning(); err != nil {
|
|
|
|
t.Fatalf("waiting for nginx to be up: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("disabling gvisor addon")
|
|
|
|
minikubeRunner.RunCommand("addons disable gvisor", true)
|
|
|
|
t.Log("waiting for gvisor controller pod to be deleted")
|
|
|
|
if err := util.WaitForGvisorControllerDeleted(); err != nil {
|
|
|
|
t.Fatalf("waiting for gvisor controller to be deleted: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("recreating untrusted workload pod")
|
|
|
|
if _, err := kubectlRunner.RunCommand([]string{"replace", "-f", untrustedPath, "--force"}); err != nil {
|
|
|
|
t.Fatalf("replacing untrusted nginx resource: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("waiting for FailedCreatePodSandBox event")
|
|
|
|
if err := util.WaitForFailedCreatePodSandBoxEvent(); err != nil {
|
|
|
|
t.Fatalf("waiting for FailedCreatePodSandBox event: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := kubectlRunner.RunCommand([]string{"delete", "-f", untrustedPath}); err != nil {
|
|
|
|
t.Logf("error deleting untrusted nginx resource: %v", err)
|
|
|
|
}
|
|
|
|
}
|