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
fbdeff5d
Commit
fbdeff5d
authored
Feb 27, 2018
by
Sandeep Rajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code Cleanup
parent
f038d994
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
67 deletions
+63
-67
dns.go
cmd/kubeadm/app/phases/addons/dns/dns.go
+22
-26
dns_test.go
cmd/kubeadm/app/phases/addons/dns/dns_test.go
+40
-40
manifests.go
cmd/kubeadm/app/phases/addons/dns/manifests.go
+1
-1
No files found.
cmd/kubeadm/app/phases/addons/dns/dns.go
View file @
fbdeff5d
...
@@ -46,7 +46,6 @@ const (
...
@@ -46,7 +46,6 @@ const (
kubeDNSStubDomain
=
"stubDomains"
kubeDNSStubDomain
=
"stubDomains"
kubeDNSUpstreamNameservers
=
"upstreamNameservers"
kubeDNSUpstreamNameservers
=
"upstreamNameservers"
kubeDNSFederation
=
"federations"
kubeDNSFederation
=
"federations"
coreDNSStanzaFormat
=
"
\n
"
)
)
// EnsureDNSAddon creates the kube-dns or CoreDNS addon
// EnsureDNSAddon creates the kube-dns or CoreDNS addon
...
@@ -281,24 +280,20 @@ func createDNSService(dnsService *v1.Service, serviceBytes []byte, client client
...
@@ -281,24 +280,20 @@ func createDNSService(dnsService *v1.Service, serviceBytes []byte, client client
func
translateStubDomainOfKubeDNSToProxyCoreDNS
(
dataField
string
,
kubeDNSConfigMap
*
v1
.
ConfigMap
)
(
string
,
error
)
{
func
translateStubDomainOfKubeDNSToProxyCoreDNS
(
dataField
string
,
kubeDNSConfigMap
*
v1
.
ConfigMap
)
(
string
,
error
)
{
if
proxy
,
ok
:=
kubeDNSConfigMap
.
Data
[
dataField
];
ok
{
if
proxy
,
ok
:=
kubeDNSConfigMap
.
Data
[
dataField
];
ok
{
stubDomainData
:=
make
(
map
[
string
][]
string
)
stubDomainData
:=
make
(
map
[
string
][]
string
)
var
proxyStanzaList
string
err
:=
json
.
Unmarshal
([]
byte
(
proxy
),
&
stubDomainData
)
err
:=
json
.
Unmarshal
([]
byte
(
proxy
),
&
stubDomainData
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to parse JSON from 'kube-dns ConfigMap: %v"
,
err
)
return
""
,
fmt
.
Errorf
(
"failed to parse JSON from 'kube-dns ConfigMap: %v"
,
err
)
}
}
var
proxyStanza
[]
interface
{}
var
proxyStanza
[]
interface
{}
for
domain
,
proxyIP
:=
range
stubDomainData
{
for
domain
,
proxyIP
:=
range
stubDomainData
{
strings
.
Join
(
proxyIP
,
" "
)
pStanza
:=
map
[
string
]
interface
{}{}
pStanza
:=
map
[
string
]
interface
{}{}
pStanza
[
"keys"
]
=
[]
string
{
domain
+
":53"
}
pStanza
[
"keys"
]
=
[]
string
{
domain
+
":53"
}
pStanza
[
"body"
]
=
[][]
string
{
pStanza
[
"body"
]
=
[][]
string
{
{
"errors"
},
{
"errors"
},
{
"cache"
,
"30"
},
{
"cache"
,
"30"
},
{
"proxy"
,
"."
,
strings
.
Join
(
proxyIP
,
" "
)}
,
append
([]
string
{
"proxy"
,
"."
},
proxyIP
...
)
,
}
}
proxyStanza
=
append
(
proxyStanza
,
pStanza
)
proxyStanza
=
append
(
proxyStanza
,
pStanza
)
}
}
stanzasBytes
,
err
:=
json
.
Marshal
(
proxyStanza
)
stanzasBytes
,
err
:=
json
.
Marshal
(
proxyStanza
)
...
@@ -306,15 +301,12 @@ func translateStubDomainOfKubeDNSToProxyCoreDNS(dataField string, kubeDNSConfigM
...
@@ -306,15 +301,12 @@ func translateStubDomainOfKubeDNSToProxyCoreDNS(dataField string, kubeDNSConfigM
return
""
,
err
return
""
,
err
}
}
outputJSON
,
err
:=
caddyfile
.
FromJSON
(
stanzasBytes
)
corefileStanza
,
err
:=
caddyfile
.
FromJSON
(
stanzasBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
// This is required to format the Corefile, otherwise errors due to bad yaml format.
output
:=
strings
.
NewReplacer
(
"
\n\t
"
,
"
\n
"
,
"
\"
"
,
""
,
"
\n
}"
,
"
\n
}"
,
"
\n\n
"
,
"
\n
"
)
.
Replace
(
string
(
outputJSON
))
proxyStanzaList
=
coreDNSStanzaFormat
+
output
+
coreDNSStanzaFormat
return
pr
oxyStanzaList
,
nil
return
pr
epCorefileFormat
(
string
(
corefileStanza
),
4
)
,
nil
}
}
return
""
,
nil
return
""
,
nil
}
}
...
@@ -342,7 +334,7 @@ func translateFederationsofKubeDNSToCoreDNS(dataField, coreDNSDomain string, kub
...
@@ -342,7 +334,7 @@ func translateFederationsofKubeDNSToCoreDNS(dataField, coreDNSDomain string, kub
if
federation
,
ok
:=
kubeDNSConfigMap
.
Data
[
dataField
];
ok
{
if
federation
,
ok
:=
kubeDNSConfigMap
.
Data
[
dataField
];
ok
{
var
(
var
(
federationStanza
[]
interface
{}
federationStanza
[]
interface
{}
fData
[]
string
body
[]
[]
string
)
)
federationData
:=
make
(
map
[
string
]
string
)
federationData
:=
make
(
map
[
string
]
string
)
...
@@ -350,33 +342,37 @@ func translateFederationsofKubeDNSToCoreDNS(dataField, coreDNSDomain string, kub
...
@@ -350,33 +342,37 @@ func translateFederationsofKubeDNSToCoreDNS(dataField, coreDNSDomain string, kub
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to parse JSON from kube-dns ConfigMap: %v"
,
err
)
return
""
,
fmt
.
Errorf
(
"failed to parse JSON from kube-dns ConfigMap: %v"
,
err
)
}
}
fStanza
:=
map
[
string
]
interface
{}{}
for
name
,
domain
:=
range
federationData
{
for
name
,
domain
:=
range
federationData
{
fData
=
append
(
fData
,
name
+
" "
+
domain
)
body
=
append
(
body
,
[]
string
{
name
,
domain
})
}
fStanza
:=
map
[
string
]
interface
{}{}
fStanza
[
"body"
]
=
[][]
string
{
{
strings
.
Join
(
fData
,
"
\n
"
)},
}
}
federationStanza
=
append
(
federationStanza
,
fStanza
)
federationStanza
=
append
(
federationStanza
,
fStanza
)
fStanza
[
"keys"
]
=
[]
string
{
"federation "
+
coreDNSDomain
}
fStanza
[
"keys"
]
=
[]
string
{
"federation "
+
coreDNSDomain
}
fStanza
[
"body"
]
=
body
stanzasBytes
,
err
:=
json
.
Marshal
(
federationStanza
)
stanzasBytes
,
err
:=
json
.
Marshal
(
federationStanza
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
outputJSON
,
err
:=
caddyfile
.
FromJSON
(
stanzasBytes
)
corefileStanza
,
err
:=
caddyfile
.
FromJSON
(
stanzasBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
// This is required to format the Corefile, otherwise errors due to bad yaml format.
return
prepCorefileFormat
(
string
(
corefileStanza
),
8
),
nil
output
:=
strings
.
NewReplacer
(
"
\n\t
"
,
"
\n
"
,
"
\"
"
,
""
,
"
\n
}"
,
"
\n
}"
)
.
Replace
(
string
(
outputJSON
))
federationStanzaList
:=
coreDNSStanzaFormat
+
output
return
federationStanzaList
,
nil
}
}
return
""
,
nil
return
""
,
nil
}
}
// prepCorefileFormat indents the output of the Corefile caddytext and replaces tabs with spaces
// to neatly format the configmap, making it readable.
func
prepCorefileFormat
(
s
string
,
indentation
int
)
string
{
r
:=
[]
string
{}
for
_
,
line
:=
range
strings
.
Split
(
s
,
"
\n
"
)
{
indented
:=
strings
.
Repeat
(
" "
,
indentation
)
+
line
r
=
append
(
r
,
indented
)
}
corefile
:=
strings
.
Join
(
r
,
"
\n
"
)
return
"
\n
"
+
strings
.
Replace
(
corefile
,
"
\t
"
,
" "
,
-
1
)
}
cmd/kubeadm/app/phases/addons/dns/dns_test.go
View file @
fbdeff5d
...
@@ -201,28 +201,28 @@ func TestTranslateStubDomainKubeDNSToCoreDNS(t *testing.T) {
...
@@ -201,28 +201,28 @@ func TestTranslateStubDomainKubeDNSToCoreDNS(t *testing.T) {
expectOne
:
`
expectOne
:
`
foo.com:53 {
foo.com:53 {
errors
errors
cache 30
cache 30
proxy . 1.2.3.4:5300 3.3.3.3
proxy . 1.2.3.4:5300 3.3.3.3
}
}
my.cluster.local:53 {
my.cluster.local:53 {
errors
errors
cache 30
cache 30
proxy . 2.3.4.5
proxy . 2.3.4.5
}
}`
,
`
,
expectTwo
:
`
expectTwo
:
`
my.cluster.local:53 {
my.cluster.local:53 {
errors
errors
cache 30
cache 30
proxy . 2.3.4.5
proxy . 2.3.4.5
}
}
foo.com:53 {
foo.com:53 {
errors
errors
cache 30
cache 30
proxy . 1.2.3.4:5300 3.3.3.3
proxy . 1.2.3.4:5300 3.3.3.3
}
}`
,
`
,
},
},
{
{
configMap
:
&
v1
.
ConfigMap
{
configMap
:
&
v1
.
ConfigMap
{
...
@@ -248,28 +248,28 @@ func TestTranslateStubDomainKubeDNSToCoreDNS(t *testing.T) {
...
@@ -248,28 +248,28 @@ func TestTranslateStubDomainKubeDNSToCoreDNS(t *testing.T) {
expectOne
:
`
expectOne
:
`
foo.com:53 {
foo.com:53 {
errors
errors
cache 30
cache 30
proxy . 1.2.3.4:5300
proxy . 1.2.3.4:5300
}
}
my.cluster.local:53 {
my.cluster.local:53 {
errors
errors
cache 30
cache 30
proxy . 2.3.4.5
proxy . 2.3.4.5
}
}`
,
`
,
expectTwo
:
`
expectTwo
:
`
my.cluster.local:53 {
my.cluster.local:53 {
errors
errors
cache 30
cache 30
proxy . 2.3.4.5
proxy . 2.3.4.5
}
}
foo.com:53 {
foo.com:53 {
errors
errors
cache 30
cache 30
proxy . 1.2.3.4:5300
proxy . 1.2.3.4:5300
}
}`
,
`
,
},
},
{
{
configMap
:
&
v1
.
ConfigMap
{
configMap
:
&
v1
.
ConfigMap
{
...
@@ -370,15 +370,15 @@ func TestTranslateFederationKubeDNSToCoreDNS(t *testing.T) {
...
@@ -370,15 +370,15 @@ func TestTranslateFederationKubeDNSToCoreDNS(t *testing.T) {
},
},
expectOne
:
`
expectOne
:
`
federation cluster.local {
federation cluster.local {
foo foo.feddomain.com
foo foo.feddomain.com
bar bar.feddomain.com
bar bar.feddomain.com
}`
,
}`
,
expectTwo
:
`
expectTwo
:
`
federation cluster.local {
federation cluster.local {
bar bar.feddomain.com
bar bar.feddomain.com
foo foo.feddomain.com
foo foo.feddomain.com
}`
,
}`
,
},
},
{
{
configMap
:
&
v1
.
ConfigMap
{
configMap
:
&
v1
.
ConfigMap
{
...
...
cmd/kubeadm/app/phases/addons/dns/manifests.go
View file @
fbdeff5d
...
@@ -309,7 +309,7 @@ data:
...
@@ -309,7 +309,7 @@ data:
health
health
kubernetes {{ .DNSDomain }} in-addr.arpa ip6.arpa {
kubernetes {{ .DNSDomain }} in-addr.arpa ip6.arpa {
pods insecure
pods insecure
upstream
upstream
fallthrough in-addr.arpa ip6.arpa
fallthrough in-addr.arpa ip6.arpa
}{{ .Federation }}
}{{ .Federation }}
prometheus :9153
prometheus :9153
...
...
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