mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Clean up redundant DNS related kubelet codes
Signed-off-by: Zihong Zheng <zihongz@google.com>
This commit is contained in:
		@@ -46,7 +46,7 @@ type HandlerRunner interface {
 | 
				
			|||||||
// RuntimeHelper wraps kubelet to make container runtime
 | 
					// RuntimeHelper wraps kubelet to make container runtime
 | 
				
			||||||
// able to get necessary informations like the RunContainerOptions, DNS settings, Host IP.
 | 
					// able to get necessary informations like the RunContainerOptions, DNS settings, Host IP.
 | 
				
			||||||
type RuntimeHelper interface {
 | 
					type RuntimeHelper interface {
 | 
				
			||||||
	GenerateRunContainerOptions(pod *v1.Pod, container *v1.Container, podIP string) (contOpts *RunContainerOptions, useClusterFirstPolicy bool, err error)
 | 
						GenerateRunContainerOptions(pod *v1.Pod, container *v1.Container, podIP string) (contOpts *RunContainerOptions, err error)
 | 
				
			||||||
	GetClusterDNS(pod *v1.Pod) (dnsServers []string, dnsSearches []string, useClusterFirstPolicy bool, err error)
 | 
						GetClusterDNS(pod *v1.Pod) (dnsServers []string, dnsSearches []string, useClusterFirstPolicy bool, err error)
 | 
				
			||||||
	// GetPodCgroupParent returns the CgroupName identifer, and its literal cgroupfs form on the host
 | 
						// GetPodCgroupParent returns the CgroupName identifer, and its literal cgroupfs form on the host
 | 
				
			||||||
	// of a pod.
 | 
						// of a pod.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -428,10 +428,6 @@ type RunContainerOptions struct {
 | 
				
			|||||||
	// this directory will be used to create and mount the log file to
 | 
						// this directory will be used to create and mount the log file to
 | 
				
			||||||
	// container.TerminationMessagePath
 | 
						// container.TerminationMessagePath
 | 
				
			||||||
	PodContainerDir string
 | 
						PodContainerDir string
 | 
				
			||||||
	// The list of DNS servers for the container to use.
 | 
					 | 
				
			||||||
	DNS []string
 | 
					 | 
				
			||||||
	// The list of DNS search domains.
 | 
					 | 
				
			||||||
	DNSSearch []string
 | 
					 | 
				
			||||||
	// The parent cgroup to pass to Docker
 | 
						// The parent cgroup to pass to Docker
 | 
				
			||||||
	CgroupParent string
 | 
						CgroupParent string
 | 
				
			||||||
	// The type of container rootfs
 | 
						// The type of container rootfs
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,12 +32,12 @@ type FakeRuntimeHelper struct {
 | 
				
			|||||||
	Err             error
 | 
						Err             error
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (f *FakeRuntimeHelper) GenerateRunContainerOptions(pod *v1.Pod, container *v1.Container, podIP string) (*kubecontainer.RunContainerOptions, bool, error) {
 | 
					func (f *FakeRuntimeHelper) GenerateRunContainerOptions(pod *v1.Pod, container *v1.Container, podIP string) (*kubecontainer.RunContainerOptions, error) {
 | 
				
			||||||
	var opts kubecontainer.RunContainerOptions
 | 
						var opts kubecontainer.RunContainerOptions
 | 
				
			||||||
	if len(container.TerminationMessagePath) != 0 {
 | 
						if len(container.TerminationMessagePath) != 0 {
 | 
				
			||||||
		opts.PodContainerDir = f.PodContainerDir
 | 
							opts.PodContainerDir = f.PodContainerDir
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return &opts, false, nil
 | 
						return &opts, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (f *FakeRuntimeHelper) GetPodCgroupParent(pod *v1.Pod) string {
 | 
					func (f *FakeRuntimeHelper) GetPodCgroupParent(pod *v1.Pod) string {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -381,18 +381,17 @@ func (kl *Kubelet) GetPodCgroupParent(pod *v1.Pod) string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// GenerateRunContainerOptions generates the RunContainerOptions, which can be used by
 | 
					// GenerateRunContainerOptions generates the RunContainerOptions, which can be used by
 | 
				
			||||||
// the container runtime to set parameters for launching a container.
 | 
					// the container runtime to set parameters for launching a container.
 | 
				
			||||||
func (kl *Kubelet) GenerateRunContainerOptions(pod *v1.Pod, container *v1.Container, podIP string) (*kubecontainer.RunContainerOptions, bool, error) {
 | 
					func (kl *Kubelet) GenerateRunContainerOptions(pod *v1.Pod, container *v1.Container, podIP string) (*kubecontainer.RunContainerOptions, error) {
 | 
				
			||||||
	useClusterFirstPolicy := false
 | 
					 | 
				
			||||||
	opts, err := kl.containerManager.GetResources(pod, container)
 | 
						opts, err := kl.containerManager.GetResources(pod, container)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, false, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cgroupParent := kl.GetPodCgroupParent(pod)
 | 
						cgroupParent := kl.GetPodCgroupParent(pod)
 | 
				
			||||||
	opts.CgroupParent = cgroupParent
 | 
						opts.CgroupParent = cgroupParent
 | 
				
			||||||
	hostname, hostDomainName, err := kl.GeneratePodHostNameAndDomain(pod)
 | 
						hostname, hostDomainName, err := kl.GeneratePodHostNameAndDomain(pod)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, false, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	opts.Hostname = hostname
 | 
						opts.Hostname = hostname
 | 
				
			||||||
	podName := volumehelper.GetUniquePodName(pod)
 | 
						podName := volumehelper.GetUniquePodName(pod)
 | 
				
			||||||
@@ -402,19 +401,19 @@ func (kl *Kubelet) GenerateRunContainerOptions(pod *v1.Pod, container *v1.Contai
 | 
				
			|||||||
	// TODO(random-liu): Move following convert functions into pkg/kubelet/container
 | 
						// TODO(random-liu): Move following convert functions into pkg/kubelet/container
 | 
				
			||||||
	devices, err := kl.makeDevices(pod, container)
 | 
						devices, err := kl.makeDevices(pod, container)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, false, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	opts.Devices = append(opts.Devices, devices...)
 | 
						opts.Devices = append(opts.Devices, devices...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mounts, err := makeMounts(pod, kl.getPodDir(pod.UID), container, hostname, hostDomainName, podIP, volumes)
 | 
						mounts, err := makeMounts(pod, kl.getPodDir(pod.UID), container, hostname, hostDomainName, podIP, volumes)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, false, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	opts.Mounts = append(opts.Mounts, mounts...)
 | 
						opts.Mounts = append(opts.Mounts, mounts...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	envs, err := kl.makeEnvironmentVariables(pod, container, podIP)
 | 
						envs, err := kl.makeEnvironmentVariables(pod, container, podIP)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, false, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	opts.Envs = append(opts.Envs, envs...)
 | 
						opts.Envs = append(opts.Envs, envs...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -429,17 +428,12 @@ func (kl *Kubelet) GenerateRunContainerOptions(pod *v1.Pod, container *v1.Contai
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	opts.DNS, opts.DNSSearch, useClusterFirstPolicy, err = kl.GetClusterDNS(pod)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, false, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// only do this check if the experimental behavior is enabled, otherwise allow it to default to false
 | 
						// only do this check if the experimental behavior is enabled, otherwise allow it to default to false
 | 
				
			||||||
	if kl.experimentalHostUserNamespaceDefaulting {
 | 
						if kl.experimentalHostUserNamespaceDefaulting {
 | 
				
			||||||
		opts.EnableHostUserNamespace = kl.enableHostUserNamespace(pod)
 | 
							opts.EnableHostUserNamespace = kl.enableHostUserNamespace(pod)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return opts, useClusterFirstPolicy, nil
 | 
						return opts, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var masterServices = sets.NewString("kubernetes")
 | 
					var masterServices = sets.NewString("kubernetes")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,7 +21,6 @@ import (
 | 
				
			|||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
	"net"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
@@ -591,90 +590,6 @@ func TestRunInContainer(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGenerateRunContainerOptions_DNSConfigurationParams(t *testing.T) {
 | 
					 | 
				
			||||||
	testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
 | 
					 | 
				
			||||||
	defer testKubelet.Cleanup()
 | 
					 | 
				
			||||||
	kubelet := testKubelet.kubelet
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	clusterNS := "203.0.113.1"
 | 
					 | 
				
			||||||
	kubelet.clusterDomain = "kubernetes.io"
 | 
					 | 
				
			||||||
	kubelet.clusterDNS = []net.IP{net.ParseIP(clusterNS)}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pods := newTestPods(4)
 | 
					 | 
				
			||||||
	pods[0].Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
 | 
					 | 
				
			||||||
	pods[1].Spec.DNSPolicy = v1.DNSClusterFirst
 | 
					 | 
				
			||||||
	pods[2].Spec.DNSPolicy = v1.DNSClusterFirst
 | 
					 | 
				
			||||||
	pods[2].Spec.HostNetwork = false
 | 
					 | 
				
			||||||
	pods[3].Spec.DNSPolicy = v1.DNSDefault
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	options := make([]*kubecontainer.RunContainerOptions, 4)
 | 
					 | 
				
			||||||
	for i, pod := range pods {
 | 
					 | 
				
			||||||
		var err error
 | 
					 | 
				
			||||||
		options[i], _, err = kubelet.GenerateRunContainerOptions(pod, &v1.Container{}, "")
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			t.Fatalf("failed to generate container options: %v", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[0].DNS) != 1 || options[0].DNS[0] != clusterNS {
 | 
					 | 
				
			||||||
		t.Errorf("expected nameserver %s, got %+v", clusterNS, options[0].DNS)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[0].DNSSearch) == 0 || options[0].DNSSearch[0] != ".svc."+kubelet.clusterDomain {
 | 
					 | 
				
			||||||
		t.Errorf("expected search %s, got %+v", ".svc."+kubelet.clusterDomain, options[0].DNSSearch)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[1].DNS) != 1 || options[1].DNS[0] != "127.0.0.1" {
 | 
					 | 
				
			||||||
		t.Errorf("expected nameserver 127.0.0.1, got %+v", options[1].DNS)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[1].DNSSearch) != 1 || options[1].DNSSearch[0] != "." {
 | 
					 | 
				
			||||||
		t.Errorf("expected search \".\", got %+v", options[1].DNSSearch)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[2].DNS) != 1 || options[2].DNS[0] != clusterNS {
 | 
					 | 
				
			||||||
		t.Errorf("expected nameserver %s, got %+v", clusterNS, options[2].DNS)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[2].DNSSearch) == 0 || options[2].DNSSearch[0] != ".svc."+kubelet.clusterDomain {
 | 
					 | 
				
			||||||
		t.Errorf("expected search %s, got %+v", ".svc."+kubelet.clusterDomain, options[2].DNSSearch)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[3].DNS) != 1 || options[3].DNS[0] != "127.0.0.1" {
 | 
					 | 
				
			||||||
		t.Errorf("expected nameserver 127.0.0.1, got %+v", options[3].DNS)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[3].DNSSearch) != 1 || options[3].DNSSearch[0] != "." {
 | 
					 | 
				
			||||||
		t.Errorf("expected search \".\", got %+v", options[3].DNSSearch)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	kubelet.resolverConfig = "/etc/resolv.conf"
 | 
					 | 
				
			||||||
	for i, pod := range pods {
 | 
					 | 
				
			||||||
		var err error
 | 
					 | 
				
			||||||
		options[i], _, err = kubelet.GenerateRunContainerOptions(pod, &v1.Container{}, "")
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			t.Fatalf("failed to generate container options: %v", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	t.Logf("nameservers %+v", options[1].DNS)
 | 
					 | 
				
			||||||
	if len(options[0].DNS) != 1 {
 | 
					 | 
				
			||||||
		t.Errorf("expected cluster nameserver only, got %+v", options[0].DNS)
 | 
					 | 
				
			||||||
	} else if options[0].DNS[0] != clusterNS {
 | 
					 | 
				
			||||||
		t.Errorf("expected nameserver %s, got %v", clusterNS, options[0].DNS[0])
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	expLength := len(options[1].DNSSearch) + 3
 | 
					 | 
				
			||||||
	if expLength > 6 {
 | 
					 | 
				
			||||||
		expLength = 6
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[0].DNSSearch) != expLength {
 | 
					 | 
				
			||||||
		t.Errorf("expected prepend of cluster domain, got %+v", options[0].DNSSearch)
 | 
					 | 
				
			||||||
	} else if options[0].DNSSearch[0] != ".svc."+kubelet.clusterDomain {
 | 
					 | 
				
			||||||
		t.Errorf("expected domain %s, got %s", ".svc."+kubelet.clusterDomain, options[0].DNSSearch)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[2].DNS) != 1 {
 | 
					 | 
				
			||||||
		t.Errorf("expected cluster nameserver only, got %+v", options[2].DNS)
 | 
					 | 
				
			||||||
	} else if options[2].DNS[0] != clusterNS {
 | 
					 | 
				
			||||||
		t.Errorf("expected nameserver %s, got %v", clusterNS, options[2].DNS[0])
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(options[2].DNSSearch) != expLength {
 | 
					 | 
				
			||||||
		t.Errorf("expected prepend of cluster domain, got %+v", options[2].DNSSearch)
 | 
					 | 
				
			||||||
	} else if options[2].DNSSearch[0] != ".svc."+kubelet.clusterDomain {
 | 
					 | 
				
			||||||
		t.Errorf("expected domain %s, got %s", ".svc."+kubelet.clusterDomain, options[0].DNSSearch)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type testServiceLister struct {
 | 
					type testServiceLister struct {
 | 
				
			||||||
	services []*v1.Service
 | 
						services []*v1.Service
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ package kubelet
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
@@ -2170,3 +2171,90 @@ type podsByUID []*v1.Pod
 | 
				
			|||||||
func (p podsByUID) Len() int           { return len(p) }
 | 
					func (p podsByUID) Len() int           { return len(p) }
 | 
				
			||||||
func (p podsByUID) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
 | 
					func (p podsByUID) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
 | 
				
			||||||
func (p podsByUID) Less(i, j int) bool { return p[i].UID < p[j].UID }
 | 
					func (p podsByUID) Less(i, j int) bool { return p[i].UID < p[j].UID }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGetClusterDNS(t *testing.T) {
 | 
				
			||||||
 | 
						testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
 | 
				
			||||||
 | 
						defer testKubelet.Cleanup()
 | 
				
			||||||
 | 
						kubelet := testKubelet.kubelet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						clusterNS := "203.0.113.1"
 | 
				
			||||||
 | 
						kubelet.clusterDomain = "kubernetes.io"
 | 
				
			||||||
 | 
						kubelet.clusterDNS = []net.IP{net.ParseIP(clusterNS)}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pods := newTestPods(4)
 | 
				
			||||||
 | 
						pods[0].Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
 | 
				
			||||||
 | 
						pods[1].Spec.DNSPolicy = v1.DNSClusterFirst
 | 
				
			||||||
 | 
						pods[2].Spec.DNSPolicy = v1.DNSClusterFirst
 | 
				
			||||||
 | 
						pods[2].Spec.HostNetwork = false
 | 
				
			||||||
 | 
						pods[3].Spec.DNSPolicy = v1.DNSDefault
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						options := make([]struct {
 | 
				
			||||||
 | 
							DNS       []string
 | 
				
			||||||
 | 
							DNSSearch []string
 | 
				
			||||||
 | 
						}, 4)
 | 
				
			||||||
 | 
						for i, pod := range pods {
 | 
				
			||||||
 | 
							var err error
 | 
				
			||||||
 | 
							options[i].DNS, options[i].DNSSearch, _, err = kubelet.GetClusterDNS(pod)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Fatalf("failed to generate container options: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[0].DNS) != 1 || options[0].DNS[0] != clusterNS {
 | 
				
			||||||
 | 
							t.Errorf("expected nameserver %s, got %+v", clusterNS, options[0].DNS)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[0].DNSSearch) == 0 || options[0].DNSSearch[0] != ".svc."+kubelet.clusterDomain {
 | 
				
			||||||
 | 
							t.Errorf("expected search %s, got %+v", ".svc."+kubelet.clusterDomain, options[0].DNSSearch)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[1].DNS) != 1 || options[1].DNS[0] != "127.0.0.1" {
 | 
				
			||||||
 | 
							t.Errorf("expected nameserver 127.0.0.1, got %+v", options[1].DNS)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[1].DNSSearch) != 1 || options[1].DNSSearch[0] != "." {
 | 
				
			||||||
 | 
							t.Errorf("expected search \".\", got %+v", options[1].DNSSearch)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[2].DNS) != 1 || options[2].DNS[0] != clusterNS {
 | 
				
			||||||
 | 
							t.Errorf("expected nameserver %s, got %+v", clusterNS, options[2].DNS)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[2].DNSSearch) == 0 || options[2].DNSSearch[0] != ".svc."+kubelet.clusterDomain {
 | 
				
			||||||
 | 
							t.Errorf("expected search %s, got %+v", ".svc."+kubelet.clusterDomain, options[2].DNSSearch)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[3].DNS) != 1 || options[3].DNS[0] != "127.0.0.1" {
 | 
				
			||||||
 | 
							t.Errorf("expected nameserver 127.0.0.1, got %+v", options[3].DNS)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[3].DNSSearch) != 1 || options[3].DNSSearch[0] != "." {
 | 
				
			||||||
 | 
							t.Errorf("expected search \".\", got %+v", options[3].DNSSearch)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						kubelet.resolverConfig = "/etc/resolv.conf"
 | 
				
			||||||
 | 
						for i, pod := range pods {
 | 
				
			||||||
 | 
							var err error
 | 
				
			||||||
 | 
							options[i].DNS, options[i].DNSSearch, _, err = kubelet.GetClusterDNS(pod)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Fatalf("failed to generate container options: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						t.Logf("nameservers %+v", options[1].DNS)
 | 
				
			||||||
 | 
						if len(options[0].DNS) != 1 {
 | 
				
			||||||
 | 
							t.Errorf("expected cluster nameserver only, got %+v", options[0].DNS)
 | 
				
			||||||
 | 
						} else if options[0].DNS[0] != clusterNS {
 | 
				
			||||||
 | 
							t.Errorf("expected nameserver %s, got %v", clusterNS, options[0].DNS[0])
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						expLength := len(options[1].DNSSearch) + 3
 | 
				
			||||||
 | 
						if expLength > 6 {
 | 
				
			||||||
 | 
							expLength = 6
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[0].DNSSearch) != expLength {
 | 
				
			||||||
 | 
							t.Errorf("expected prepend of cluster domain, got %+v", options[0].DNSSearch)
 | 
				
			||||||
 | 
						} else if options[0].DNSSearch[0] != ".svc."+kubelet.clusterDomain {
 | 
				
			||||||
 | 
							t.Errorf("expected domain %s, got %s", ".svc."+kubelet.clusterDomain, options[0].DNSSearch)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[2].DNS) != 1 {
 | 
				
			||||||
 | 
							t.Errorf("expected cluster nameserver only, got %+v", options[2].DNS)
 | 
				
			||||||
 | 
						} else if options[2].DNS[0] != clusterNS {
 | 
				
			||||||
 | 
							t.Errorf("expected nameserver %s, got %v", clusterNS, options[2].DNS[0])
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(options[2].DNSSearch) != expLength {
 | 
				
			||||||
 | 
							t.Errorf("expected prepend of cluster domain, got %+v", options[2].DNSSearch)
 | 
				
			||||||
 | 
						} else if options[2].DNSSearch[0] != ".svc."+kubelet.clusterDomain {
 | 
				
			||||||
 | 
							t.Errorf("expected domain %s, got %s", ".svc."+kubelet.clusterDomain, options[0].DNSSearch)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -174,7 +174,7 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// generateContainerConfig generates container config for kubelet runtime v1.
 | 
					// generateContainerConfig generates container config for kubelet runtime v1.
 | 
				
			||||||
func (m *kubeGenericRuntimeManager) generateContainerConfig(container *v1.Container, pod *v1.Pod, restartCount int, podIP, imageRef string) (*runtimeapi.ContainerConfig, error) {
 | 
					func (m *kubeGenericRuntimeManager) generateContainerConfig(container *v1.Container, pod *v1.Pod, restartCount int, podIP, imageRef string) (*runtimeapi.ContainerConfig, error) {
 | 
				
			||||||
	opts, _, err := m.runtimeHelper.GenerateRunContainerOptions(pod, container, podIP)
 | 
						opts, err := m.runtimeHelper.GenerateRunContainerOptions(pod, container, podIP)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -207,7 +207,7 @@ func makeExpectedConfig(m *kubeGenericRuntimeManager, pod *v1.Pod, containerInde
 | 
				
			|||||||
	container := &pod.Spec.Containers[containerIndex]
 | 
						container := &pod.Spec.Containers[containerIndex]
 | 
				
			||||||
	podIP := ""
 | 
						podIP := ""
 | 
				
			||||||
	restartCount := 0
 | 
						restartCount := 0
 | 
				
			||||||
	opts, _, _ := m.runtimeHelper.GenerateRunContainerOptions(pod, container, podIP)
 | 
						opts, _ := m.runtimeHelper.GenerateRunContainerOptions(pod, container, podIP)
 | 
				
			||||||
	containerLogsPath := buildContainerLogsPath(container.Name, restartCount)
 | 
						containerLogsPath := buildContainerLogsPath(container.Name, restartCount)
 | 
				
			||||||
	restartCountUint32 := uint32(restartCount)
 | 
						restartCountUint32 := uint32(restartCount)
 | 
				
			||||||
	envs := make([]*runtimeapi.KeyValue, len(opts.Envs))
 | 
						envs := make([]*runtimeapi.KeyValue, len(opts.Envs))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -842,7 +842,7 @@ func (r *Runtime) newAppcRuntimeApp(pod *v1.Pod, podIP string, c v1.Container, r
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO: determine how this should be handled for rkt
 | 
						// TODO: determine how this should be handled for rkt
 | 
				
			||||||
	opts, _, err := r.runtimeHelper.GenerateRunContainerOptions(pod, &c, podIP)
 | 
						opts, err := r.runtimeHelper.GenerateRunContainerOptions(pod, &c, podIP)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user