mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 09:43:17 -04:00 
			
		
		
		
	| @@ -4,6 +4,7 @@ package etcd | |||||||
| import ( | import ( | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"strings" | 	"strings" | ||||||
|  | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/miekg/coredns/middleware" | 	"github.com/miekg/coredns/middleware" | ||||||
| 	"github.com/miekg/coredns/middleware/etcd/msg" | 	"github.com/miekg/coredns/middleware/etcd/msg" | ||||||
| @@ -47,7 +48,9 @@ func (g Etcd) Records(name string, exact bool) ([]msg.Service, error) { | |||||||
| // Get is a wrapper for client.Get that uses SingleInflight to suppress multiple outstanding queries. | // Get is a wrapper for client.Get that uses SingleInflight to suppress multiple outstanding queries. | ||||||
| func (g Etcd) Get(path string, recursive bool) (*etcdc.Response, error) { | func (g Etcd) Get(path string, recursive bool) (*etcdc.Response, error) { | ||||||
| 	resp, err := g.Inflight.Do(path, func() (interface{}, error) { | 	resp, err := g.Inflight.Do(path, func() (interface{}, error) { | ||||||
| 		r, e := g.Client.Get(g.Ctx, path, &etcdc.GetOptions{Sort: false, Recursive: recursive}) | 		ctx, cancel := context.WithTimeout(g.Ctx, etcdTimeout) | ||||||
|  | 		defer cancel() | ||||||
|  | 		r, e := g.Client.Get(ctx, path, &etcdc.GetOptions{Sort: false, Recursive: recursive}) | ||||||
| 		if e != nil { | 		if e != nil { | ||||||
| 			return nil, e | 			return nil, e | ||||||
| 		} | 		} | ||||||
| @@ -145,8 +148,9 @@ func isEtcdNameError(err error) bool { | |||||||
| } | } | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
| 	priority   = 10  // default priority when nothing is set | 	priority    = 10  // default priority when nothing is set | ||||||
| 	ttl        = 300 // default ttl when nothing is set | 	ttl         = 300 // default ttl when nothing is set | ||||||
| 	minTtl     = 60 | 	minTtl      = 60 | ||||||
| 	hostmaster = "hostmaster" | 	hostmaster  = "hostmaster" | ||||||
|  | 	etcdTimeout = 5 * time.Second | ||||||
| ) | ) | ||||||
|   | |||||||
| @@ -37,7 +37,7 @@ const ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| 	ctx = context.TODO() | 	ctx, _ = context.WithTimeout(ctx.Background(), etcdTimeout) | ||||||
|  |  | ||||||
| 	etcdCfg := etcdc.Config{ | 	etcdCfg := etcdc.Config{ | ||||||
| 		Endpoints: []string{"http://localhost:2379"}, | 		Endpoints: []string{"http://localhost:2379"}, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user