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
19cf8310
Commit
19cf8310
authored
Oct 24, 2016
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubedns: use initial resource listing as ready signal
parent
8d761a07
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
40 deletions
+38
-40
options.go
cmd/kube-dns/app/options/options.go
+5
-0
server.go
cmd/kube-dns/app/server.go
+7
-9
known-flags.txt
hack/verify-flags/known-flags.txt
+1
-0
dns.go
pkg/dns/dns.go
+25
-31
No files found.
cmd/kube-dns/app/options/options.go
View file @
19cf8310
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"net/url"
"net/url"
"os"
"os"
"strings"
"strings"
"time"
"github.com/spf13/pflag"
"github.com/spf13/pflag"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -34,6 +35,7 @@ type KubeDNSConfig struct {
...
@@ -34,6 +35,7 @@ type KubeDNSConfig struct {
ClusterDomain
string
ClusterDomain
string
KubeConfigFile
string
KubeConfigFile
string
KubeMasterURL
string
KubeMasterURL
string
InitialSyncTimeout
time
.
Duration
HealthzPort
int
HealthzPort
int
DNSBindAddress
string
DNSBindAddress
string
...
@@ -51,6 +53,7 @@ func NewKubeDNSConfig() *KubeDNSConfig {
...
@@ -51,6 +53,7 @@ func NewKubeDNSConfig() *KubeDNSConfig {
HealthzPort
:
8081
,
HealthzPort
:
8081
,
DNSBindAddress
:
"0.0.0.0"
,
DNSBindAddress
:
"0.0.0.0"
,
DNSPort
:
53
,
DNSPort
:
53
,
InitialSyncTimeout
:
60
*
time
.
Second
,
Federations
:
make
(
map
[
string
]
string
),
Federations
:
make
(
map
[
string
]
string
),
...
@@ -160,4 +163,6 @@ func (s *KubeDNSConfig) AddFlags(fs *pflag.FlagSet) {
...
@@ -160,4 +163,6 @@ func (s *KubeDNSConfig) AddFlags(fs *pflag.FlagSet) {
"config-map name. If empty, then the config-map will not used. Cannot be "
+
"config-map name. If empty, then the config-map will not used. Cannot be "
+
" used in conjunction with federations flag. config-map contains "
+
" used in conjunction with federations flag. config-map contains "
+
"dynamically adjustable configuration."
)
"dynamically adjustable configuration."
)
fs
.
DurationVar
(
&
s
.
InitialSyncTimeout
,
"initial-sync-timeout"
,
s
.
InitialSyncTimeout
,
"Timeout for initial resource sync."
)
}
}
cmd/kube-dns/app/server.go
View file @
19cf8310
...
@@ -47,17 +47,11 @@ type KubeDNSServer struct {
...
@@ -47,17 +47,11 @@ type KubeDNSServer struct {
}
}
func
NewKubeDNSServerDefault
(
config
*
options
.
KubeDNSConfig
)
*
KubeDNSServer
{
func
NewKubeDNSServerDefault
(
config
*
options
.
KubeDNSConfig
)
*
KubeDNSServer
{
ks
:=
KubeDNSServer
{
domain
:
config
.
ClusterDomain
}
kubeClient
,
err
:=
newKubeClient
(
config
)
kubeClient
,
err
:=
newKubeClient
(
config
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Failed to create a kubernetes client: %v"
,
err
)
glog
.
Fatalf
(
"Failed to create a kubernetes client: %v"
,
err
)
}
}
ks
.
healthzPort
=
config
.
HealthzPort
ks
.
dnsBindAddress
=
config
.
DNSBindAddress
ks
.
dnsPort
=
config
.
DNSPort
var
configSync
dnsconfig
.
Sync
var
configSync
dnsconfig
.
Sync
if
config
.
ConfigMap
==
""
{
if
config
.
ConfigMap
==
""
{
glog
.
V
(
0
)
.
Infof
(
"ConfigMap not configured, using values from command line flags"
)
glog
.
V
(
0
)
.
Infof
(
"ConfigMap not configured, using values from command line flags"
)
...
@@ -70,9 +64,13 @@ func NewKubeDNSServerDefault(config *options.KubeDNSConfig) *KubeDNSServer {
...
@@ -70,9 +64,13 @@ func NewKubeDNSServerDefault(config *options.KubeDNSConfig) *KubeDNSServer {
kubeClient
,
config
.
ConfigMapNs
,
config
.
ConfigMap
)
kubeClient
,
config
.
ConfigMapNs
,
config
.
ConfigMap
)
}
}
ks
.
kd
=
kdns
.
NewKubeDNS
(
kubeClient
,
config
.
ClusterDomain
,
configSync
)
return
&
KubeDNSServer
{
domain
:
config
.
ClusterDomain
,
return
&
ks
healthzPort
:
config
.
HealthzPort
,
dnsBindAddress
:
config
.
DNSBindAddress
,
dnsPort
:
config
.
DNSPort
,
kd
:
kdns
.
NewKubeDNS
(
kubeClient
,
config
.
ClusterDomain
,
config
.
InitialSyncTimeout
,
configSync
),
}
}
}
// TODO: evaluate using pkg/client/clientcmd
// TODO: evaluate using pkg/client/clientcmd
...
...
hack/verify-flags/known-flags.txt
View file @
19cf8310
...
@@ -275,6 +275,7 @@ image-service-endpoint
...
@@ -275,6 +275,7 @@ image-service-endpoint
include-extended-apis
include-extended-apis
include-extended-apis
include-extended-apis
included-types-overrides
included-types-overrides
initial-sync-timeout
input-base
input-base
input-dirs
input-dirs
insecure-allow-any-token
insecure-allow-any-token
...
...
pkg/dns/dns.go
View file @
19cf8310
...
@@ -24,9 +24,6 @@ import (
...
@@ -24,9 +24,6 @@ import (
"sync"
"sync"
"time"
"time"
etcd
"github.com/coreos/etcd/client"
"github.com/miekg/dns"
skymsg
"github.com/skynetservices/skydns/msg"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1/endpoints"
"k8s.io/kubernetes/pkg/api/v1/endpoints"
metav1
"k8s.io/kubernetes/pkg/apis/meta/v1"
metav1
"k8s.io/kubernetes/pkg/apis/meta/v1"
...
@@ -40,7 +37,10 @@ import (
...
@@ -40,7 +37,10 @@ import (
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/pkg/watch"
etcd
"github.com/coreos/etcd/client"
"github.com/golang/glog"
"github.com/golang/glog"
"github.com/miekg/dns"
skymsg
"github.com/skynetservices/skydns/msg"
)
)
const
(
const
(
...
@@ -117,9 +117,12 @@ type KubeDNS struct {
...
@@ -117,9 +117,12 @@ type KubeDNS struct {
configLock
sync
.
RWMutex
configLock
sync
.
RWMutex
// configSync manages synchronization of the config map
// configSync manages synchronization of the config map
configSync
config
.
Sync
configSync
config
.
Sync
// Initial timeout for endpoints and services to be synced from APIServer
initialSyncTimeout
time
.
Duration
}
}
func
NewKubeDNS
(
client
clientset
.
Interface
,
clusterDomain
string
,
configSync
config
.
Sync
)
*
KubeDNS
{
func
NewKubeDNS
(
client
clientset
.
Interface
,
clusterDomain
string
,
timeout
time
.
Duration
,
configSync
config
.
Sync
)
*
KubeDNS
{
kd
:=
&
KubeDNS
{
kd
:=
&
KubeDNS
{
kubeClient
:
client
,
kubeClient
:
client
,
domain
:
clusterDomain
,
domain
:
clusterDomain
,
...
@@ -129,6 +132,7 @@ func NewKubeDNS(client clientset.Interface, clusterDomain string, configSync con
...
@@ -129,6 +132,7 @@ func NewKubeDNS(client clientset.Interface, clusterDomain string, configSync con
reverseRecordMap
:
make
(
map
[
string
]
*
skymsg
.
Service
),
reverseRecordMap
:
make
(
map
[
string
]
*
skymsg
.
Service
),
clusterIPServiceMap
:
make
(
map
[
string
]
*
v1
.
Service
),
clusterIPServiceMap
:
make
(
map
[
string
]
*
v1
.
Service
),
domainPath
:
util
.
ReverseArray
(
strings
.
Split
(
strings
.
TrimRight
(
clusterDomain
,
"."
),
"."
)),
domainPath
:
util
.
ReverseArray
(
strings
.
Split
(
strings
.
TrimRight
(
clusterDomain
,
"."
),
"."
)),
initialSyncTimeout
:
timeout
,
configLock
:
sync
.
RWMutex
{},
configLock
:
sync
.
RWMutex
{},
configSync
:
configSync
,
configSync
:
configSync
,
...
@@ -149,38 +153,28 @@ func (kd *KubeDNS) Start() {
...
@@ -149,38 +153,28 @@ func (kd *KubeDNS) Start() {
kd
.
startConfigMapSync
()
kd
.
startConfigMapSync
()
// Wait synchronously for the Kubernetes service. This ensures that
// Wait synchronously for the initial list operations to be
// the Start function returns only after having received Service
// complete of endpoints and services from APIServer.
// objects from APIServer.
kd
.
waitForResourceSyncedOrDie
()
//
// TODO: we might not have to wait for kubernetes service
// specifically. We should just wait for a list operation to be
// complete from APIServer.
kd
.
waitForKubernetesService
()
}
}
func
(
kd
*
KubeDNS
)
waitForKubernetesService
()
{
func
(
kd
*
KubeDNS
)
waitForResourceSyncedOrDie
()
{
glog
.
V
(
2
)
.
Infof
(
"Waiting for Kubernetes service"
)
// Wait for both controllers have completed an initial resource listing
timeout
:=
time
.
After
(
kd
.
initialSyncTimeout
)
const
kubernetesSvcName
=
"kubernetes"
ticker
:=
time
.
NewTicker
(
500
*
time
.
Millisecond
)
const
servicePollInterval
=
1
*
time
.
Second
defer
ticker
.
Stop
()
name
:=
fmt
.
Sprintf
(
"%v/%v"
,
v1
.
NamespaceDefault
,
kubernetesSvcName
)
glog
.
V
(
2
)
.
Infof
(
"Waiting for service: %v"
,
name
)
for
{
for
{
svc
,
err
:=
kd
.
kubeClient
.
Core
()
.
Services
(
v1
.
NamespaceDefault
)
.
Get
(
kubernetesSvcName
)
select
{
if
err
!=
nil
||
svc
==
nil
{
case
<-
timeout
:
glog
.
V
(
3
)
.
Infof
(
glog
.
Fatalf
(
"Timeout waiting for initialization"
)
"Ignoring error while waiting for service %v: %v. Sleeping %v before retrying."
,
case
<-
ticker
.
C
:
name
,
err
,
servicePollInterval
)
if
kd
.
endpointsController
.
HasSynced
()
&&
kd
.
serviceController
.
HasSynced
()
{
time
.
Sleep
(
servicePollInterval
)
glog
.
V
(
0
)
.
Infof
(
"Initialized services and endpoints from apiserver"
)
continue
return
}
glog
.
V
(
0
)
.
Infof
(
"DNS server not ready, retry in 500 milliseconds"
)
}
}
break
}
}
return
}
}
func
(
kd
*
KubeDNS
)
startConfigMapSync
()
{
func
(
kd
*
KubeDNS
)
startConfigMapSync
()
{
...
...
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