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
31cf2bc9
Commit
31cf2bc9
authored
Apr 16, 2019
by
Erik Wilson
Committed by
Erik Wilson
Apr 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add coredns entries for nodes
parent
334efc74
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
0 deletions
+123
-0
coredns.yaml
manifests/coredns.yaml
+6
-0
controller.go
pkg/node/controller.go
+115
-0
server.go
pkg/server/server.go
+2
-0
No files found.
manifests/coredns.yaml
View file @
31cf2bc9
...
...
@@ -60,6 +60,10 @@ data:
upstream
fallthrough in-addr.arpa ip6.arpa
}
hosts /etc/coredns/NodeHosts {
reload 1s
fallthrough
}
prometheus :9153
proxy . /etc/resolv.conf
cache 30
...
...
@@ -146,6 +150,8 @@ spec:
items
:
-
key
:
Corefile
path
:
Corefile
-
key
:
NodeHosts
path
:
NodeHosts
---
apiVersion
:
v1
kind
:
Service
...
...
pkg/node/controller.go
0 → 100644
View file @
31cf2bc9
package
node
import
(
"context"
"strings"
"github.com/pkg/errors"
coreclient
"github.com/rancher/k3s/types/apis/core/v1"
"github.com/sirupsen/logrus"
core
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)
func
Register
(
ctx
context
.
Context
)
error
{
clients
:=
coreclient
.
ClientsFrom
(
ctx
)
h
:=
&
handler
{
configCache
:
clients
.
ConfigMap
.
Cache
(),
configClient
:
clients
.
ConfigMap
,
}
clients
.
Node
.
OnCreate
(
ctx
,
"node"
,
h
.
onChange
)
clients
.
Node
.
OnChange
(
ctx
,
"node"
,
h
.
onChange
)
clients
.
Node
.
OnRemove
(
ctx
,
"node"
,
h
.
onRemove
)
return
nil
}
type
handler
struct
{
configCache
coreclient
.
ConfigMapClientCache
configClient
coreclient
.
ConfigMapClient
}
func
(
h
*
handler
)
onChange
(
node
*
core
.
Node
)
(
runtime
.
Object
,
error
)
{
return
h
.
updateHosts
(
node
,
false
)
}
func
(
h
*
handler
)
onRemove
(
node
*
core
.
Node
)
(
runtime
.
Object
,
error
)
{
return
h
.
updateHosts
(
node
,
true
)
}
func
(
h
*
handler
)
updateHosts
(
node
*
core
.
Node
,
removed
bool
)
(
runtime
.
Object
,
error
)
{
var
(
newHosts
string
nodeUID
string
nodeAddress
string
nodeEntry
string
uidHostsMap
map
[
string
]
string
)
nodeUID
=
string
(
node
.
UID
)
uidHostsMap
=
make
(
map
[
string
]
string
)
for
_
,
address
:=
range
node
.
Status
.
Addresses
{
if
address
.
Type
==
"InternalIP"
{
nodeAddress
=
address
.
Address
break
}
}
if
nodeAddress
==
""
{
logrus
.
Errorf
(
"No InternalIP found for node %s"
,
node
.
Name
)
return
nil
,
nil
}
nodeEntry
=
nodeAddress
+
" "
+
node
.
Name
configMap
,
err
:=
h
.
configCache
.
Get
(
"kube-system"
,
"coredns"
)
if
err
!=
nil
||
configMap
==
nil
{
logrus
.
Warn
(
errors
.
Wrap
(
err
,
"Unable to fetch coredns config map"
))
return
nil
,
nil
}
hosts
:=
configMap
.
Data
[
"NodeHosts"
]
for
_
,
line
:=
range
strings
.
Split
(
hosts
,
"
\n
"
)
{
if
line
==
""
{
continue
}
fields
:=
strings
.
Fields
(
line
)
if
len
(
fields
)
!=
4
||
fields
[
2
]
!=
"#"
{
logrus
.
Warnf
(
"Unknown format for hosts line [%s]"
,
line
)
continue
}
ip
:=
fields
[
0
]
host
:=
fields
[
1
]
uid
:=
fields
[
3
]
hostEntry
:=
ip
+
" "
+
host
if
uid
==
nodeUID
{
if
removed
{
continue
}
if
hostEntry
==
nodeEntry
{
return
nil
,
nil
}
}
uidHostsMap
[
uid
]
=
hostEntry
}
if
!
removed
{
uidHostsMap
[
nodeUID
]
=
nodeEntry
}
for
uid
,
hostEntry
:=
range
uidHostsMap
{
newHosts
+=
hostEntry
+
" # "
+
uid
+
"
\n
"
}
configMap
.
Data
[
"NodeHosts"
]
=
newHosts
if
_
,
err
:=
h
.
configClient
.
Update
(
configMap
);
err
!=
nil
{
return
nil
,
err
}
var
actionType
string
if
removed
{
actionType
=
"Removed"
}
else
{
actionType
=
"Updated"
}
logrus
.
Infof
(
"%s coredns node hosts entry [%s]"
,
actionType
,
nodeEntry
)
return
nil
,
nil
}
pkg/server/server.go
View file @
31cf2bc9
...
...
@@ -18,6 +18,7 @@ import (
"github.com/rancher/k3s/pkg/datadir"
"github.com/rancher/k3s/pkg/deploy"
"github.com/rancher/k3s/pkg/helm"
"github.com/rancher/k3s/pkg/node"
"github.com/rancher/k3s/pkg/rootlessports"
"github.com/rancher/k3s/pkg/servicelb"
"github.com/rancher/k3s/pkg/static"
...
...
@@ -112,6 +113,7 @@ func startNorman(ctx context.Context, config *Config) (string, error) {
},
DisableLeaderElection
:
true
,
MasterControllers
:
[]
norman
.
ControllerRegister
{
node
.
Register
,
helm
.
Register
,
func
(
ctx
context
.
Context
)
error
{
return
servicelb
.
Register
(
ctx
,
norman
.
GetServer
(
ctx
)
.
K8sClient
,
!
config
.
DisableServiceLB
,
...
...
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