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 (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
commonutil "k8s.io/minikube/pkg/util"
|
|
|
|
"k8s.io/minikube/test/integration/util"
|
|
|
|
)
|
|
|
|
|
2016-12-05 22:49:52 +00:00
|
|
|
func testClusterDNS(t *testing.T) {
|
|
|
|
t.Parallel()
|
2016-06-02 22:51:30 +00:00
|
|
|
kubectlRunner := util.NewKubectlRunner(t)
|
|
|
|
podName := "busybox"
|
|
|
|
podPath, _ := filepath.Abs("testdata/busybox.yaml")
|
|
|
|
|
|
|
|
dnsTest := func() error {
|
|
|
|
podNamespace := kubectlRunner.CreateRandomNamespace()
|
|
|
|
defer kubectlRunner.DeleteNamespace(podNamespace)
|
|
|
|
|
|
|
|
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath, "--namespace=" + podNamespace}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer kubectlRunner.RunCommand([]string{"delete", "-f", podPath, "--namespace=" + podNamespace})
|
|
|
|
|
2016-06-29 21:52:10 +00:00
|
|
|
p := &api.Pod{}
|
2016-06-02 22:51:30 +00:00
|
|
|
for p.Status.Phase != "Running" {
|
2017-04-26 23:53:41 +00:00
|
|
|
var err error
|
|
|
|
p, err = kubectlRunner.GetPod(podName, podNamespace)
|
|
|
|
if err != nil {
|
|
|
|
return &commonutil.RetriableError{Err: err}
|
|
|
|
}
|
2016-06-02 22:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dnsByteArr, err := kubectlRunner.RunCommand([]string{"exec", podName, "--namespace=" + podNamespace,
|
|
|
|
"nslookup", "kubernetes.default"})
|
|
|
|
dnsOutput := string(dnsByteArr)
|
|
|
|
if err != nil {
|
2016-10-13 20:53:38 +00:00
|
|
|
return &commonutil.RetriableError{Err: err}
|
2016-06-02 22:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(dnsOutput, "10.0.0.1") || !strings.Contains(dnsOutput, "10.0.0.10") {
|
|
|
|
return fmt.Errorf("DNS lookup failed, could not find both 10.0.0.1 and 10.0.0.10. Output: %s", dnsOutput)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-05 22:49:52 +00:00
|
|
|
if err := commonutil.RetryAfter(40, dnsTest, 5*time.Second); err != nil {
|
2017-01-30 23:39:35 +00:00
|
|
|
t.Fatal("DNS lookup failed with error:", err)
|
2016-06-02 22:51:30 +00:00
|
|
|
}
|
|
|
|
}
|