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
f0861b9e
Commit
f0861b9e
authored
Jun 24, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update skydns/msg dep
Using the exact v2.5.1a commit.
parent
2803b86a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
267 additions
and
10 deletions
+267
-10
Godeps.json
Godeps/Godeps.json
+2
-2
service.go
...space/src/github.com/skynetservices/skydns/msg/service.go
+128
-8
service_test.go
.../src/github.com/skynetservices/skydns/msg/service_test.go
+137
-0
No files found.
Godeps/Godeps.json
View file @
f0861b9e
...
...
@@ -475,8 +475,8 @@
},
{
"ImportPath"
:
"github.com/skynetservices/skydns/msg"
,
"Comment"
:
"2.
0.1d-2-g245a121
"
,
"Rev"
:
"
245a1216be2a7f5377ea56e957fdfa0de6ecd067
"
"Comment"
:
"2.
5.1a
"
,
"Rev"
:
"
1be70b5b8aa07acccd972146d84011b670af88b4
"
},
{
"ImportPath"
:
"github.com/spf13/cobra"
,
...
...
Godeps/_workspace/src/github.com/skynetservices/skydns/msg/service.go
View file @
f0861b9e
...
...
@@ -20,15 +20,60 @@ type Service struct {
Port
int
`json:"port,omitempty"`
Priority
int
`json:"priority,omitempty"`
Weight
int
`json:"weight,omitempty"`
Text
string
`json:"text,omitempty"`
Mail
bool
`json:"mail,omitempty"`
// Be an MX record. Priority becomes Preference.
Ttl
uint32
`json:"ttl,omitempty"`
// etcd key where we found this service and ignore from json un-/marshalling
// When a SRV record with a "Host: IP-address" is added, we synthesize
// a srv.Target domain name. Normally we convert the full Key where
// the record lives to a DNS name and use this as the srv.Target. When
// TargetStrip > 0 we strip the left most TargetStrip labels from the
// DNS name.
TargetStrip
int
`json:"targetstrip",omitempty"`
// Group is used to group (or *not* to group) different services
// together. Services with an identical Group are returned in the same
// answer.
Group
string
`json:"group,omitempty"`
// Etcd key where we found this service and ignored from json un-/marshalling
Key
string
`json:"-"`
}
// NewSRV returns a new SRV record based on the Service.
func
(
s
*
Service
)
NewSRV
(
name
string
,
weight
uint16
)
*
dns
.
SRV
{
host
:=
dns
.
Fqdn
(
s
.
Host
)
offset
,
end
:=
0
,
false
for
i
:=
0
;
i
<
s
.
TargetStrip
;
i
++
{
offset
,
end
=
dns
.
NextLabel
(
host
,
offset
)
}
if
end
{
// We overshot the name, use the orignal one.
offset
=
0
}
host
=
host
[
offset
:
]
return
&
dns
.
SRV
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypeSRV
,
Class
:
dns
.
ClassINET
,
Ttl
:
s
.
Ttl
},
Priority
:
uint16
(
s
.
Priority
),
Weight
:
weight
,
Port
:
uint16
(
s
.
Port
),
Target
:
dns
.
Fqdn
(
s
.
Host
)}
Priority
:
uint16
(
s
.
Priority
),
Weight
:
weight
,
Port
:
uint16
(
s
.
Port
),
Target
:
host
}
}
// NewMX returns a new MX record based on the Service.
func
(
s
*
Service
)
NewMX
(
name
string
)
*
dns
.
MX
{
host
:=
dns
.
Fqdn
(
s
.
Host
)
offset
,
end
:=
0
,
false
for
i
:=
0
;
i
<
s
.
TargetStrip
;
i
++
{
offset
,
end
=
dns
.
NextLabel
(
host
,
offset
)
}
if
end
{
// We overshot the name, use the orignal one.
offset
=
0
}
host
=
host
[
offset
:
]
return
&
dns
.
MX
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypeMX
,
Class
:
dns
.
ClassINET
,
Ttl
:
s
.
Ttl
},
Preference
:
uint16
(
s
.
Priority
),
Mx
:
host
}
}
// NewA returns a new A record based on the Service.
...
...
@@ -51,23 +96,28 @@ func (s *Service) NewNS(name string, target string) *dns.NS {
return
&
dns
.
NS
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypeNS
,
Class
:
dns
.
ClassINET
,
Ttl
:
s
.
Ttl
},
Ns
:
target
}
}
// NewTXT returns a new TXT record based on the Service.
func
(
s
*
Service
)
NewTXT
(
name
string
)
*
dns
.
TXT
{
return
&
dns
.
TXT
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypeTXT
,
Class
:
dns
.
ClassINET
,
Ttl
:
s
.
Ttl
},
Txt
:
split255
(
s
.
Text
)}
}
// NewPTR returns a new PTR record based on the Service.
func
(
s
*
Service
)
NewPTR
(
name
string
,
ttl
uint32
)
*
dns
.
PTR
{
return
&
dns
.
PTR
{
Hdr
:
dns
.
RR_Header
{
Name
:
name
,
Rrtype
:
dns
.
TypePTR
,
Class
:
dns
.
ClassINET
,
Ttl
:
ttl
},
Ptr
:
dns
.
Fqdn
(
s
.
Host
)}
}
// As Path, but
//
if a name contains wildcards (*), the name will be chopped of before the (first) wildcard,
and
//
we do a highler evel search and later find the matching names.
//
So service.*.skydns.local, will look for all services under skydns.local and will later check
//
for names that match
service.*.skydns.local. If a wildcard is found the returned bool is true.
// As Path, but
if a name contains wildcards (* or any), the name will be
//
chopped of before the (first) wildcard, and we do a highler evel search
and
//
later find the matching names. So service.*.skydns.local, will look for all
//
services under skydns.local and will later check for names that match
// service.*.skydns.local. If a wildcard is found the returned bool is true.
func
PathWithWildcard
(
s
string
)
(
string
,
bool
)
{
l
:=
dns
.
SplitDomainName
(
s
)
for
i
,
j
:=
0
,
len
(
l
)
-
1
;
i
<
j
;
i
,
j
=
i
+
1
,
j
-
1
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
for
i
,
k
:=
range
l
{
if
k
==
"*"
{
if
k
==
"*"
||
k
==
"any"
{
return
path
.
Join
(
append
([]
string
{
"/skydns/"
},
l
[
:
i
]
...
)
...
),
true
}
}
...
...
@@ -93,3 +143,73 @@ func Domain(s string) string {
}
return
dns
.
Fqdn
(
strings
.
Join
(
l
[
1
:
len
(
l
)
-
1
],
"."
))
}
// Group checks the services in sx, it looks for a Group attribute on the shortest
// keys. If there are multiple shortest keys *and* the group attribute disagrees (and
// is not empty), we don't consider it a group.
// If a group is found, only services with *that* group (or no group) will be returned.
func
Group
(
sx
[]
Service
)
[]
Service
{
if
len
(
sx
)
==
0
{
return
sx
}
// Shortest key with group attribute sets the group for this set.
group
:=
sx
[
0
]
.
Group
slashes
:=
strings
.
Count
(
sx
[
0
]
.
Key
,
"/"
)
length
:=
make
([]
int
,
len
(
sx
))
for
i
,
s
:=
range
sx
{
x
:=
strings
.
Count
(
s
.
Key
,
"/"
)
length
[
i
]
=
x
if
x
<
slashes
{
if
s
.
Group
==
""
{
break
}
slashes
=
x
group
=
s
.
Group
}
}
if
group
==
""
{
return
sx
}
ret
:=
[]
Service
{}
// with slice-tricks in sx we can prolly save this allocation (TODO)
for
i
,
s
:=
range
sx
{
if
s
.
Group
==
""
{
ret
=
append
(
ret
,
s
)
continue
}
// Disagreement on the same level
if
length
[
i
]
==
slashes
&&
s
.
Group
!=
group
{
return
sx
}
if
s
.
Group
==
group
{
ret
=
append
(
ret
,
s
)
}
}
return
ret
}
// Split255 splits a string into 255 byte chunks.
func
split255
(
s
string
)
[]
string
{
if
len
(
s
)
<
255
{
return
[]
string
{
s
}
}
sx
:=
[]
string
{}
p
,
i
:=
0
,
255
for
{
if
i
<=
len
(
s
)
{
sx
=
append
(
sx
,
s
[
p
:
i
])
}
else
{
sx
=
append
(
sx
,
s
[
p
:
])
break
}
p
,
i
=
p
+
255
,
i
+
255
}
return
sx
}
Godeps/_workspace/src/github.com/skynetservices/skydns/msg/service_test.go
0 → 100644
View file @
f0861b9e
// Copyright (c) 2015 The SkyDNS Authors. All rights reserved.
// Use of this source code is governed by The MIT License (MIT) that can be
// found in the LICENSE file.
package
msg
import
"testing"
func
TestSplit255
(
t
*
testing
.
T
)
{
xs
:=
split255
(
"abc"
)
if
len
(
xs
)
!=
1
&&
xs
[
0
]
!=
"abc"
{
t
.
Logf
(
"Failure to split abc"
)
t
.
Fail
()
}
s
:=
""
for
i
:=
0
;
i
<
255
;
i
++
{
s
+=
"a"
}
xs
=
split255
(
s
)
if
len
(
xs
)
!=
1
&&
xs
[
0
]
!=
s
{
t
.
Logf
(
"failure to split 255 char long string"
)
t
.
Logf
(
"%s %v
\n
"
,
s
,
xs
)
t
.
Fail
()
}
s
+=
"b"
xs
=
split255
(
s
)
if
len
(
xs
)
!=
2
||
xs
[
1
]
!=
"b"
{
t
.
Logf
(
"failure to split 256 char long string: %d"
,
len
(
xs
))
t
.
Logf
(
"%s %v
\n
"
,
s
,
xs
)
t
.
Fail
()
}
for
i
:=
0
;
i
<
255
;
i
++
{
s
+=
"a"
}
xs
=
split255
(
s
)
if
len
(
xs
)
!=
3
||
xs
[
2
]
!=
"a"
{
t
.
Logf
(
"failure to split 510 char long string: %d"
,
len
(
xs
))
t
.
Logf
(
"%s %v
\n
"
,
s
,
xs
)
t
.
Fail
()
}
}
func
TestGroup
(
t
*
testing
.
T
)
{
// Key are in the wrong order, but for this test it does not matter.
sx
:=
Group
(
[]
Service
{
{
Host
:
"127.0.0.1"
,
Group
:
"g1"
,
Key
:
"b/sub/dom1/skydns/test"
},
{
Host
:
"127.0.0.2"
,
Group
:
"g2"
,
Key
:
"a/dom1/skydns/test"
},
},
)
// Expecting to return the shortest key with a Group attribute.
if
len
(
sx
)
!=
1
{
t
.
Fatalf
(
"failure to group zeroth set: %v"
,
sx
)
}
if
sx
[
0
]
.
Key
!=
"a/dom1/skydns/test"
{
t
.
Fatalf
(
"failure to group zeroth set: %v, wrong Key"
,
sx
)
}
// Groups disagree, so we will not do anything.
sx
=
Group
(
[]
Service
{
{
Host
:
"server1"
,
Group
:
"g1"
,
Key
:
"region1/skydns/test"
},
{
Host
:
"server2"
,
Group
:
"g2"
,
Key
:
"region1/skydns/test"
},
},
)
if
len
(
sx
)
!=
2
{
t
.
Fatalf
(
"failure to group first set: %v"
,
sx
)
}
// Group is g1, include only the top-level one.
sx
=
Group
(
[]
Service
{
{
Host
:
"server1"
,
Group
:
"g1"
,
Key
:
"a/dom/region1/skydns/test"
},
{
Host
:
"server2"
,
Group
:
"g2"
,
Key
:
"a/subdom/dom/region1/skydns/test"
},
},
)
if
len
(
sx
)
!=
1
{
t
.
Fatalf
(
"failure to group second set: %v"
,
sx
)
}
// Groupless services must be included.
sx
=
Group
(
[]
Service
{
{
Host
:
"server1"
,
Group
:
"g1"
,
Key
:
"a/dom/region1/skydns/test"
},
{
Host
:
"server2"
,
Group
:
"g2"
,
Key
:
"a/subdom/dom/region1/skydns/test"
},
{
Host
:
"server2"
,
Group
:
""
,
Key
:
"b/subdom/dom/region1/skydns/test"
},
},
)
if
len
(
sx
)
!=
2
{
t
.
Fatalf
(
"failure to group third set: %v"
,
sx
)
}
// Empty group on the highest level: include that one also.
sx
=
Group
(
[]
Service
{
{
Host
:
"server1"
,
Group
:
"g1"
,
Key
:
"a/dom/region1/skydns/test"
},
{
Host
:
"server1"
,
Group
:
""
,
Key
:
"b/dom/region1/skydns/test"
},
{
Host
:
"server2"
,
Group
:
"g2"
,
Key
:
"a/subdom/dom/region1/skydns/test"
},
},
)
if
len
(
sx
)
!=
2
{
t
.
Fatalf
(
"failure to group fourth set: %v"
,
sx
)
}
// Empty group on the highest level: include that one also, and the rest.
sx
=
Group
(
[]
Service
{
{
Host
:
"server1"
,
Group
:
"g5"
,
Key
:
"a/dom/region1/skydns/test"
},
{
Host
:
"server1"
,
Group
:
""
,
Key
:
"b/dom/region1/skydns/test"
},
{
Host
:
"server2"
,
Group
:
"g5"
,
Key
:
"a/subdom/dom/region1/skydns/test"
},
},
)
if
len
(
sx
)
!=
3
{
t
.
Fatalf
(
"failure to group fith set: %v"
,
sx
)
}
// One group.
sx
=
Group
(
[]
Service
{
{
Host
:
"server1"
,
Group
:
"g6"
,
Key
:
"a/dom/region1/skydns/test"
},
},
)
if
len
(
sx
)
!=
1
{
t
.
Fatalf
(
"failure to group sixth set: %v"
,
sx
)
}
// No group, once service
sx
=
Group
(
[]
Service
{
{
Host
:
"server1"
,
Key
:
"a/dom/region1/skydns/test"
},
},
)
if
len
(
sx
)
!=
1
{
t
.
Fatalf
(
"failure to group seventh set: %v"
,
sx
)
}
}
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