Skip to content

Commit 147ccdd

Browse files
authored
[Feature] Add ClusterDomain config (#683)
1 parent d232d3d commit 147ccdd

32 files changed

+237
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
4+
- Add support for spec.ClusterDomain to be able to use FQDN in ArangoDB cluster communication
45

56
## [1.1.3](https://github.com/arangodb/kube-arangodb/tree/1.1.3) (2020-12-16)
67
- Add v2alpha1 API for ArangoDeployment and ArangoDeploymentReplication

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ type DeploymentSpec struct {
116116
Bootstrap BootstrapSpec `json:"bootstrap,omitempty"`
117117

118118
Timeouts *Timeouts `json:"timeouts,omitempty"`
119+
120+
ClusterDomain *string `json:"ClusterDomain,omitempty"`
119121
}
120122

121123
// GetRestoreFrom returns the restore from string or empty string if not set

pkg/apis/deployment/v1/member_status.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ type MemberStatus struct {
7171
Image *ImageInfo `json:"image,omitempty"`
7272
// Upgrade define if upgrade should be enforced during next execution
7373
Upgrade bool `json:"upgrade,omitempty"`
74+
// Endpoint definition how member should be reachable
75+
Endpoint *string `json:"endpoint,omitempty"`
7476
}
7577

7678
// Equal checks for equality
@@ -87,7 +89,8 @@ func (s MemberStatus) Equal(other MemberStatus) bool {
8789
s.ArangoVersion == other.ArangoVersion &&
8890
s.ImageID == other.ImageID &&
8991
s.Image.Equal(other.Image) &&
90-
s.Upgrade == other.Upgrade
92+
s.Upgrade == other.Upgrade &&
93+
util.CompareStringPointers(s.Endpoint, other.Endpoint)
9194
}
9295

9396
// Age returns the duration since the creation timestamp of this member.
@@ -115,6 +118,14 @@ func (s *MemberStatus) RemoveTerminationsBefore(timestamp time.Time) int {
115118
}
116119
}
117120

121+
func (s *MemberStatus) GetEndpoint(defaultEndpoint string) string {
122+
if s == nil || s.Endpoint == nil {
123+
return defaultEndpoint
124+
}
125+
126+
return *s.Endpoint
127+
}
128+
118129
// RecentTerminationsSince returns the number of terminations since the given timestamp.
119130
func (s MemberStatus) RecentTerminationsSince(timestamp time.Time) int {
120131
count := 0

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/deployment/v2alpha1/deployment_spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ type DeploymentSpec struct {
116116
Bootstrap BootstrapSpec `json:"bootstrap,omitempty"`
117117

118118
Timeouts *Timeouts `json:"timeouts,omitempty"`
119+
120+
ClusterDomain *string `json:"ClusterDomain,omitempty"`
119121
}
120122

121123
// GetRestoreFrom returns the restore from string or empty string if not set

pkg/apis/deployment/v2alpha1/external_access_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package v2alpha1
2424

2525
import (
2626
"github.com/arangodb/kube-arangodb/pkg/util/errors"
27+
2728
v1 "k8s.io/api/core/v1"
2829
)
2930

pkg/apis/deployment/v2alpha1/member_status.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ type MemberStatus struct {
7171
Image *ImageInfo `json:"image,omitempty"`
7272
// Upgrade define if upgrade should be enforced during next execution
7373
Upgrade bool `json:"upgrade,omitempty"`
74+
// Endpoint definition how member should be reachable
75+
Endpoint *string `json:"endpoint,omitempty"`
7476
}
7577

7678
// Equal checks for equality
@@ -87,7 +89,8 @@ func (s MemberStatus) Equal(other MemberStatus) bool {
8789
s.ArangoVersion == other.ArangoVersion &&
8890
s.ImageID == other.ImageID &&
8991
s.Image.Equal(other.Image) &&
90-
s.Upgrade == other.Upgrade
92+
s.Upgrade == other.Upgrade &&
93+
util.CompareStringPointers(s.Endpoint, other.Endpoint)
9194
}
9295

9396
// Age returns the duration since the creation timestamp of this member.
@@ -115,6 +118,14 @@ func (s *MemberStatus) RemoveTerminationsBefore(timestamp time.Time) int {
115118
}
116119
}
117120

121+
func (s *MemberStatus) GetEndpoint(defaultEndpoint string) string {
122+
if s == nil || s.Endpoint == nil {
123+
return defaultEndpoint
124+
}
125+
126+
return *s.Endpoint
127+
}
128+
118129
// RecentTerminationsSince returns the number of terminations since the given timestamp.
119130
func (s MemberStatus) RecentTerminationsSince(timestamp time.Time) int {
120131
count := 0

pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/client/client_cache.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ package client
2424

2525
import (
2626
"context"
27-
"fmt"
2827
"net"
2928
"strconv"
3029
"sync"
@@ -49,19 +48,15 @@ type Cache interface {
4948

5049
func NewClientCache(apiObjectGetter func() *api.ArangoDeployment, factory conn.Factory) Cache {
5150
return &cache{
52-
clients: make(map[string]driver.Client),
5351
apiObjectGetter: apiObjectGetter,
5452
factory: factory,
5553
}
5654
}
5755

5856
type cache struct {
5957
mutex sync.Mutex
60-
clients map[string]driver.Client
6158
apiObjectGetter func() *api.ArangoDeployment
6259

63-
databaseClient driver.Client
64-
6560
factory conn.Factory
6661
}
6762

@@ -75,18 +70,12 @@ func (cc *cache) extendHost(host string) string {
7570
}
7671

7772
func (cc *cache) getClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error) {
78-
key := fmt.Sprintf("%d-%s", group, id)
79-
c, found := cc.clients[key]
80-
if found {
81-
return c, nil
82-
}
73+
m, _, _ := cc.apiObjectGetter().Status.Members.ElementByID(id)
8374

84-
// Not found, create a new client
85-
c, err := cc.factory.Client(cc.extendHost(k8sutil.CreatePodDNSName(cc.apiObjectGetter(), group.AsRole(), id)))
75+
c, err := cc.factory.Client(cc.extendHost(m.GetEndpoint(k8sutil.CreatePodDNSName(cc.apiObjectGetter(), group.AsRole(), id))))
8676
if err != nil {
8777
return nil, errors.WithStack(err)
8878
}
89-
cc.clients[key] = c
9079
return c, nil
9180
}
9281

@@ -99,7 +88,6 @@ func (cc *cache) get(ctx context.Context, group api.ServerGroup, id string) (dri
9988
if _, err := client.Version(ctx); err == nil {
10089
return client, nil
10190
} else if driver.IsUnauthorized(err) {
102-
delete(cc.clients, fmt.Sprintf("%d-%s", group, id))
10391
return cc.getClient(ctx, group, id)
10492
} else {
10593
return client, nil
@@ -120,16 +108,10 @@ func (cc cache) GetAuth() conn.Auth {
120108
}
121109

122110
func (cc *cache) getDatabaseClient() (driver.Client, error) {
123-
if c := cc.databaseClient; c != nil {
124-
return c, nil
125-
}
126-
127-
// Not found, create a new client
128111
c, err := cc.factory.Client(cc.extendHost(k8sutil.CreateDatabaseClientServiceDNSName(cc.apiObjectGetter())))
129112
if err != nil {
130113
return nil, errors.WithStack(err)
131114
}
132-
cc.databaseClient = c
133115
return c, nil
134116
}
135117

@@ -142,7 +124,6 @@ func (cc *cache) getDatabase(ctx context.Context) (driver.Client, error) {
142124
if _, err := client.Version(ctx); err == nil {
143125
return client, nil
144126
} else if driver.IsUnauthorized(err) {
145-
cc.databaseClient = nil
146127
return cc.getDatabaseClient()
147128
} else {
148129
return client, nil
@@ -162,7 +143,7 @@ func (cc *cache) getAgencyClient() (agency.Agency, error) {
162143
// Not found, create a new client
163144
var dnsNames []string
164145
for _, m := range cc.apiObjectGetter().Status.Members.Agents {
165-
dnsNames = append(dnsNames, cc.extendHost(k8sutil.CreatePodDNSName(cc.apiObjectGetter(), api.ServerGroupAgents.AsRole(), m.ID)))
146+
dnsNames = append(dnsNames, cc.extendHost(m.GetEndpoint(k8sutil.CreatePodDNSName(cc.apiObjectGetter(), api.ServerGroupAgents.AsRole(), m.ID))))
166147
}
167148

168149
if len(dnsNames) == 0 {

pkg/deployment/context_impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func (d *Deployment) GetSyncServerClient(ctx context.Context, group api.ServerGr
322322
}
323323

324324
// Fetch server DNS name
325-
dnsName := k8sutil.CreatePodDNSName(d.apiObject, group.AsRole(), id)
325+
dnsName := k8sutil.CreatePodDNSNameWithDomain(d.apiObject, d.apiObject.Spec.ClusterDomain, group.AsRole(), id)
326326

327327
// Build client
328328
port := k8sutil.ArangoSyncMasterPort

0 commit comments

Comments
 (0)