Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
*: allow specifying Cluster Domain for clientURLs(#2082)
Browse files Browse the repository at this point in the history
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 <mikkel.larsen@zalando.de>
  • Loading branch information
mikkeloscar authored and hasbro17 committed May 23, 2019
1 parent c3a9fa0 commit 8347d27
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/etcd/v1beta2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion pkg/cluster/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/restore-operator/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion pkg/util/etcdutil/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8347d27

Please sign in to comment.