rename func, add comments
parent
3ddb4e30b3
commit
260d22cd57
|
@ -134,7 +134,7 @@ func Start(starter Starter, apiServer bool) (*kubeconfig.Settings, error) {
|
|||
klog.Errorf("Unable to scale down deployment %q in namespace %q to 1 replica: %v", kconst.CoreDNSDeploymentName, meta.NamespaceSystem, err)
|
||||
}
|
||||
// inject {"host.minikube.internal": hostIP} record into CoreDNS
|
||||
if err := updateCoreDNS(starter.Runner, "host.minikube.internal", hostIP.String(), *starter.Cfg); err != nil {
|
||||
if err := addCoreDNSEntry(starter.Runner, "host.minikube.internal", hostIP.String(), *starter.Cfg); err != nil {
|
||||
klog.Errorf("Unable to inject {%q: %s} record into CoreDNS: %v", "host.minikube.internal", hostIP.String(), err)
|
||||
}
|
||||
} else {
|
||||
|
@ -676,13 +676,16 @@ func prepareNone() {
|
|||
}
|
||||
}
|
||||
|
||||
// updateCoreDNS adds host name and IP record to the DNS by updating CoreDNS's ConfigMap.
|
||||
// addCoreDNSEntry adds host name and IP record to the DNS by updating CoreDNS's ConfigMap.
|
||||
// ref: https://coredns.io/plugins/hosts/
|
||||
func updateCoreDNS(runner command.Runner, name, ip string, cc config.ClusterConfig) error {
|
||||
func addCoreDNSEntry(runner command.Runner, name, ip string, cc config.ClusterConfig) error {
|
||||
kubectl := kapi.KubectlBinaryPath(cc.KubernetesConfig.KubernetesVersion)
|
||||
kubecfg := path.Join(vmpath.GuestPersistentDir, "kubeconfig")
|
||||
// get current coredns configmap
|
||||
cur := fmt.Sprintf("sudo %s --kubeconfig=%s -n kube-system get configmap coredns -o yaml", kubectl, kubecfg)
|
||||
// inject hosts record into coredns configmap
|
||||
sed := fmt.Sprintf("sed '/^ forward . \\/etc\\/resolv.conf.*/i \\ hosts {\\n %s %s\\n fallthrough\\n }'", ip, name)
|
||||
// replace coredns configmap
|
||||
new := fmt.Sprintf("sudo %s --kubeconfig=%s replace -f -", kubectl, kubecfg)
|
||||
_, err := runner.RunCmd(exec.Command("/bin/bash", "-c", fmt.Sprintf("%s | %s | %s", cur, sed, new)))
|
||||
if err == nil {
|
||||
|
|
|
@ -485,21 +485,9 @@ func validateDeployAppToMultiNode(ctx context.Context, t *testing.T, profile str
|
|||
|
||||
// verify both pods could resolve "host.minikube.internal"
|
||||
for _, name := range podNames {
|
||||
// get node's default gateway via 'ip' - eg: "default via 192.168.49.1 dev eth0" => "192.168.49.1"
|
||||
out, err := Run(t, exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "ip -4 route show default | cut -d' ' -f3"))
|
||||
_, err = Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "exec", name, "--", "nslookup", "host.minikube.internal"))
|
||||
if err != nil {
|
||||
t.Errorf("Error getting default gateway for pod %s: %v", name, err)
|
||||
} else {
|
||||
dgw := strings.TrimSpace(out.Stdout.String())
|
||||
out, err = Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "exec", name, "--", "sh", "-c", "nslookup host.minikube.internal | awk 'NR==5' | cut -d' ' -f3"))
|
||||
if err != nil {
|
||||
t.Errorf("Pod %s could not resolve 'host.minikube.internal': %v", name, err)
|
||||
} else {
|
||||
hip := strings.TrimSpace(out.Stdout.String())
|
||||
if hip != dgw {
|
||||
t.Errorf("Pod %s resolved 'host.minikube.internal' to %q different from host's IP (%s)", name, hip, dgw)
|
||||
}
|
||||
}
|
||||
t.Errorf("Pod %s could not resolve 'host.minikube.internal': %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue