Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c1a959c6
Commit
c1a959c6
authored
Nov 04, 2017
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up redundant DNS related kubelet codes
Signed-off-by:
Zihong Zheng
<
zihongz@google.com
>
parent
2ecb3680
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
101 additions
and
108 deletions
+101
-108
helpers.go
pkg/kubelet/container/helpers.go
+1
-1
runtime.go
pkg/kubelet/container/runtime.go
+0
-4
fake_runtime_helper.go
pkg/kubelet/container/testing/fake_runtime_helper.go
+2
-2
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+7
-13
kubelet_pods_test.go
pkg/kubelet/kubelet_pods_test.go
+0
-85
kubelet_test.go
pkg/kubelet/kubelet_test.go
+88
-0
kuberuntime_container.go
pkg/kubelet/kuberuntime/kuberuntime_container.go
+1
-1
kuberuntime_container_test.go
pkg/kubelet/kuberuntime/kuberuntime_container_test.go
+1
-1
rkt.go
pkg/kubelet/rkt/rkt.go
+1
-1
No files found.
pkg/kubelet/container/helpers.go
View file @
c1a959c6
...
...
@@ -46,7 +46,7 @@ type HandlerRunner interface {
// RuntimeHelper wraps kubelet to make container runtime
// able to get necessary informations like the RunContainerOptions, DNS settings, Host IP.
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
)
// GetPodCgroupParent returns the CgroupName identifer, and its literal cgroupfs form on the host
// of a pod.
...
...
pkg/kubelet/container/runtime.go
View file @
c1a959c6
...
...
@@ -428,10 +428,6 @@ type RunContainerOptions struct {
// this directory will be used to create and mount the log file to
// container.TerminationMessagePath
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
CgroupParent
string
// The type of container rootfs
...
...
pkg/kubelet/container/testing/fake_runtime_helper.go
View file @
c1a959c6
...
...
@@ -32,12 +32,12 @@ type FakeRuntimeHelper struct {
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
if
len
(
container
.
TerminationMessagePath
)
!=
0
{
opts
.
PodContainerDir
=
f
.
PodContainerDir
}
return
&
opts
,
false
,
nil
return
&
opts
,
nil
}
func
(
f
*
FakeRuntimeHelper
)
GetPodCgroupParent
(
pod
*
v1
.
Pod
)
string
{
...
...
pkg/kubelet/kubelet_pods.go
View file @
c1a959c6
...
...
@@ -381,18 +381,17 @@ func (kl *Kubelet) GetPodCgroupParent(pod *v1.Pod) string {
// GenerateRunContainerOptions generates the RunContainerOptions, which can be used by
// 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
)
{
useClusterFirstPolicy
:=
false
func
(
kl
*
Kubelet
)
GenerateRunContainerOptions
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
podIP
string
)
(
*
kubecontainer
.
RunContainerOptions
,
error
)
{
opts
,
err
:=
kl
.
containerManager
.
GetResources
(
pod
,
container
)
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
err
}
cgroupParent
:=
kl
.
GetPodCgroupParent
(
pod
)
opts
.
CgroupParent
=
cgroupParent
hostname
,
hostDomainName
,
err
:=
kl
.
GeneratePodHostNameAndDomain
(
pod
)
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
err
}
opts
.
Hostname
=
hostname
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
devices
,
err
:=
kl
.
makeDevices
(
pod
,
container
)
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
err
}
opts
.
Devices
=
append
(
opts
.
Devices
,
devices
...
)
mounts
,
err
:=
makeMounts
(
pod
,
kl
.
getPodDir
(
pod
.
UID
),
container
,
hostname
,
hostDomainName
,
podIP
,
volumes
)
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
err
}
opts
.
Mounts
=
append
(
opts
.
Mounts
,
mounts
...
)
envs
,
err
:=
kl
.
makeEnvironmentVariables
(
pod
,
container
,
podIP
)
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
err
}
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
if
kl
.
experimentalHostUserNamespaceDefaulting
{
opts
.
EnableHostUserNamespace
=
kl
.
enableHostUserNamespace
(
pod
)
}
return
opts
,
useClusterFirstPolicy
,
nil
return
opts
,
nil
}
var
masterServices
=
sets
.
NewString
(
"kubernetes"
)
...
...
pkg/kubelet/kubelet_pods_test.go
View file @
c1a959c6
...
...
@@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"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
{
services
[]
*
v1
.
Service
}
...
...
pkg/kubelet/kubelet_test.go
View file @
c1a959c6
...
...
@@ -19,6 +19,7 @@ package kubelet
import
(
"fmt"
"io/ioutil"
"net"
"os"
"sort"
"testing"
...
...
@@ -2170,3 +2171,90 @@ type podsByUID []*v1.Pod
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
)
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
)
}
}
pkg/kubelet/kuberuntime/kuberuntime_container.go
View file @
c1a959c6
...
...
@@ -174,7 +174,7 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
// 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
)
{
opts
,
_
,
err
:=
m
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
container
,
podIP
)
opts
,
err
:=
m
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
container
,
podIP
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/kubelet/kuberuntime/kuberuntime_container_test.go
View file @
c1a959c6
...
...
@@ -207,7 +207,7 @@ func makeExpectedConfig(m *kubeGenericRuntimeManager, pod *v1.Pod, containerInde
container
:=
&
pod
.
Spec
.
Containers
[
containerIndex
]
podIP
:=
""
restartCount
:=
0
opts
,
_
,
_
:=
m
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
container
,
podIP
)
opts
,
_
:=
m
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
container
,
podIP
)
containerLogsPath
:=
buildContainerLogsPath
(
container
.
Name
,
restartCount
)
restartCountUint32
:=
uint32
(
restartCount
)
envs
:=
make
([]
*
runtimeapi
.
KeyValue
,
len
(
opts
.
Envs
))
...
...
pkg/kubelet/rkt/rkt.go
View file @
c1a959c6
...
...
@@ -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
opts
,
_
,
err
:=
r
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
&
c
,
podIP
)
opts
,
err
:=
r
.
runtimeHelper
.
GenerateRunContainerOptions
(
pod
,
&
c
,
podIP
)
if
err
!=
nil
{
return
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment