2016-06-02 22:51:30 +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 (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2017-09-08 22:09:52 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
pkgutil "k8s.io/minikube/pkg/util"
|
|
|
|
|
2016-06-02 22:51:30 +00:00
|
|
|
"k8s.io/minikube/test/integration/util"
|
|
|
|
)
|
|
|
|
|
2016-12-05 22:49:52 +00:00
|
|
|
func testClusterDNS(t *testing.T) {
|
|
|
|
t.Parallel()
|
2017-08-23 18:33:00 +00:00
|
|
|
if err := util.WaitForDNSRunning(t); err != nil {
|
|
|
|
t.Fatalf("Waiting for DNS to be running: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-06-02 22:51:30 +00:00
|
|
|
kubectlRunner := util.NewKubectlRunner(t)
|
2017-08-23 15:52:15 +00:00
|
|
|
podPath := filepath.Join(*testdataDir, "busybox.yaml")
|
2017-09-08 22:09:52 +00:00
|
|
|
|
|
|
|
client, err := pkgutil.GetClient()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error getting kubernetes client %s", err)
|
|
|
|
}
|
2016-06-02 22:51:30 +00:00
|
|
|
|
2017-08-23 18:33:00 +00:00
|
|
|
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {
|
|
|
|
t.Fatalf("creating busybox pod: %s", err)
|
2017-04-28 17:38:55 +00:00
|
|
|
}
|
2016-06-02 22:51:30 +00:00
|
|
|
|
2017-08-23 18:33:00 +00:00
|
|
|
if err := util.WaitForBusyboxRunning(t, "default"); err != nil {
|
|
|
|
t.Fatalf("Waiting for busybox pod to be up: %s", err)
|
2017-04-28 17:38:55 +00:00
|
|
|
}
|
2017-09-08 22:09:52 +00:00
|
|
|
listOpts := metav1.ListOptions{LabelSelector: "integration-test=busybox"}
|
|
|
|
pods, err := client.CoreV1().Pods("default").List(listOpts)
|
|
|
|
if len(pods.Items) == 0 {
|
|
|
|
t.Fatal("Expected a busybox pod to be running")
|
|
|
|
}
|
|
|
|
|
|
|
|
podName := pods.Items[0].Name
|
|
|
|
defer kubectlRunner.RunCommand([]string{"delete", "po", podName})
|
2017-04-28 17:38:55 +00:00
|
|
|
|
2017-08-23 18:33:00 +00:00
|
|
|
dnsByteArr, err := kubectlRunner.RunCommand([]string{"exec", podName,
|
|
|
|
"nslookup", "kubernetes"})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("running nslookup in pod:%s", err)
|
2016-06-02 22:51:30 +00:00
|
|
|
}
|
2017-08-23 18:33:00 +00:00
|
|
|
dnsOutput := string(dnsByteArr)
|
2017-10-20 15:37:21 +00:00
|
|
|
if !strings.Contains(dnsOutput, "10.96.0.1") || !strings.Contains(dnsOutput, "10.0.0.10") {
|
|
|
|
t.Errorf("DNS lookup failed, could not find both 10.06.0.1 and 10.96.0.10. Output: %s", dnsOutput)
|
2016-06-02 22:51:30 +00:00
|
|
|
}
|
|
|
|
}
|