From 8347d27afa18b6c76d4a8bb85ad56a2e60927018 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Larsen Date: Thu, 23 May 2019 22:29:55 +0200 Subject: [PATCH] *: allow specifying Cluster Domain for clientURLs(#2082) Allow specifying Cluster Domain for clientURLs This allows setting the ClusterDomain config in the PodPolicy. The cluster domain is used as a suffix in the Client URLs for the etcd members. The ability to set a custom cluster domain is desirable when running in clusters with a custom DNS configuration. Signed-off-by: Mikkel Oscar Lyderik Larsen --- CHANGELOG.md | 2 ++ pkg/apis/etcd/v1beta2/cluster.go | 5 +++++ pkg/cluster/cluster.go | 3 +++ pkg/cluster/member.go | 7 ++++++- pkg/controller/restore-operator/sync.go | 3 +++ pkg/util/etcdutil/member.go | 5 ++++- 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 948409c37..941712903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Added +- Added `spec.Pod.ClusterDomain` to explicitly set the cluster domain used for the etcd member URLs. [#2082](https://github.com/coreos/etcd-operator/pull/2082) + ### Changed ### Removed diff --git a/pkg/apis/etcd/v1beta2/cluster.go b/pkg/apis/etcd/v1beta2/cluster.go index ddfe0cf62..889534b6b 100644 --- a/pkg/apis/etcd/v1beta2/cluster.go +++ b/pkg/apis/etcd/v1beta2/cluster.go @@ -157,6 +157,11 @@ type PodPolicy struct { // reverse DNS lookup its IP given the hostname. // The default is to wait indefinitely and has a vaule of 0. DNSTimeoutInSecond int64 `json:"DNSTimeoutInSecond,omitempty"` + + // ClusterDomain is the cluster domain to use for member URLs E.g. + // '.cluster.local'. + // The default is to not set a cluster domain explicitly. + ClusterDomain string `json:"ClusterDomain"` } // TODO: move this to initializer diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 2f8322a37..fe4f297f4 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -316,6 +316,9 @@ func (c *Cluster) startSeedMember() error { SecurePeer: c.isSecurePeer(), SecureClient: c.isSecureClient(), } + if c.cluster.Spec.Pod != nil { + m.ClusterDomain = c.cluster.Spec.Pod.ClusterDomain + } ms := etcdutil.NewMemberSet(m) if err := c.createPod(ms, m, "new"); err != nil { return fmt.Errorf("failed to create seed member (%s): %v", m.Name, err) diff --git a/pkg/cluster/member.go b/pkg/cluster/member.go index c59688bd9..93b4a412e 100644 --- a/pkg/cluster/member.go +++ b/pkg/cluster/member.go @@ -51,12 +51,17 @@ func (c *Cluster) updateMembers(known etcdutil.MemberSet) error { func (c *Cluster) newMember() *etcdutil.Member { name := k8sutil.UniqueMemberName(c.cluster.Name) - return &etcdutil.Member{ + m := &etcdutil.Member{ Name: name, Namespace: c.cluster.Namespace, SecurePeer: c.isSecurePeer(), SecureClient: c.isSecureClient(), } + + if c.cluster.Spec.Pod != nil { + m.ClusterDomain = c.cluster.Spec.Pod.ClusterDomain + } + return m } func podsToMemberSet(pods []*v1.Pod, sc bool) etcdutil.MemberSet { diff --git a/pkg/controller/restore-operator/sync.go b/pkg/controller/restore-operator/sync.go index 6d59fee7c..d29761119 100644 --- a/pkg/controller/restore-operator/sync.go +++ b/pkg/controller/restore-operator/sync.go @@ -217,6 +217,9 @@ func (r *Restore) createSeedMember(ec *api.EtcdCluster, svcAddr, clusterName str SecurePeer: ec.Spec.TLS.IsSecurePeer(), SecureClient: ec.Spec.TLS.IsSecureClient(), } + if ec.Spec.Pod != nil { + m.ClusterDomain = ec.Spec.Pod.ClusterDomain + } ms := etcdutil.NewMemberSet(m) backupURL := backupapi.BackupURLForRestore("http", svcAddr, clusterName) ec.SetDefaults() diff --git a/pkg/util/etcdutil/member.go b/pkg/util/etcdutil/member.go index 9e89977f3..8dc74ede4 100644 --- a/pkg/util/etcdutil/member.go +++ b/pkg/util/etcdutil/member.go @@ -33,10 +33,13 @@ type Member struct { SecurePeer bool SecureClient bool + + // ClusterDomain is the DNS name of the cluster. E.g. .cluster.local. + ClusterDomain string } func (m *Member) Addr() string { - return fmt.Sprintf("%s.%s.%s.svc", m.Name, clusterNameFromMemberName(m.Name), m.Namespace) + return fmt.Sprintf("%s.%s.%s.svc%s", m.Name, clusterNameFromMemberName(m.Name), m.Namespace, m.ClusterDomain) } // ClientURL is the client URL for this member