From 4c048963dc05edf642538b8bc71588f475854ac6 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 17 Apr 2019 17:29:49 -0700 Subject: [PATCH] etcd: Handle create buckets with common prefixes properly (#7556) common prefixes in bucket name if already created are disallowed when etcd is configured due to the prefix matching issue. Make sure that when we look for bucket we are only interested in exact bucket name not the prefix. --- cmd/bucket-handlers.go | 8 ++++---- pkg/dns/etcd_dns.go | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index 63bd92e61..33616151a 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -774,10 +774,6 @@ func (api objectAPIHandlers) DeleteBucketHandler(w http.ResponseWriter, r *http. return } - globalNotificationSys.RemoveNotification(bucket) - globalPolicySys.Remove(bucket) - globalNotificationSys.DeleteBucket(ctx, bucket) - if globalDNSConfig != nil { if err := globalDNSConfig.Delete(bucket); err != nil { // Deleting DNS entry failed, attempt to create the bucket again. @@ -787,6 +783,10 @@ func (api objectAPIHandlers) DeleteBucketHandler(w http.ResponseWriter, r *http. } } + globalNotificationSys.RemoveNotification(bucket) + globalPolicySys.Remove(bucket) + globalNotificationSys.DeleteBucket(ctx, bucket) + // Write success response. writeSuccessNoContent(w) } diff --git a/pkg/dns/etcd_dns.go b/pkg/dns/etcd_dns.go index aa4cc61f7..ec2e1f02e 100644 --- a/pkg/dns/etcd_dns.go +++ b/pkg/dns/etcd_dns.go @@ -70,7 +70,20 @@ func (c *coreDNS) Get(bucket string) ([]SrvRecord, error) { if err != nil { return nil, err } - srvRecords = append(srvRecords, records...) + // Make sure we have record.Key is empty + // this can only happen when record.Key + // has bucket entry with exact prefix + // match any record.Key which do not + // match the prefixes we skip them. + for _, record := range records { + if record.Key != "" { + continue + } + srvRecords = append(srvRecords, records...) + } + } + if len(srvRecords) == 0 { + return nil, ErrNoEntriesFound } return srvRecords, nil }