本文整理汇总了Golang中github.com/skynetservices/skydns/msg.Path函数的典型用法代码示例。如果您正苦于以下问题:Golang Path函数的具体用法?Golang Path怎么用?Golang Path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: removeDNS
// Removes 'subdomain' from etcd.
func (ks *kube2sky) removeDNS(subdomain string) error {
glog.V(2).Infof("Removing %s from DNS", subdomain)
resp, err := ks.etcdClient.RawGet(skymsg.Path(subdomain), false, true)
if err != nil {
return err
}
if resp.StatusCode == http.StatusNotFound {
glog.V(2).Infof("Subdomain %q does not exist in etcd", subdomain)
return nil
}
_, err = ks.etcdClient.Delete(skymsg.Path(subdomain), true)
return err
}
示例2: ReverseRecord
// ReverseRecord implements the SkyDNS Backend interface and returns standard records for
// a name.
func (b *ServiceResolver) ReverseRecord(name string) (*msg.Service, error) {
clusterIP, ok := extractIP(name)
if !ok {
return nil, fmt.Errorf("does not support reverse lookup with %s", name)
}
svc, err := b.accessor.ServiceByClusterIP(clusterIP)
if err != nil {
return nil, err
}
port := 0
if len(svc.Spec.Ports) > 0 {
port = int(svc.Spec.Ports[0].Port)
}
hostName := buildDNSName(b.base, "svc", svc.Namespace, svc.Name)
return &msg.Service{
Host: hostName,
Port: port,
Priority: 10,
Weight: 10,
Ttl: 30,
Key: msg.Path(name),
}, nil
}
示例3: ReverseRecord
// ReverseRecord implements the SkyDNS Backend interface and returns standard records for
// a name.
func (b *ServiceResolver) ReverseRecord(name string) (*msg.Service, error) {
portalIP, ok := extractIP(name)
if !ok {
return nil, fmt.Errorf("does not support reverse lookup with %s", name)
}
svc, err := b.accessor.ServiceByPortalIP(portalIP)
if err != nil {
return nil, err
}
port := 0
if len(svc.Spec.Ports) > 0 {
port = svc.Spec.Ports[0].Port
}
return &msg.Service{
Host: fmt.Sprintf("%s.%s.svc.%s", svc.Name, svc.Namespace, b.base),
Port: port,
Priority: 10,
Weight: 10,
Ttl: 30,
Text: "",
Key: msg.Path(name),
}, nil
}
示例4: NewDomain
func NewDomain(prefix string) (d *Domain) {
d = &Domain{}
msg.PathPrefix = "astralboot"
d.prefix = msg.Path(prefix)
d.entries = make(map[string]*msg.Service)
return d
}
示例5: addDNS
func addDNS(record string, service *kapi.Service, etcdClient *etcd.Client) error {
// if PortalIP is not set, a DNS entry should not be created
if !kapi.IsServiceIPSet(service) {
log.Printf("Skipping dns record for headless service: %s\n", service.Name)
return nil
}
for i := range service.Spec.Ports {
svc := skymsg.Service{
Host: service.Spec.PortalIP,
Port: service.Spec.Ports[i].Port,
Priority: 10,
Weight: 10,
Ttl: 30,
}
b, err := json.Marshal(svc)
if err != nil {
return err
}
// Set with no TTL, and hope that kubernetes events are accurate.
log.Printf("Setting DNS record: %v -> %s:%d\n", record, service.Spec.PortalIP, service.Spec.Ports[i].Port)
_, err = etcdClient.Set(skymsg.Path(record), string(b), uint64(0))
if err != nil {
return err
}
}
return nil
}
示例6: Records
func (g *Backendv3) Records(name string, exact bool) ([]msg.Service, error) {
path, star := msg.PathWithWildcard(name)
r, err := g.get(path, true)
if err != nil {
return nil, err
}
segments := strings.Split(msg.Path(name), "/")
return g.loopNodes(r.Kvs, segments, star, nil)
}
示例7: NSRecords
// NSRecords returns NS records from etcd.
func (s *server) NSRecords(q dns.Question, name string) (records []dns.RR, extra []dns.RR, err error) {
path, star := msg.PathWithWildcard(name)
r, err := get(s.client, path, true)
if err != nil {
return nil, nil, err
}
if !r.Node.Dir { // single element
serv := new(msg.Service)
if err := json.Unmarshal([]byte(r.Node.Value), serv); err != nil {
s.config.log.Infof("failed to parse json: %s", err.Error())
return nil, nil, err
}
ip := net.ParseIP(serv.Host)
ttl := s.calculateTtl(r.Node, serv)
serv.Key = r.Node.Key
serv.Ttl = ttl
switch {
case ip == nil:
return nil, nil, fmt.Errorf("NS record must be an IP address")
case ip.To4() != nil:
serv.Host = msg.Domain(serv.Key)
records = append(records, serv.NewNS(q.Name, serv.Host))
extra = append(extra, serv.NewA(serv.Host, ip.To4()))
case ip.To4() == nil:
serv.Host = msg.Domain(serv.Key)
records = append(records, serv.NewNS(q.Name, serv.Host))
extra = append(extra, serv.NewAAAA(serv.Host, ip.To16()))
}
return records, extra, nil
}
sx, err := s.loopNodes(&r.Node.Nodes, strings.Split(msg.Path(name), "/"), star, nil)
if err != nil || len(sx) == 0 {
return nil, nil, err
}
for _, serv := range sx {
ip := net.ParseIP(serv.Host)
switch {
case ip == nil:
return nil, nil, fmt.Errorf("NS record must be an IP address")
case ip.To4() != nil:
serv.Host = msg.Domain(serv.Key)
records = append(records, serv.NewNS(q.Name, serv.Host))
extra = append(extra, serv.NewA(serv.Host, ip.To4()))
case ip.To4() == nil:
serv.Host = msg.Domain(serv.Key)
records = append(records, serv.NewNS(q.Name, serv.Host))
extra = append(extra, serv.NewAAAA(serv.Host, ip.To16()))
}
}
return records, extra, nil
}
示例8: Records
func (g *Backend) Records(name string, exact bool) ([]msg.Service, error) {
path, star := msg.PathWithWildcard(name)
r, err := g.get(path, true)
if err != nil {
return nil, err
}
segments := strings.Split(msg.Path(name), "/")
switch {
case exact && r.Node.Dir:
return nil, nil
case r.Node.Dir:
return g.loopNodes(r.Node.Nodes, segments, star, nil)
default:
return g.loopNodes([]*etcd.Node{r.Node}, segments, false, nil)
}
}
示例9: addDNS
func (ksync *KubernetesSync) addDNS(service string, info *serviceInfo) error {
// ADD to SkyDNS registry
svc := msg.Service{
Host: info.portalIP.String(),
Port: info.portalPort,
Priority: 10,
Weight: 10,
Ttl: 30,
}
b, err := json.Marshal(svc)
//Set with no TTL, and hope that kubernetes events are accurate.
log.Printf("setting dns record: %v\n", service)
_, err = ksync.eclient.Set(msg.Path(service), string(b), uint64(0))
return err
}
示例10: addDNS
func addDNS(record string, service *kapi.Service, etcdClient *etcd.Client) error {
svc := skymsg.Service{
Host: service.Spec.PortalIP,
Port: service.Spec.Port,
Priority: 10,
Weight: 10,
Ttl: 30,
}
b, err := json.Marshal(svc)
if err != nil {
return err
}
// Set with no TTL, and hope that kubernetes events are accurate.
log.Printf("Setting dns record: %v -> %s:%d\n", record, service.Spec.PortalIP, service.Spec.Port)
_, err = etcdClient.Set(skymsg.Path(record), string(b), uint64(0))
return err
}
示例11: setEntry
// setEntry creates the entire path if it doesn't already exist in the cache,
// then sets the given service record under the given key. The path this entry
// would have occupied in an etcd datastore is computed from the given fqdn and
// stored as the "Key" of the skydns service; this is only required because
// skydns expects the service record to contain a key in a specific format
// (presumably for legacy compatibility). Note that the fqnd string typically
// contains both the key and all elements in the path.
func (cache *TreeCache) setEntry(key string, val *skymsg.Service, fqdn string, path ...string) {
// TODO: Consolidate setEntry and setSubCache into a single method with a
// type switch.
// TODO: Insted of passing the fqdn as an argument, we can reconstruct
// it from the path, provided callers always pass the full path to the
// object. This is currently *not* the case, since callers first create
// a new, empty node, populate it, then parent it under the right path.
// So we don't know the full key till the final parenting operation.
node := cache.ensureChildNode(path...)
// This key is used to construct the "target" for SRV record lookups.
// For normal service/endpoint lookups, this will result in a key like:
// /skydns/local/cluster/svc/svcNS/svcName/record-hash
// but for headless services that govern pods requesting a specific
// hostname (as used by petset), this will end up being:
// /skydns/local/cluster/svc/svcNS/svcName/pod-hostname
val.Key = skymsg.Path(fqdn)
node.Entries[key] = val
}
示例12: ReverseRecord
func (g *Backendv3) ReverseRecord(name string) (*msg.Service, error) {
path, star := msg.PathWithWildcard(name)
if star {
return nil, fmt.Errorf("reverse can not contain wildcards")
}
r, err := g.get(path, true)
if err != nil {
return nil, err
}
segments := strings.Split(msg.Path(name), "/")
records, err := g.loopNodes(r.Kvs, segments, false, nil)
if err != nil {
return nil, err
}
if len(records) != 1 {
return nil, fmt.Errorf("must be only one service record")
}
return &records[0], nil
}
示例13: ReverseRecord
func (g *Backend) ReverseRecord(name string, rmtIP net.IP) (*msg.Service, error) {
path, star := msg.PathWithWildcard(name)
if star {
return nil, fmt.Errorf("reverse can not contain wildcards")
}
r, err := g.get(path, true)
if err != nil {
return nil, err
}
if r.Node.Dir {
return nil, fmt.Errorf("reverse must not be a directory")
}
segments := strings.Split(msg.Path(name), "/")
records, err := g.loopNodes(&etcd.Nodes{r.Node}, segments, false, nil, rmtIP)
if err != nil {
return nil, err
}
if len(records) != 1 {
return nil, fmt.Errorf("must be only one service record")
}
return &records[0], nil
}
示例14: Records
func (g *Backend) Records(name string, exact bool, rmtIP net.IP) ([]msg.Service, error) {
path, star := msg.PathWithWildcard(name)
r, err := g.get(path, true)
if err != nil {
return nil, err
}
segments := strings.Split(msg.Path(name), "/")
switch {
case exact && r.Node.Dir:
return nil, nil
case r.Node.Dir:
if _, err := g.get(fmt.Sprintf("%s/.wildcards", path), true); err != nil {
return nil, err
}
if r2, err := g.get(fmt.Sprintf("%s/.self", path), true); err != nil {
return g.loopNodes(&r.Node.Nodes, segments, star, nil, rmtIP)
} else {
return g.loopNodes(&etcd.Nodes{r2.Node}, segments, false, nil, rmtIP)
}
default:
return g.loopNodes(&etcd.Nodes{r.Node}, segments, false, nil, rmtIP)
}
}
示例15: removeDNS
func removeDNS(record string, etcdClient *etcd.Client) error {
log.Printf("Removing %s from DNS", record)
_, err := etcdClient.Delete(skymsg.Path(record), true)
return err
}