From 3498f5b0ec415d6fb529bde12184026a89dc9fef Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 12 Dec 2018 10:47:03 -0800 Subject: [PATCH] List exact DNS entries for a requested bucketName (#6936) Currently we would end up considering common prefix buckets to be part of the same DNS service record, which leads to Minio server wrongly forwarding the records to incorrect IPs. --- pkg/dns/etcd_dns.go | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/pkg/dns/etcd_dns.go b/pkg/dns/etcd_dns.go index cdfb29a42..216208714 100644 --- a/pkg/dns/etcd_dns.go +++ b/pkg/dns/etcd_dns.go @@ -85,16 +85,28 @@ func (c *coreDNS) list(key string) ([]SrvRecord, error) { } srvRecord.Key = strings.TrimPrefix(string(n.Key), key) srvRecord.Key = strings.TrimSuffix(srvRecord.Key, srvRecord.Host) - srvRecords = append(srvRecords, srvRecord) + // SRV records are stored in the following form + // /skydns/net/miniocloud/bucket1, so this function serves multiple + // purposes basically when we do a Get(bucketName) this function + // should return a single DNS record for any input 'bucketName'. + // + // In all other situations when we want to list all DNS records, + // which is handled in the else clause. + if key != msg.Path(fmt.Sprintf(".%s.", c.domainName), defaultPrefixPath) { + if srvRecord.Key == "/" { + srvRecords = append(srvRecords, srvRecord) + } + } else { + srvRecords = append(srvRecords, srvRecord) + } } - if srvRecords != nil { - sort.Slice(srvRecords, func(i int, j int) bool { - return srvRecords[i].Key < srvRecords[j].Key - }) - } else { + if len(srvRecords) == 0 { return nil, ErrNoEntriesFound } + sort.Slice(srvRecords, func(i int, j int) bool { + return srvRecords[i].Key < srvRecords[j].Key + }) return srvRecords, nil } @@ -123,9 +135,18 @@ func (c *coreDNS) Put(bucket string) error { // Removes DNS entries added in Put(). func (c *coreDNS) Delete(bucket string) error { key := msg.Path(fmt.Sprintf("%s.%s.", bucket, c.domainName), defaultPrefixPath) - ctx, cancel := context.WithTimeout(context.Background(), defaultContextTimeout) - _, err := c.etcdClient.Delete(ctx, key) - defer cancel() + srvRecords, err := c.list(key) + if err != nil { + return err + } + for _, record := range srvRecords { + dctx, dcancel := context.WithTimeout(context.Background(), defaultContextTimeout) + if _, err = c.etcdClient.Delete(dctx, key+"/"+record.Host); err != nil { + dcancel() + return err + } + dcancel() + } return err }