mirror of
https://github.com/hanzoai/volume.git
synced 2026-10-01 00:48:00 +00:00
A fork of Rancher's local-path-provisioner at v0.0.36. The behaviour is unchanged and deliberately so — a directory on the node a pod lands on is the right thing for a disk. What changes is identity. The provisioner answers to hanzo.ai/volume rather than rancher.io/local-path. That is not branding: two provisioners sharing one name race for the same claims, and a stock k3s carries the upstream one, so a cluster running both would settle our storage by chance. Data lives at /var/lib/hanzo/volume, so reading a Hanzo cluster does not mean learning another vendor's directory. Apache-2.0 as published, unaltered, with Rancher's attribution in NOTICE. The README says what this is not: durability. A volume here dies with its node. That is hanzoai/replicate's question, one layer up, and keeping the two apart is what lets the disk stay this simple.
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package dns
|
|
|
|
// Dedup removes identical RRs from rrs. It preserves the original ordering.
|
|
// The lowest TTL of any duplicates is used in the remaining one. Dedup modifies
|
|
// rrs.
|
|
// m is used to store the RRs temporary. If it is nil a new map will be allocated.
|
|
func Dedup(rrs []RR, m map[string]RR) []RR {
|
|
|
|
if m == nil {
|
|
m = make(map[string]RR)
|
|
}
|
|
// Save the keys, so we don't have to call normalizedString twice.
|
|
keys := make([]*string, 0, len(rrs))
|
|
|
|
for _, r := range rrs {
|
|
key := normalizedString(r)
|
|
keys = append(keys, &key)
|
|
if mr, ok := m[key]; ok {
|
|
// Shortest TTL wins.
|
|
rh, mrh := r.Header(), mr.Header()
|
|
if mrh.Ttl > rh.Ttl {
|
|
mrh.Ttl = rh.Ttl
|
|
}
|
|
continue
|
|
}
|
|
|
|
m[key] = r
|
|
}
|
|
// If the length of the result map equals the amount of RRs we got,
|
|
// it means they were all different. We can then just return the original rrset.
|
|
if len(m) == len(rrs) {
|
|
return rrs
|
|
}
|
|
|
|
j := 0
|
|
for i, r := range rrs {
|
|
// If keys[i] lives in the map, we should copy and remove it.
|
|
if _, ok := m[*keys[i]]; ok {
|
|
delete(m, *keys[i])
|
|
rrs[j] = r
|
|
j++
|
|
}
|
|
|
|
if len(m) == 0 {
|
|
break
|
|
}
|
|
}
|
|
|
|
return rrs[:j]
|
|
}
|
|
|
|
// normalizedString returns a normalized string from r. The TTL
|
|
// is removed and the domain name is lowercased. We go from this:
|
|
// DomainName<TAB>TTL<TAB>CLASS<TAB>TYPE<TAB>RDATA to:
|
|
// lowercasename<TAB>CLASS<TAB>TYPE...
|
|
func normalizedString(r RR) string {
|
|
// A string Go DNS makes has: domainname<TAB>TTL<TAB>...
|
|
b := []byte(r.String())
|
|
|
|
// find the first non-escaped tab, then another, so we capture where the TTL lives.
|
|
esc := false
|
|
ttlStart, ttlEnd := 0, 0
|
|
for i := 0; i < len(b) && ttlEnd == 0; i++ {
|
|
switch {
|
|
case b[i] == '\\':
|
|
esc = !esc
|
|
case b[i] == '\t' && !esc:
|
|
if ttlStart == 0 {
|
|
ttlStart = i
|
|
continue
|
|
}
|
|
if ttlEnd == 0 {
|
|
ttlEnd = i
|
|
}
|
|
case b[i] >= 'A' && b[i] <= 'Z' && !esc:
|
|
b[i] += 32
|
|
default:
|
|
esc = false
|
|
}
|
|
}
|
|
|
|
// remove TTL.
|
|
copy(b[ttlStart:], b[ttlEnd:])
|
|
cut := ttlEnd - ttlStart
|
|
return string(b[:len(b)-cut])
|
|
}
|