1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Cluster IP communication (#728)

This commit is contained in:
Adam Janikowski 2021-05-18 14:26:32 +02:00 committed by GitHub
parent e3ac5e6039
commit 16614a2334
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 493 additions and 133 deletions

View file

@ -1,6 +1,7 @@
# Change Log
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- Add IP, DNS, ShortDNS, HeadlessService (Default) communication methods
## [1.1.8](https://github.com/arangodb/kube-arangodb/tree/1.1.8) (2021-04-21)
- Prevent Single member recreation

View file

@ -229,7 +229,7 @@ dashboard/assets.go: $(DASHBOARDSOURCES) $(DASHBOARDDIR)/Dockerfile.build
-v $(DASHBOARDDIR)/public:/usr/code/public:ro \
-v $(DASHBOARDDIR)/src:/usr/code/src:ro \
$(DASHBOARDBUILDIMAGE)
go run github.com/jessevdk/go-assets-builder -s /dashboard/build/ -o dashboard/assets.go -p dashboard dashboard/build
$(GOPATH)/bin/go-assets-builder -s /dashboard/build/ -o dashboard/assets.go -p dashboard dashboard/build
.PHONY: bin
bin: $(BIN)
@ -418,6 +418,8 @@ tools: update-vendor
@go get golang.org/x/tools/cmd/goimports@0bb7e5c47b1a31f85d4f173edc878a8e049764a5
@echo ">> Fetching license check"
@go get github.com/google/addlicense@6d92264d717064f28b32464f0f9693a5b4ef0239
@echo ">> Fetching GO Assets Builder"
@go get github.com/jessevdk/go-assets-builder@b8483521738fd2198ecfc378067a4e8a6079f8e5
.PHONY: vendor
vendor:

File diff suppressed because one or more lines are too long

6
go.mod
View file

@ -3,7 +3,7 @@ module github.com/arangodb/kube-arangodb
go 1.16
replace (
github.com/arangodb/go-driver => github.com/arangodb/go-driver v0.0.0-20200617115956-9dac4c7fed22
github.com/arangodb/go-driver => github.com/arangodb/go-driver v0.0.0-20210518064911-4985e8be3d90
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring => github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.46.0
github.com/prometheus-operator/prometheus-operator/pkg/client => github.com/prometheus-operator/prometheus-operator/pkg/client v0.46.0
github.com/stretchr/testify => github.com/stretchr/testify v1.5.1
@ -42,6 +42,7 @@ require (
github.com/jessevdk/go-assets v0.0.0-20160921144138-4f4301a06e15
github.com/jessevdk/go-assets-builder v0.0.0-20130903091706-b8483521738f // indirect
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/json-iterator/go v1.1.10
github.com/julienschmidt/httprouter v1.3.0
github.com/kevinburke/rest v0.0.0-20210222204520-f7a2e216372f // indirect
github.com/magiconair/properties v1.8.0
@ -52,7 +53,7 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/client v0.0.0-00010101000000-000000000000
github.com/prometheus/client_golang v1.7.1
github.com/robfig/cron v1.2.0
github.com/rs/zerolog v1.14.3
github.com/rs/zerolog v1.19.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
@ -60,7 +61,6 @@ require (
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 // indirect
github.com/voxelbrain/goptions v0.0.0-20180630082107-58cddc247ea2 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 // indirect
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57
golang.org/x/tools v0.1.1-0.20210504181558-0bb7e5c47b1a // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect

12
go.sum
View file

@ -52,6 +52,10 @@ github.com/arangodb/arangosync-client v0.6.3 h1:CJL9IxjCNVci2HNuWncZdVzHBeYTz0Ce
github.com/arangodb/arangosync-client v0.6.3/go.mod h1:C0DmhtoPKJGm2PO18FrfZf4mVWcG7qW2YPBTFMR2P1g=
github.com/arangodb/go-driver v0.0.0-20200617115956-9dac4c7fed22 h1:3Ken6Y1Qs+VLCTEiv1+807Gx2ToiuRCo8Dd1mPE5FC0=
github.com/arangodb/go-driver v0.0.0-20200617115956-9dac4c7fed22/go.mod h1:JG79qtPYRxUB6CdGWSH1XwpolSBjthuZX+Iaz/H38rA=
github.com/arangodb/go-driver v0.0.0-20210517114204-8cc084268066 h1:NneOFWxfa7rhNXIfEYWgxytudmgj2KPZfYSnKXSVGcw=
github.com/arangodb/go-driver v0.0.0-20210517114204-8cc084268066/go.mod h1:3NUekcRLpgheFIGEwcOvxilEW73MV1queNKW58k7sdc=
github.com/arangodb/go-driver v0.0.0-20210518064911-4985e8be3d90 h1:NMnMsS32jOF+e0v+MLXlgRJM7ejSAXxHg1UDv1q417I=
github.com/arangodb/go-driver v0.0.0-20210518064911-4985e8be3d90/go.mod h1:3NUekcRLpgheFIGEwcOvxilEW73MV1queNKW58k7sdc=
github.com/arangodb/go-upgrade-rules v0.0.0-20180809110947-031b4774ff21 h1:+W7D5ttxi/Ygh/39vialtypE23p9KI7P0J2qtoqUV4w=
github.com/arangodb/go-upgrade-rules v0.0.0-20180809110947-031b4774ff21/go.mod h1:RkPIG6JJ2pcJUoymc18NxAJGraZd+iAEVnOTDjZey/w=
github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e h1:Xg+hGrY2LcQBbxd0ZFdbGSyRKTYMZCfBbw/pMJFOk1g=
@ -226,6 +230,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/addlicense v0.0.0-20200817051935-6f4cd4aacc89/go.mod h1:EMjYTRimagHs1FwlIqKyX3wAM0u3rA+McvlIIWmSamA=
github.com/google/addlicense v0.0.0-20200906110928-a0294312aa76 h1:JypWNzPMSgH5yL0NvFoAIsDRlKFgL0AsS3GO5bg4Pto=
github.com/google/addlicense v0.0.0-20200906110928-a0294312aa76/go.mod h1:EMjYTRimagHs1FwlIqKyX3wAM0u3rA+McvlIIWmSamA=
github.com/google/addlicense v0.0.0-20210428195630-6d92264d7170 h1:jLUa4MO3autxlRJmC4KubeE5QGIb5JqW9oEaqYTb/fA=
@ -415,6 +420,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.14.3 h1:4EGfSkR2hJDB0s3oFfrlPqjU1e4WLncergLil3nEKW0=
github.com/rs/zerolog v1.14.3/go.mod h1:3WXPzbXEEliJ+a6UFE4vhIxV8qR1EML6ngzP9ug4eYg=
github.com/rs/zerolog v1.19.0 h1:hYz4ZVdUgjXTBUmrkrw55j1nHx68LfOKIQk5IYtyScg=
github.com/rs/zerolog v1.19.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
@ -463,6 +470,7 @@ github.com/voxelbrain/goptions v0.0.0-20180630082107-58cddc247ea2/go.mod h1:DGCI
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.3/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
@ -544,6 +552,7 @@ golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
@ -563,6 +572,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEha
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
@ -642,6 +652,7 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
@ -650,6 +661,7 @@ golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200616133436-c1934b75d054 h1:HHeAlu5H9b71C+Fx0K+1dGgVFN1DM1/wz4aoGOA5qS8=
golang.org/x/tools v0.0.0-20200616133436-c1934b75d054/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200818005847-188abfa75333/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1-0.20210504181558-0bb7e5c47b1a h1:xiJ7cj6CCsHjXZvlwLWEB1qwiw7jA7iWBzOLnkHM52c=

View file

@ -50,6 +50,46 @@ func validatePullPolicy(v core.PullPolicy) error {
}
}
// DeploymentCommunicationMethod define communication method used for inter-cluster communication
type DeploymentCommunicationMethod string
// Get returns communication method from pointer. If pointer is nil default is returned.
func (d *DeploymentCommunicationMethod) Get() DeploymentCommunicationMethod {
if d == nil {
return DefaultDeploymentCommunicationMethod
}
switch v := *d; v {
case DeploymentCommunicationMethodHeadlessService, DeploymentCommunicationMethodDNS, DeploymentCommunicationMethodIP, DeploymentCommunicationMethodShortDNS:
return v
default:
return DefaultDeploymentCommunicationMethod
}
}
// String returns string representation of method.
func (d DeploymentCommunicationMethod) String() string {
return string(d)
}
// New returns pointer.
func (d DeploymentCommunicationMethod) New() *DeploymentCommunicationMethod {
return &d
}
const (
// DefaultDeploymentCommunicationMethod define default communication method.
DefaultDeploymentCommunicationMethod = DeploymentCommunicationMethodHeadlessService
// DeploymentCommunicationMethodHeadlessService define old communication mechanism, based on headless service.
DeploymentCommunicationMethodHeadlessService DeploymentCommunicationMethod = "headless"
// DeploymentCommunicationMethodDNS define ClusterIP Service DNS based communication.
DeploymentCommunicationMethodDNS DeploymentCommunicationMethod = "dns"
// DeploymentCommunicationMethodDNS define ClusterIP Service DNS based communication. Use namespaced short DNS (used in migration)
DeploymentCommunicationMethodShortDNS DeploymentCommunicationMethod = "short-dns"
// DeploymentCommunicationMethodIP define ClusterIP Servce IP based communication.
DeploymentCommunicationMethodIP DeploymentCommunicationMethod = "ip"
)
// DeploymentSpec contains the spec part of a ArangoDeployment resource.
type DeploymentSpec struct {
Mode *DeploymentMode `json:"mode,omitempty"`
@ -118,6 +158,9 @@ type DeploymentSpec struct {
Timeouts *Timeouts `json:"timeouts,omitempty"`
ClusterDomain *string `json:"ClusterDomain,omitempty"`
// CommunicationMethod define communication method used in deployment
CommunicationMethod *DeploymentCommunicationMethod `json:"communicationMethod,omitempty"`
}
// GetRestoreFrom returns the restore from string or empty string if not set

View file

@ -567,6 +567,11 @@ func (in *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) {
*out = new(string)
**out = **in
}
if in.CommunicationMethod != nil {
in, out := &in.CommunicationMethod, &out.CommunicationMethod
*out = new(DeploymentCommunicationMethod)
**out = **in
}
return
}

View file

@ -235,7 +235,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
}
// Ensure we have image info
if retrySoon, exists, err := d.ensureImages(ctx, d.apiObject); err != nil {
if retrySoon, exists, err := d.ensureImages(ctx, d.apiObject, cachedStatus); err != nil {
return minInspectionInterval, errors.Wrapf(err, "Image detection failed")
} else if retrySoon || !exists {
return minInspectionInterval, nil

View file

@ -30,6 +30,8 @@ import (
"strings"
"time"
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
@ -81,7 +83,7 @@ type imagesBuilder struct {
// ensureImages creates pods needed to detect ImageID for specified images.
// Returns: retrySoon, error
func (d *Deployment) ensureImages(ctx context.Context, apiObject *api.ArangoDeployment) (bool, bool, error) {
func (d *Deployment) ensureImages(ctx context.Context, apiObject *api.ArangoDeployment, cachedStatus inspectorInterface.Inspector) (bool, bool, error) {
status, lastVersion := d.GetStatus()
ib := imagesBuilder{
APIObject: apiObject,
@ -96,8 +98,7 @@ func (d *Deployment) ensureImages(ctx context.Context, apiObject *api.ArangoDepl
return nil
},
}
retrySoon, exists, err := ib.Run(ctx)
retrySoon, exists, err := ib.Run(ctx, cachedStatus)
if err != nil {
return retrySoon, exists, errors.WithStack(err)
}
@ -107,11 +108,11 @@ func (d *Deployment) ensureImages(ctx context.Context, apiObject *api.ArangoDepl
// Run creates pods needed to detect ImageID for specified images and puts the found
// image ID's into the status.Images list.
// Returns: retrySoon, error
func (ib *imagesBuilder) Run(ctx context.Context) (bool, bool, error) {
func (ib *imagesBuilder) Run(ctx context.Context, cachedStatus inspectorInterface.Inspector) (bool, bool, error) {
// Check ArangoDB image
if _, found := ib.Status.Images.GetByImage(ib.Spec.GetImage()); !found {
// We need to find the image ID for the ArangoDB image
retrySoon, err := ib.fetchArangoDBImageIDAndVersion(ctx, ib.Spec.GetImage())
retrySoon, err := ib.fetchArangoDBImageIDAndVersion(ctx, cachedStatus, ib.Spec.GetImage())
if err != nil {
return retrySoon, false, errors.WithStack(err)
}
@ -124,7 +125,7 @@ func (ib *imagesBuilder) Run(ctx context.Context) (bool, bool, error) {
// fetchArangoDBImageIDAndVersion checks a running pod for fetching the ID of the given image.
// When no pod exists, it is created, otherwise the ID is fetched & version detected.
// Returns: retrySoon, error
func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, image string) (bool, error) {
func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cachedStatus inspectorInterface.Inspector, image string) (bool, error) {
role := k8sutil.ImageIDAndVersionRole
id := fmt.Sprintf("%0x", sha1.Sum([]byte(image)))[:6]
podName := k8sutil.CreatePodName(ib.APIObject.GetName(), role, id, "")
@ -225,7 +226,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
apiObject: ib.APIObject,
}
pod, err = resources.RenderArangoPod(ib.APIObject, role, id, podName, args, &imagePod)
pod, err = resources.RenderArangoPod(cachedStatus, ib.APIObject, role, id, podName, args, &imagePod)
if err != nil {
log.Debug().Err(err).Msg("Failed to render image ID pod")
return true, errors.WithStack(err)
@ -324,7 +325,7 @@ func (i *ImageUpdatePod) GetVolumes() ([]core.Volume, []core.VolumeMount) {
func (i *ImageUpdatePod) GetSidecars(*core.Pod) {
}
func (i *ImageUpdatePod) GetInitContainers() ([]core.Container, error) {
func (i *ImageUpdatePod) GetInitContainers(cachedStatus interfaces.Inspector) ([]core.Container, error) {
return nil, nil
}

View file

@ -29,6 +29,8 @@ import (
"testing"
"time"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
@ -331,7 +333,7 @@ func TestEnsureImages(t *testing.T) {
require.NoError(t, err)
// Act
retrySoon, _, err := d.ensureImages(context.Background(), d.apiObject)
retrySoon, _, err := d.ensureImages(context.Background(), d.apiObject, inspector.NewEmptyInspector())
// Assert
assert.EqualValues(t, testCase.RetrySoon, retrySoon)

View file

@ -0,0 +1,63 @@
//
// DISCLAIMER
//
// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Adam Janikowski
//
package pod
import (
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service"
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func GenerateMemberEndpoint(services service.Inspector, apiObject meta.Object, spec api.DeploymentSpec, group api.ServerGroup, member api.MemberStatus) (string, error) {
memberName := member.ArangoMemberName(apiObject.GetName(), group)
svc, ok := services.Service(memberName)
if !ok {
return "", errors.Newf("Service %s not found", memberName)
}
return GenerateMemberEndpointFromService(svc, apiObject, spec, group, member)
}
func GenerateMemberEndpointFromService(svc *core.Service, apiObject meta.Object, spec api.DeploymentSpec, group api.ServerGroup, member api.MemberStatus) (string, error) {
if group.IsArangod() {
switch method := spec.CommunicationMethod.Get(); method {
case api.DeploymentCommunicationMethodDNS:
return k8sutil.CreateServiceDNSNameWithDomain(svc, spec.ClusterDomain), nil
case api.DeploymentCommunicationMethodIP:
if svc.Spec.ClusterIP == "" {
return "", errors.Newf("ClusterIP of service %s is empty", svc.GetName())
}
return svc.Spec.ClusterIP, nil
case api.DeploymentCommunicationMethodShortDNS:
return svc.GetName(), nil
default:
return k8sutil.CreatePodDNSNameWithDomain(apiObject, spec.ClusterDomain, group.AsRole(), member.ID), nil
}
} else {
return k8sutil.CreateSyncMasterClientServiceDNSNameWithDomain(apiObject, spec.ClusterDomain), nil
}
}

View file

@ -19,6 +19,7 @@
//
// Author Ewout Prangsma
// Author Tomasz Mielech
// Author Adam Janikowski
//
package reconcile
@ -150,6 +151,8 @@ func (a *actionWaitForMemberUp) checkProgressAgent(ctx context.Context) (bool, b
shortCtx, c := context.WithTimeout(ctx, 3*time.Second)
defer c()
shortCtx = agency.WithAllowDifferentLeaderEndpoints(shortCtx)
if err := agency.AreAgentsHealthy(shortCtx, clients); err != nil {
log.Debug().Err(err).Msg("Not all agents are ready")
return false, false, nil

View file

@ -25,6 +25,10 @@ package reconcile
import (
"context"
json "github.com/json-iterator/go"
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/go-driver"
@ -115,7 +119,7 @@ func createRotateOrUpgradePlanInternal(ctx context.Context, log zerolog.Logger,
!decision.AutoUpgradeNeeded)
} else {
// Use new level of rotate logic
rotNeeded, reason := podNeedsRotation(ctx, log, pod, spec, group, status, m, cachedStatus, context)
rotNeeded, reason := podNeedsRotation(ctx, log, apiObject, pod, spec, group, status, m, cachedStatus, context)
if rotNeeded {
newPlan = createRotateMemberPlan(log, m, group, reason)
}
@ -282,9 +286,10 @@ func memberImageInfo(spec api.DeploymentSpec, status api.MemberStatus, images ap
// given pod differs from what it should be according to the
// given deployment spec.
// When true is returned, a reason for the rotation is already returned.
func podNeedsRotation(ctx context.Context, log zerolog.Logger, p *core.Pod, spec api.DeploymentSpec,
func podNeedsRotation(ctx context.Context, log zerolog.Logger, apiObject k8sutil.APIObject, p *core.Pod, spec api.DeploymentSpec,
group api.ServerGroup, status api.DeploymentStatus, m api.MemberStatus,
cachedStatus inspectorInterface.Inspector, planCtx PlanBuilderContext) (bool, string) {
if m.PodUID != p.UID {
return true, "Pod UID does not match, this pod is not managed by Operator. Recreating"
}
@ -318,9 +323,31 @@ func podNeedsRotation(ctx context.Context, log zerolog.Logger, p *core.Pod, spec
}
if m.PodSpecVersion != checksum {
if _, err := json.Marshal(renderedPod); err == nil {
log.Info().Str("id", m.ID).Str("Before", m.PodSpecVersion).Str("After", checksum).Msgf("XXXXXXXXXXX Pod needs rotation - checksum does not match")
}
return true, "Pod needs rotation - checksum does not match"
}
endpoint, err := pod.GenerateMemberEndpoint(cachedStatus, apiObject, spec, group, m)
if err != nil {
log.Err(err).Msg("Error while getting pod endpoint")
return false, ""
}
if e := m.Endpoint; e == nil {
if spec.CommunicationMethod == nil {
// TODO: Remove in 1.2.0 release to allow rotation
return false, "Pod endpoint is not set and CommunicationMethod is not set, do not recreate"
}
return true, "Communication method has been set - ensure endpoint"
} else {
if *e != endpoint {
return true, "Pod endpoint changed"
}
}
return false, ""
}

View file

@ -64,12 +64,12 @@ func versionHasAdvertisedEndpoint(v driver.Version) bool {
}
// createArangodArgsWithUpgrade creates command line arguments for an arangod server upgrade in the given group.
func createArangodArgsWithUpgrade(input pod.Input) []string {
return createArangodArgs(input, pod.AutoUpgrade().Args(input)...)
func createArangodArgsWithUpgrade(cachedStatus interfaces.Inspector, input pod.Input) ([]string, error) {
return createArangodArgs(cachedStatus, input, pod.AutoUpgrade().Args(input)...)
}
// createArangodArgs creates command line arguments for an arangod server in the given group.
func createArangodArgs(input pod.Input, additionalOptions ...k8sutil.OptionPair) []string {
func createArangodArgs(cachedStatus interfaces.Inspector, input pod.Input, additionalOptions ...k8sutil.OptionPair) ([]string, error) {
options := k8sutil.CreateOptionPairs(64)
//scheme := NewURLSchemes(bsCfg.SslKeyFile != "").Arangod
@ -107,15 +107,13 @@ func createArangodArgs(input pod.Input, additionalOptions ...k8sutil.OptionPair)
versionHasAdvertisedEndpoint := versionHasAdvertisedEndpoint(input.Version)
/* if config.ServerThreads != 0 {
options = append(options,
k8sutil.OptionPair{"--server.threads", strconv.Itoa(config.ServerThreads)})
}*/
/*if config.DebugCluster {
options = append(options,
k8sutil.OptionPair{"--log.level", "startup=trace"})
}*/
myTCPURL := scheme + "://" + net.JoinHostPort(k8sutil.CreatePodDNSNameWithDomain(input.ApiObject, input.Deployment.ClusterDomain, input.Group.AsRole(), input.Member.ID), strconv.Itoa(k8sutil.ArangoPort))
endpoint, err := pod.GenerateMemberEndpoint(cachedStatus, input.ApiObject, input.Deployment, input.Group, input.Member)
if err != nil {
return nil, err
}
endpoint = util.StringOrDefault(input.Member.Endpoint, endpoint)
myTCPURL := scheme + "://" + net.JoinHostPort(endpoint, strconv.Itoa(k8sutil.ArangoPort))
addAgentEndpoints := false
switch input.Group {
case api.ServerGroupAgents:
@ -128,8 +126,11 @@ func createArangodArgs(input pod.Input, additionalOptions ...k8sutil.OptionPair)
options.Add("--server.statistics", "false")
for _, p := range input.Status.Members.Agents {
if p.ID != input.Member.ID {
dnsName := p.GetEndpoint(k8sutil.CreatePodDNSNameWithDomain(input.ApiObject, input.Deployment.ClusterDomain, api.ServerGroupAgents.AsRole(), p.ID))
options.Addf("--agency.endpoint", "%s://%s", scheme, net.JoinHostPort(dnsName, strconv.Itoa(k8sutil.ArangoPort)))
dnsName, err := pod.GenerateMemberEndpoint(cachedStatus, input.ApiObject, input.Deployment, api.ServerGroupAgents, p)
if err != nil {
return nil, err
}
options.Addf("--agency.endpoint", "%s://%s", scheme, net.JoinHostPort(util.StringOrDefault(p.Endpoint, dnsName), strconv.Itoa(k8sutil.ArangoPort)))
}
}
case api.ServerGroupDBServers:
@ -162,8 +163,11 @@ func createArangodArgs(input pod.Input, additionalOptions ...k8sutil.OptionPair)
}
if addAgentEndpoints {
for _, p := range input.Status.Members.Agents {
dnsName := p.GetEndpoint(k8sutil.CreatePodDNSNameWithDomain(input.ApiObject, input.Deployment.ClusterDomain, api.ServerGroupAgents.AsRole(), p.ID))
options.Addf("--cluster.agency-endpoint", "%s://%s", scheme, net.JoinHostPort(dnsName, strconv.Itoa(k8sutil.ArangoPort)))
dnsName, err := pod.GenerateMemberEndpoint(cachedStatus, input.ApiObject, input.Deployment, api.ServerGroupAgents, p)
if err != nil {
return nil, err
}
options.Addf("--cluster.agency-endpoint", "%s://%s", scheme, net.JoinHostPort(util.StringOrDefault(p.Endpoint, dnsName), strconv.Itoa(k8sutil.ArangoPort)))
}
}
@ -176,12 +180,11 @@ func createArangodArgs(input pod.Input, additionalOptions ...k8sutil.OptionPair)
args = append(args, input.GroupSpec.Args...)
}
return args
return args, nil
}
// createArangoSyncArgs creates command line arguments for an arangosync server in the given group.
func createArangoSyncArgs(apiObject metav1.Object, spec api.DeploymentSpec, group api.ServerGroup,
groupSpec api.ServerGroupSpec, member api.MemberStatus) []string {
func createArangoSyncArgs(apiObject metav1.Object, spec api.DeploymentSpec, group api.ServerGroup, groupSpec api.ServerGroupSpec, member api.MemberStatus) []string {
options := k8sutil.CreateOptionPairs(64)
var runCmd string
var port int
@ -314,7 +317,7 @@ func (r *Resources) RenderPodForMember(ctx context.Context, cachedStatus inspect
member, ok := cachedStatus.ArangoMember(memberName)
if !ok {
return nil, errors.Newf("Service of member %s not found", memberName)
return nil, errors.Newf("ArangoMember %s not found", memberName)
}
// Update pod name
@ -346,13 +349,16 @@ func (r *Resources) RenderPodForMember(ctx context.Context, cachedStatus inspect
input := memberPod.AsInput()
args := createArangodArgs(input)
args, err := createArangodArgs(cachedStatus, input)
if err != nil {
return nil, errors.WithStack(err)
}
if err := memberPod.Validate(cachedStatus); err != nil {
return nil, errors.WithStack(errors.Wrapf(err, "Validation of pods resources failed"))
}
return RenderArangoPod(apiObject, role, newMember.ID, newMember.PodName, args, &memberPod)
return RenderArangoPod(cachedStatus, apiObject, role, newMember.ID, newMember.PodName, args, &memberPod)
} else if group.IsArangosync() {
// Check image
if !imageInfo.Enterprise {
@ -423,7 +429,7 @@ func (r *Resources) RenderPodForMember(ctx context.Context, cachedStatus inspect
arangoMember: *member,
}
return RenderArangoPod(apiObject, role, newMember.ID, newMember.PodName, args, &memberSyncPod)
return RenderArangoPod(cachedStatus, apiObject, role, newMember.ID, newMember.PodName, args, &memberSyncPod)
} else {
return nil, errors.Newf("unable to render Pod")
}
@ -476,13 +482,27 @@ func (r *Resources) createPodForMember(ctx context.Context, spec api.DeploymentS
imageInfo = *m.Image
kubecli := r.context.GetKubeCli()
apiObject := r.context.GetAPIObject()
endpoint, err := pod.GenerateMemberEndpoint(cachedStatus, apiObject, spec, group, m)
if err != nil {
return errors.WithStack(err)
}
if m.Endpoint == nil || *m.Endpoint != endpoint {
// Update endpoint
m.Endpoint = &endpoint
if err := status.Members.Update(m, group); err != nil {
return errors.WithStack(err)
}
}
pod, err := r.RenderPodForMember(ctx, cachedStatus, spec, status, memberID, imageInfo)
if err != nil {
return errors.WithStack(err)
}
kubecli := r.context.GetKubeCli()
apiObject := r.context.GetAPIObject()
ns := r.context.GetNamespace()
secrets := kubecli.CoreV1().Secrets(ns)
if !found {
@ -518,7 +538,6 @@ func (r *Resources) createPodForMember(ctx context.Context, spec api.DeploymentS
m.PodUID = uid
m.PodSpecVersion = sha
m.Endpoint = util.NewString(k8sutil.CreatePodDNSNameWithDomain(apiObject, spec.ClusterDomain, role, m.ID))
m.ArangoVersion = m.Image.ArangoDBVersion
m.ImageID = m.Image.ImageID
@ -571,7 +590,7 @@ func (r *Resources) createPodForMember(ctx context.Context, spec api.DeploymentS
log.Debug().Str("pod-name", m.PodName).Msg("Created pod")
m.PodUID = uid
m.Endpoint = util.NewString(k8sutil.CreateSyncMasterClientServiceDNSNameWithDomain(apiObject, spec.ClusterDomain))
m.Endpoint = &endpoint
m.PodSpecVersion = sha
}
// Record new member phase
@ -596,7 +615,7 @@ func (r *Resources) createPodForMember(ctx context.Context, spec api.DeploymentS
}
// RenderArangoPod renders new ArangoD Pod
func RenderArangoPod(deployment k8sutil.APIObject, role, id, podName string,
func RenderArangoPod(cachedStatus inspectorInterface.Inspector, deployment k8sutil.APIObject, role, id, podName string,
args []string, podCreator interfaces.PodCreator) (*core.Pod, error) {
// Prepare basic pod
@ -620,7 +639,7 @@ func RenderArangoPod(deployment k8sutil.APIObject, role, id, podName string,
podCreator.Init(&p)
if initContainers, err := podCreator.GetInitContainers(); err != nil {
if initContainers, err := podCreator.GetInitContainers(cachedStatus); err != nil {
return nil, errors.WithStack(err)
} else if initContainers != nil {
p.Spec.InitContainers = append(p.Spec.InitContainers, initContainers...)

View file

@ -25,6 +25,11 @@ package resources
import (
"testing"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
"github.com/stretchr/testify/require"
core "k8s.io/api/core/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
"github.com/stretchr/testify/assert"
@ -34,6 +39,54 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util"
)
type inspectorMock interface {
AddService(t *testing.T, svc ...*core.Service) inspectorMock
RegisterMemberStatus(t *testing.T, apiObject *api.ArangoDeployment, group api.ServerGroup, members ...api.MemberStatus) inspectorMock
Get(t *testing.T) inspectorInterface.Inspector
}
func newInspectorMock() inspectorMock {
return inspectorMockStruct{
services: map[string]*core.Service{},
}
}
type inspectorMockStruct struct {
services map[string]*core.Service
}
func (i inspectorMockStruct) RegisterMemberStatus(t *testing.T, apiObject *api.ArangoDeployment, group api.ServerGroup, members ...api.MemberStatus) inspectorMock {
var z inspectorMock = i
for _, member := range members {
memberName := member.ArangoMemberName(apiObject.GetName(), group)
svc := core.Service{
ObjectMeta: metav1.ObjectMeta{
Name: memberName,
},
Spec: core.ServiceSpec{
ClusterIP: "127.0.0.1",
},
}
z = z.AddService(t, &svc)
}
return z
}
func (i inspectorMockStruct) AddService(t *testing.T, svc ...*core.Service) inspectorMock {
for _, s := range svc {
i.services[s.GetName()] = s
}
return i
}
func (i inspectorMockStruct) Get(t *testing.T) inspectorInterface.Inspector {
return inspector.NewInspectorFromData(nil, nil, nil, i.services, nil, nil, nil, nil)
}
// TestCreateArangodArgsAgent tests createArangodArgs for agent.
func TestCreateArangodArgsAgent(t *testing.T) {
// Default deployment
@ -64,7 +117,12 @@ func TestCreateArangodArgsAgent(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--agency.activate=true",
@ -119,7 +177,12 @@ func TestCreateArangodArgsAgent(t *testing.T) {
AutoUpgrade: true,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgsWithUpgrade(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...)
cmdline, err := createArangodArgsWithUpgrade(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--agency.activate=true",
@ -178,7 +241,12 @@ func TestCreateArangodArgsAgent(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--agency.activate=true",
@ -232,7 +300,12 @@ func TestCreateArangodArgsAgent(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--agency.activate=true",
@ -286,7 +359,12 @@ func TestCreateArangodArgsAgent(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--agency.activate=true",

View file

@ -391,7 +391,7 @@ func (m *MemberArangoDPod) IsDeploymentMode() bool {
return m.spec.IsDevelopment()
}
func (m *MemberArangoDPod) GetInitContainers() ([]core.Container, error) {
func (m *MemberArangoDPod) GetInitContainers(cachedStatus interfaces.Inspector) ([]core.Container, error) {
var initContainers []core.Container
if c := m.groupSpec.InitContainers.GetContainers(); len(c) > 0 {
@ -426,7 +426,10 @@ func (m *MemberArangoDPod) GetInitContainers() ([]core.Container, error) {
{
// Upgrade container - run in background
if m.autoUpgrade || m.status.Upgrade {
args := createArangodArgsWithUpgrade(m.AsInput())
args, err := createArangodArgsWithUpgrade(cachedStatus, m.AsInput())
if err != nil {
return nil, err
}
c, err := k8sutil.NewContainer(args, m.GetContainerCreator())
if err != nil {
@ -447,7 +450,10 @@ func (m *MemberArangoDPod) GetInitContainers() ([]core.Container, error) {
{
versionArgs := pod.UpgradeVersionCheck().Args(m.AsInput())
if len(versionArgs) > 0 {
args := createArangodArgs(m.AsInput(), versionArgs...)
args, err := createArangodArgs(cachedStatus, m.AsInput(), versionArgs...)
if err != nil {
return nil, err
}
c, err := k8sutil.NewContainer(args, m.GetContainerCreator())
if err != nil {

View file

@ -25,6 +25,8 @@ package resources
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
"github.com/stretchr/testify/assert"
@ -64,7 +66,12 @@ func TestCreateArangodArgsCoordinator(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",
@ -116,7 +123,12 @@ func TestCreateArangodArgsCoordinator(t *testing.T) {
AutoUpgrade: true,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgsWithUpgrade(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgsWithUpgrade(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",
@ -169,7 +181,12 @@ func TestCreateArangodArgsCoordinator(t *testing.T) {
AutoUpgrade: true,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgsWithUpgrade(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgsWithUpgrade(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",
@ -225,7 +242,12 @@ func TestCreateArangodArgsCoordinator(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529",
@ -276,7 +298,12 @@ func TestCreateArangodArgsCoordinator(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",
@ -329,7 +356,12 @@ func TestCreateArangodArgsCoordinator(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",

View file

@ -25,6 +25,8 @@ package resources
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
"github.com/stretchr/testify/assert"
@ -64,7 +66,12 @@ func TestCreateArangodArgsDBServer(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",
@ -116,7 +123,12 @@ func TestCreateArangodArgsDBServer(t *testing.T) {
AutoUpgrade: true,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgsWithUpgrade(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgsWithUpgrade(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",
@ -170,7 +182,12 @@ func TestCreateArangodArgsDBServer(t *testing.T) {
AutoUpgrade: true,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgsWithUpgrade(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgsWithUpgrade(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc.cluster.local:8529",
@ -226,7 +243,12 @@ func TestCreateArangodArgsDBServer(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=tcp://name-agent-a1.name-int.ns.svc:8529",
@ -277,7 +299,12 @@ func TestCreateArangodArgsDBServer(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",
@ -330,7 +357,12 @@ func TestCreateArangodArgsDBServer(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock()
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...).RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",

View file

@ -25,6 +25,8 @@ package resources
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -54,7 +56,11 @@ func TestCreateArangodArgsSingle(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock().RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--database.directory=/data",
@ -91,7 +97,11 @@ func TestCreateArangodArgsSingle(t *testing.T) {
AutoUpgrade: true,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgsWithUpgrade(input)
i := newInspectorMock().RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgsWithUpgrade(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--database.auto-upgrade=true",
@ -132,7 +142,11 @@ func TestCreateArangodArgsSingle(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock().RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--database.directory=/data",
@ -168,7 +182,11 @@ func TestCreateArangodArgsSingle(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock().RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--database.directory=/data",
@ -206,7 +224,11 @@ func TestCreateArangodArgsSingle(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock().RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--database.directory=/data",
@ -243,7 +265,11 @@ func TestCreateArangodArgsSingle(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "a1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock().RegisterMemberStatus(t, apiObject, input.Group, input.Member)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--database.directory=/data",
@ -292,7 +318,12 @@ func TestCreateArangodArgsSingle(t *testing.T) {
AutoUpgrade: false,
Member: api.MemberStatus{ID: "id1"},
}
cmdline := createArangodArgs(input)
i := newInspectorMock().RegisterMemberStatus(t, apiObject, input.Group, input.Member)
i = i.RegisterMemberStatus(t, apiObject, api.ServerGroupAgents, agents...)
cmdline, err := createArangodArgs(i.Get(t), input)
require.NoError(t, err)
assert.Equal(t,
[]string{
"--cluster.agency-endpoint=ssl://name-agent-a1.name-int.ns.svc:8529",

View file

@ -264,7 +264,7 @@ func (m *MemberSyncPod) IsDeploymentMode() bool {
return m.spec.IsDevelopment()
}
func (m *MemberSyncPod) GetInitContainers() ([]core.Container, error) {
func (m *MemberSyncPod) GetInitContainers(cachedStatus interfaces.Inspector) ([]core.Container, error) {
var initContainers []core.Container
if c := m.groupSpec.InitContainers.GetContainers(); len(c) > 0 {

View file

@ -150,6 +150,7 @@ func (r *Resources) EnsureSecrets(ctx context.Context, log zerolog.Logger, cache
k8sutil.CreatePodDNSName(apiObject, role, m.ID),
k8sutil.CreateServiceDNSName(service),
service.Spec.ClusterIP,
service.GetName(),
}
if spec.ClusterDomain != nil {

View file

@ -24,11 +24,13 @@ package interfaces
import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service"
core "k8s.io/api/core/v1"
)
type Inspector interface {
secret.Inspector
service.Inspector
}
type PodModifier interface {
@ -41,7 +43,7 @@ type PodCreator interface {
GetRole() string
GetVolumes() ([]core.Volume, []core.VolumeMount)
GetSidecars(*core.Pod)
GetInitContainers() ([]core.Container, error)
GetInitContainers(cachedStatus Inspector) ([]core.Container, error)
GetFinalizers() []string
GetTolerations() []core.Toleration
GetNodeSelector() map[string]string