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
386d1b61
Commit
386d1b61
authored
Nov 16, 2017
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate DNS codes in kubelet pkg
parent
a82460d7
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
43 additions
and
37 deletions
+43
-37
helpers.go
pkg/kubelet/container/helpers.go
+1
-1
BUILD
pkg/kubelet/container/testing/BUILD
+1
-0
fake_runtime_helper.go
pkg/kubelet/container/testing/fake_runtime_helper.go
+7
-2
kubelet_network.go
pkg/kubelet/kubelet_network.go
+4
-4
helpers.go
pkg/kubelet/kuberuntime/helpers.go
+0
-5
kuberuntime_sandbox.go
pkg/kubelet/kuberuntime/kuberuntime_sandbox.go
+2
-10
BUILD
pkg/kubelet/network/dns/BUILD
+1
-0
dns.go
pkg/kubelet/network/dns/dns.go
+18
-8
dns_test.go
pkg/kubelet/network/dns/dns_test.go
+5
-3
rkt.go
pkg/kubelet/rkt/rkt.go
+4
-4
No files found.
pkg/kubelet/container/helpers.go
View file @
386d1b61
...
...
@@ -47,7 +47,7 @@ type HandlerRunner interface {
// 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
,
err
error
)
Get
ClusterDNS
(
pod
*
v1
.
Pod
)
(
dnsServers
[]
string
,
dnsSearches
[]
string
,
dnsOptions
[]
string
,
useClusterFirstPolicy
bool
,
err
error
)
Get
PodDNS
(
pod
*
v1
.
Pod
)
(
dnsConfig
*
runtimeapi
.
DNSConfig
,
err
error
)
// GetPodCgroupParent returns the CgroupName identifer, and its literal cgroupfs form on the host
// of a pod.
GetPodCgroupParent
(
pod
*
v1
.
Pod
)
string
...
...
pkg/kubelet/container/testing/BUILD
View file @
386d1b61
...
...
@@ -14,6 +14,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/kubelet/container/testing",
visibility = ["//visibility:public"],
deps = [
"//pkg/kubelet/apis/cri/v1alpha1/runtime:go_default_library",
"//pkg/kubelet/container:go_default_library",
"//pkg/volume:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library",
...
...
pkg/kubelet/container/testing/fake_runtime_helper.go
View file @
386d1b61
...
...
@@ -19,6 +19,7 @@ package testing
import
(
"k8s.io/api/core/v1"
kubetypes
"k8s.io/apimachinery/pkg/types"
runtimeapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
)
...
...
@@ -26,6 +27,7 @@ import (
type
FakeRuntimeHelper
struct
{
DNSServers
[]
string
DNSSearches
[]
string
DNSOptions
[]
string
HostName
string
HostDomain
string
PodContainerDir
string
...
...
@@ -44,8 +46,11 @@ func (f *FakeRuntimeHelper) GetPodCgroupParent(pod *v1.Pod) string {
return
""
}
func
(
f
*
FakeRuntimeHelper
)
GetClusterDNS
(
pod
*
v1
.
Pod
)
([]
string
,
[]
string
,
[]
string
,
bool
,
error
)
{
return
f
.
DNSServers
,
f
.
DNSSearches
,
nil
,
false
,
f
.
Err
func
(
f
*
FakeRuntimeHelper
)
GetPodDNS
(
pod
*
v1
.
Pod
)
(
*
runtimeapi
.
DNSConfig
,
error
)
{
return
&
runtimeapi
.
DNSConfig
{
Servers
:
f
.
DNSServers
,
Searches
:
f
.
DNSSearches
,
Options
:
f
.
DNSOptions
},
f
.
Err
}
// This is not used by docker runtime.
...
...
pkg/kubelet/kubelet_network.go
View file @
386d1b61
...
...
@@ -22,6 +22,7 @@ import (
"github.com/golang/glog"
"k8s.io/api/core/v1"
clientset
"k8s.io/client-go/kubernetes"
runtimeapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/network"
...
...
@@ -281,10 +282,9 @@ func getIPTablesMark(bit int) string {
return
fmt
.
Sprintf
(
"%#08x/%#08x"
,
value
,
value
)
}
// GetClusterDNS returns a list of the DNS servers, a list of the DNS search
// domains of the cluster, and a list of resolv.conf options.
// GetPodDNS returns DNS setttings for the pod.
// This function is defined in kubecontainer.RuntimeHelper interface so we
// have to implement it.
func
(
kl
*
Kubelet
)
Get
ClusterDNS
(
pod
*
v1
.
Pod
)
([]
string
,
[]
string
,
[]
string
,
bool
,
error
)
{
return
kl
.
dnsConfigurer
.
Get
Cluster
DNS
(
pod
)
func
(
kl
*
Kubelet
)
Get
PodDNS
(
pod
*
v1
.
Pod
)
(
*
runtimeapi
.
DNSConfig
,
error
)
{
return
kl
.
dnsConfigurer
.
Get
Pod
DNS
(
pod
)
}
pkg/kubelet/kuberuntime/helpers.go
View file @
386d1b61
...
...
@@ -41,11 +41,6 @@ const (
minQuotaPeriod
=
1000
)
var
(
// The default dns opt strings
defaultDNSOptions
=
[]
string
{
"ndots:5"
}
)
type
podsByID
[]
*
kubecontainer
.
Pod
func
(
b
podsByID
)
Len
()
int
{
return
len
(
b
)
}
...
...
pkg/kubelet/kuberuntime/kuberuntime_sandbox.go
View file @
386d1b61
...
...
@@ -74,19 +74,11 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
Annotations
:
newPodAnnotations
(
pod
),
}
dns
Servers
,
dnsSearches
,
dnsOptions
,
useClusterFirstPolicy
,
err
:=
m
.
runtimeHelper
.
GetCluster
DNS
(
pod
)
dns
Config
,
err
:=
m
.
runtimeHelper
.
GetPod
DNS
(
pod
)
if
err
!=
nil
{
return
nil
,
err
}
podSandboxConfig
.
DnsConfig
=
&
runtimeapi
.
DNSConfig
{
Servers
:
dnsServers
,
Searches
:
dnsSearches
,
Options
:
dnsOptions
,
}
if
useClusterFirstPolicy
{
podSandboxConfig
.
DnsConfig
.
Options
=
defaultDNSOptions
}
podSandboxConfig
.
DnsConfig
=
dnsConfig
if
!
kubecontainer
.
IsHostNetworkPod
(
pod
)
{
// TODO: Add domain support in new runtime interface
...
...
pkg/kubelet/network/dns/BUILD
View file @
386d1b61
...
...
@@ -6,6 +6,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/kubelet/network/dns",
visibility = ["//visibility:public"],
deps = [
"//pkg/kubelet/apis/cri/v1alpha1/runtime:go_default_library",
"//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/util/format:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
...
...
pkg/kubelet/network/dns/dns.go
View file @
386d1b61
...
...
@@ -27,12 +27,18 @@ import (
"k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
runtimeapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/util/format"
"github.com/golang/glog"
)
var
(
// The default dns opt strings.
defaultDNSOptions
=
[]
string
{
"ndots:5"
}
)
// Configurer is used for setting up DNS resolver configuration when launching pods.
type
Configurer
struct
{
recorder
record
.
EventRecorder
...
...
@@ -219,22 +225,20 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
return
nameservers
,
searches
,
options
,
nil
}
// GetClusterDNS returns a list of the DNS servers, a list of the DNS search
// domains of the cluster, and a list of resolv.conf options.
// TODO: This should return a struct.
func
(
c
*
Configurer
)
GetClusterDNS
(
pod
*
v1
.
Pod
)
([]
string
,
[]
string
,
[]
string
,
bool
,
error
)
{
// GetPodDNS returns DNS setttings for the pod.
func
(
c
*
Configurer
)
GetPodDNS
(
pod
*
v1
.
Pod
)
(
*
runtimeapi
.
DNSConfig
,
error
)
{
var
hostDNS
,
hostSearch
,
hostOptions
[]
string
// Get host DNS settings
if
c
.
ResolverConfig
!=
""
{
f
,
err
:=
os
.
Open
(
c
.
ResolverConfig
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
false
,
err
return
nil
,
err
}
defer
f
.
Close
()
hostDNS
,
hostSearch
,
hostOptions
,
err
=
parseResolvConf
(
f
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
false
,
err
return
nil
,
err
}
}
useClusterFirstPolicy
:=
((
pod
.
Spec
.
DNSPolicy
==
v1
.
DNSClusterFirst
&&
!
kubecontainer
.
IsHostNetworkPod
(
pod
))
||
pod
.
Spec
.
DNSPolicy
==
v1
.
DNSClusterFirstWithHostNet
)
...
...
@@ -268,7 +272,10 @@ func (c *Configurer) GetClusterDNS(pod *v1.Pod) ([]string, []string, []string, b
}
else
{
hostSearch
=
c
.
formDNSSearchForDNSDefault
(
hostSearch
,
pod
)
}
return
hostDNS
,
hostSearch
,
hostOptions
,
useClusterFirstPolicy
,
nil
return
&
runtimeapi
.
DNSConfig
{
Servers
:
hostDNS
,
Searches
:
hostSearch
,
Options
:
hostOptions
},
nil
}
// for a pod with DNSClusterFirst policy, the cluster DNS server is the only nameserver configured for
...
...
@@ -280,7 +287,10 @@ func (c *Configurer) GetClusterDNS(pod *v1.Pod) ([]string, []string, []string, b
}
dnsSearch
:=
c
.
formDNSSearch
(
hostSearch
,
pod
)
return
dns
,
dnsSearch
,
hostOptions
,
useClusterFirstPolicy
,
nil
return
&
runtimeapi
.
DNSConfig
{
Servers
:
dns
,
Searches
:
dnsSearch
,
Options
:
defaultDNSOptions
},
nil
}
// SetupDNSinContainerizedMounter replaces the nameserver in containerized-mounter's rootfs/etc/resolve.conf with kubelet.ClusterDNS
...
...
pkg/kubelet/network/dns/dns_test.go
View file @
386d1b61
...
...
@@ -152,7 +152,7 @@ func TestComposeDNSSearch(t *testing.T) {
}
}
func
TestGet
Cluster
DNS
(
t
*
testing
.
T
)
{
func
TestGet
Pod
DNS
(
t
*
testing
.
T
)
{
recorder
:=
record
.
NewFakeRecorder
(
20
)
nodeRef
:=
&
v1
.
ObjectReference
{
Kind
:
"Node"
,
...
...
@@ -179,10 +179,11 @@ func TestGetClusterDNS(t *testing.T) {
},
4
)
for
i
,
pod
:=
range
pods
{
var
err
error
options
[
i
]
.
DNS
,
options
[
i
]
.
DNSSearch
,
_
,
_
,
err
=
configurer
.
GetCluster
DNS
(
pod
)
dnsConfig
,
err
:=
configurer
.
GetPod
DNS
(
pod
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate container options: %v"
,
err
)
}
options
[
i
]
.
DNS
,
options
[
i
]
.
DNSSearch
=
dnsConfig
.
Servers
,
dnsConfig
.
Searches
}
if
len
(
options
[
0
]
.
DNS
)
!=
1
||
options
[
0
]
.
DNS
[
0
]
!=
clusterNS
{
t
.
Errorf
(
"expected nameserver %s, got %+v"
,
clusterNS
,
options
[
0
]
.
DNS
)
...
...
@@ -213,10 +214,11 @@ func TestGetClusterDNS(t *testing.T) {
configurer
=
NewConfigurer
(
recorder
,
nodeRef
,
nil
,
testClusterDNS
,
testClusterDNSDomain
,
testResolverConfig
)
for
i
,
pod
:=
range
pods
{
var
err
error
options
[
i
]
.
DNS
,
options
[
i
]
.
DNSSearch
,
_
,
_
,
err
=
configurer
.
GetCluster
DNS
(
pod
)
dnsConfig
,
err
:=
configurer
.
GetPod
DNS
(
pod
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate container options: %v"
,
err
)
}
options
[
i
]
.
DNS
,
options
[
i
]
.
DNSSearch
=
dnsConfig
.
Servers
,
dnsConfig
.
Searches
}
t
.
Logf
(
"nameservers %+v"
,
options
[
1
]
.
DNS
)
if
len
(
options
[
0
]
.
DNS
)
!=
1
{
...
...
pkg/kubelet/rkt/rkt.go
View file @
386d1b61
...
...
@@ -1041,17 +1041,17 @@ func (r *Runtime) generateRunCommand(pod *v1.Pod, uuid, networkNamespaceID strin
}
}
else
{
// Setup DNS.
dns
Servers
,
dnsSearches
,
_
,
_
,
err
:=
r
.
runtimeHelper
.
GetCluster
DNS
(
pod
)
dns
Config
,
err
:=
r
.
runtimeHelper
.
GetPod
DNS
(
pod
)
if
err
!=
nil
{
return
""
,
err
}
for
_
,
server
:=
range
dnsServers
{
for
_
,
server
:=
range
dns
Config
.
Servers
{
runPrepared
=
append
(
runPrepared
,
fmt
.
Sprintf
(
"--dns=%s"
,
server
))
}
for
_
,
search
:=
range
dnsSearches
{
for
_
,
search
:=
range
dns
Config
.
Searches
{
runPrepared
=
append
(
runPrepared
,
fmt
.
Sprintf
(
"--dns-search=%s"
,
search
))
}
if
len
(
dns
Servers
)
>
0
||
len
(
dns
Searches
)
>
0
{
if
len
(
dns
Config
.
Servers
)
>
0
||
len
(
dnsConfig
.
Searches
)
>
0
{
runPrepared
=
append
(
runPrepared
,
fmt
.
Sprintf
(
"--dns-opt=%s"
,
defaultDNSOption
))
}
...
...
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