From 9fd836e51f204a678f422c926de2b0af600500bd Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 20 Jul 2020 12:28:48 -0700 Subject: [PATCH] add dnsStore interface for upcoming operator webhook (#10077) --- cmd/common-main.go | 6 +++++- cmd/config/etcd/dns/etcd_dns.go | 5 +++-- cmd/config/etcd/dns/store.go | 27 +++++++++++++++++++++++++++ cmd/data-update-tracker.go | 2 +- cmd/endpoint.go | 8 ++++---- cmd/globals.go | 2 +- cmd/handler-api.go | 4 ++-- 7 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 cmd/config/etcd/dns/store.go diff --git a/cmd/common-main.go b/cmd/common-main.go index 05f74bcd4..3effc99bd 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -223,7 +223,11 @@ func handleCommonEnvVars() { } else { // Add found interfaces IP address to global domain IPS, // loopback addresses will be naturally dropped. - updateDomainIPs(mustGetLocalIP4()) + domainIPs := mustGetLocalIP4() + for _, host := range globalEndpoints.Hostnames() { + domainIPs.Add(host) + } + updateDomainIPs(domainIPs) } // In place update is true by default if the MINIO_UPDATE is not set diff --git a/cmd/config/etcd/dns/etcd_dns.go b/cmd/config/etcd/dns/etcd_dns.go index eac67c0e9..371be9c83 100644 --- a/cmd/config/etcd/dns/etcd_dns.go +++ b/cmd/config/etcd/dns/etcd_dns.go @@ -48,8 +48,9 @@ func newCoreDNSMsg(ip string, port string, ttl uint32, t time.Time) ([]byte, err } // Close closes the internal etcd client and cannot be used further -func (c *CoreDNS) Close() { +func (c *CoreDNS) Close() error { c.etcdClient.Close() + return nil } // List - Retrieves list of DNS entries for the domain. @@ -259,7 +260,7 @@ func CoreDNSPath(prefix string) Option { } // NewCoreDNS - initialize a new coreDNS set/unset values. -func NewCoreDNS(cfg clientv3.Config, setters ...Option) (*CoreDNS, error) { +func NewCoreDNS(cfg clientv3.Config, setters ...Option) (Store, error) { etcdClient, err := clientv3.New(cfg) if err != nil { return nil, err diff --git a/cmd/config/etcd/dns/store.go b/cmd/config/etcd/dns/store.go new file mode 100644 index 000000000..aa0bfda21 --- /dev/null +++ b/cmd/config/etcd/dns/store.go @@ -0,0 +1,27 @@ +/* + * MinIO Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dns + +// Store dns record store +type Store interface { + Put(bucket string) error + Get(bucket string) ([]SrvRecord, error) + Delete(bucket string) error + List() (map[string][]SrvRecord, error) + DeleteRecord(record SrvRecord) error + Close() error +} diff --git a/cmd/data-update-tracker.go b/cmd/data-update-tracker.go index 1b59f328f..7202b54a9 100644 --- a/cmd/data-update-tracker.go +++ b/cmd/data-update-tracker.go @@ -206,7 +206,7 @@ func (d *dataUpdateTracker) load(ctx context.Context, drives ...string) { continue } err = d.deserialize(f, d.Saved) - if err != nil && err != io.EOF { + if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { logger.LogIf(ctx, err) } f.Close() diff --git a/cmd/endpoint.go b/cmd/endpoint.go index 725d3659a..c174ce8ee 100644 --- a/cmd/endpoint.go +++ b/cmd/endpoint.go @@ -239,15 +239,15 @@ func (l EndpointZones) NEndpoints() (count int) { return count } -// Hosts - returns list of unique hosts -func (l EndpointZones) Hosts() []string { +// Hostnames - returns list of unique hostnames +func (l EndpointZones) Hostnames() []string { foundSet := set.NewStringSet() for _, ep := range l { for _, endpoint := range ep.Endpoints { - if foundSet.Contains(endpoint.Host) { + if foundSet.Contains(endpoint.Hostname()) { continue } - foundSet.Add(endpoint.Host) + foundSet.Add(endpoint.Hostname()) } } return foundSet.ToSlice() diff --git a/cmd/globals.go b/cmd/globals.go index 9f0f34ec1..179cf101d 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -234,7 +234,7 @@ var ( globalBucketFederation bool // Allocated DNS config wrapper over etcd client. - globalDNSConfig *dns.CoreDNS + globalDNSConfig dns.Store // GlobalKMS initialized KMS configuration GlobalKMS crypto.KMS diff --git a/cmd/handler-api.go b/cmd/handler-api.go index f946a4391..769f4961c 100644 --- a/cmd/handler-api.go +++ b/cmd/handler-api.go @@ -44,8 +44,8 @@ func (t *apiConfig) init(cfg api.Config) { } apiRequestsMax := cfg.APIRequestsMax - if len(globalEndpoints.Hosts()) > 0 { - apiRequestsMax /= len(globalEndpoints.Hosts()) + if len(globalEndpoints.Hostnames()) > 0 { + apiRequestsMax /= len(globalEndpoints.Hostnames()) } t.requestsPool = make(chan struct{}, apiRequestsMax)