Skip to content

Commit e9f0469

Browse files
author
lamai93
committed
Merge remote-tracking branch 'origin/master' into feature/bootstrap-root-pwd
2 parents e58fb32 + 241e91a commit e9f0469

File tree

14 files changed

+636
-65
lines changed

14 files changed

+636
-65
lines changed

Makefile

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ endif
104104
SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')
105105
DASHBOARDSOURCES := $(shell find $(DASHBOARDDIR)/src -name '*.js' -not -path './test/*') $(DASHBOARDDIR)/package.json
106106

107+
ifndef ARANGOSYNCSRCDIR
108+
ARANGOSYNCSRCDIR := $(SCRIPTDIR)/arangosync
109+
endif
110+
DOCKERARANGOSYNCCTRLFILE=tests/sync/Dockerfile
111+
ifndef ARANGOSYNCTESTCTRLIMAGE
112+
ARANGOSYNCTESTCTRLIMAGE := $(DOCKERNAMESPACE)/kube-arangodb-sync-test-ctrl$(IMAGESUFFIX)
113+
endif
114+
ifndef ARANGOSYNCTESTIMAGE
115+
ARANGOSYNCTESTIMAGE := $(DOCKERNAMESPACE)/kube-arangodb-sync-test$(IMAGESUFFIX)
116+
endif
117+
ifndef ARANGOSYNCIMAGE
118+
ARANGOSYNCIMAGE := $(DOCKERNAMESPACE)/kube-arangodb-sync$(IMAGESUFFIX)
119+
endif
120+
ARANGOSYNCTESTCTRLBINNAME := $(PROJECT)_sync_test_ctrl
121+
ARANGOSYNCTESTCTRLBIN := $(BINDIR)/$(ARANGOSYNCTESTCTRLBINNAME)
122+
107123
.PHONY: all
108124
all: verify-generated build
109125

@@ -298,6 +314,23 @@ docker-test: $(TESTBIN)
298314
run-upgrade-tests:
299315
TESTOPTIONS="-test.run=TestUpgrade" make run-tests
300316

317+
.PHONY: prepare-run-tests
318+
prepare-run-tests:
319+
ifdef PUSHIMAGES
320+
docker push $(OPERATORIMAGE)
321+
endif
322+
ifneq ($(DEPLOYMENTNAMESPACE), default)
323+
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(DEPLOYMENTNAMESPACE)
324+
kubectl create namespace $(DEPLOYMENTNAMESPACE)
325+
endif
326+
kubectl apply -f $(MANIFESTPATHCRD)
327+
kubectl apply -f $(MANIFESTPATHSTORAGE)
328+
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
329+
kubectl apply -f $(MANIFESTPATHDEPLOYMENTREPLICATION)
330+
kubectl apply -f $(MANIFESTPATHTEST)
331+
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
332+
$(ROOTDIR)/scripts/kube_create_license_key_secret.sh "$(DEPLOYMENTNAMESPACE)" '$(ENTERPRISELICENSE)'
333+
301334
.PHONY: run-tests
302335
run-tests: docker-test
303336
ifdef PUSHIMAGES
@@ -424,3 +457,54 @@ redeploy-operator: delete-operator manifests
424457
kubectl apply -f $(MANIFESTPATHDEPLOYMENTREPLICATION)
425458
kubectl apply -f $(MANIFESTPATHTEST)
426459
kubectl get pods
460+
461+
## ArangoSync Tests
462+
463+
$(ARANGOSYNCTESTCTRLBIN): $(GOBUILDDIR) $(SOURCES)
464+
@mkdir -p $(BINDIR)
465+
docker run \
466+
--rm \
467+
-v $(SRCDIR):/usr/code \
468+
-v $(CACHEVOL):/usr/gocache \
469+
-e GOCACHE=/usr/gocache \
470+
-e GOPATH=/usr/code/.gobuild \
471+
-e GOOS=linux \
472+
-e GOARCH=amd64 \
473+
-e CGO_ENABLED=0 \
474+
-w /usr/code/ \
475+
golang:$(GOVERSION) \
476+
go build -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(ARANGOSYNCTESTCTRLBINNAME) $(REPOPATH)/tests/sync
477+
478+
.PHONY: check-sync-vars
479+
check-sync-vars:
480+
ifndef ARANGOSYNCSRCDIR
481+
@echo ARANGOSYNCSRCDIR must point to the arangosync source directory
482+
@exit 1
483+
endif
484+
ifndef ARANGODIMAGE
485+
@echo ARANGODIMAGE must point to the usable arangodb enterprise image
486+
@exit 1
487+
endif
488+
ifndef ENTERPRISELICENSE
489+
@echo For tests using ArangoSync you most likely need the license key. Please set ENTERPRISELICENSE.
490+
@exit 1
491+
endif
492+
@echo Using ArangoSync source at $(ARANGOSYNCSRCDIR)
493+
@echo Using ArangoDB image $(ARANGODIMAGE)
494+
495+
.PHONY: docker-sync
496+
docker-sync: check-sync-vars
497+
SYNCIMAGE=$(ARANGOSYNCIMAGE) TESTIMAGE=$(ARANGOSYNCTESTIMAGE) $(MAKE) -C $(ARANGOSYNCSRCDIR) docker docker-test
498+
499+
.PHONY:
500+
docker-sync-test-ctrl: $(ARANGOSYNCTESTCTRLBIN)
501+
docker build --quiet -f $(DOCKERARANGOSYNCCTRLFILE) -t $(ARANGOSYNCTESTCTRLIMAGE) .
502+
503+
.PHONY:
504+
run-sync-tests: check-vars docker-sync docker-sync-test-ctrl prepare-run-tests
505+
ifdef PUSHIMAGES
506+
docker push $(ARANGOSYNCTESTCTRLIMAGE)
507+
docker push $(ARANGOSYNCTESTIMAGE)
508+
docker push $(ARANGOSYNCIMAGE)
509+
endif
510+
$(ROOTDIR)/scripts/kube_run_sync_tests.sh $(DEPLOYMENTNAMESPACE) '$(ARANGODIMAGE)' '$(ARANGOSYNCIMAGE)' '$(ARANGOSYNCTESTIMAGE)' '$(ARANGOSYNCTESTCTRLIMAGE)' '$(TESTOPTIONS)'

docs/Manual/Deployment/Kubernetes/Drain.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,18 @@ POST /_db/_system/_api/replication/clusterInventory
238238
}
239239
```
240240

241-
Check that for all collections the attribute `"allInSync"` has
242-
the value `true`. Note that it is necessary to do this for all databases!
241+
Check that for all collections the attributes `"isReady"` and `"allInSync"`
242+
both have the value `true`. Note that it is necessary to do this for all
243+
databases!
243244

244245
Here is a shell command which makes this check easy:
245246

246247
```bash
247-
curl -k https://arangodb.9hoeffer.de:8529/_db/_system/_api/replication/clusterInventory --user root: | jq . | grep '"allInSync"' | sort | uniq -c
248+
curl -k https://arangodb.9hoeffer.de:8529/_db/_system/_api/replication/clusterInventory --user root: | jq . | grep '"isReady"\|"allInSync"' | sort | uniq -c
248249
```
249250

250-
If all these checks are performed and are okay, the cluster is ready to
251-
run a risk-free drain operation.
251+
If all these checks are performed and are okay, then it is safe to
252+
continue with the clean out and drain procedure as described below.
252253

253254
{% hint 'danger' %}
254255
If there are some collections with `replicationFactor` set to
@@ -274,13 +275,14 @@ below, the procedure should also work without this.
274275
Finally, one should **not run a rolling upgrade or restart operation**
275276
at the time of a node drain.
276277

277-
## Clean out a DBserver manually (optional)
278+
## Clean out a DBserver manually
278279

279-
In this step we clean out a _DBServer_ manually, before even issuing the
280-
`kubectl drain` command. This step is optional, but can speed up things
281-
considerably. Here is why:
280+
In this step we clean out a _DBServer_ manually, **before issuing the
281+
`kubectl drain` command**. Previously, we have denoted this step as optional,
282+
but for safety reasons, we consider it mandatory now, since it is near
283+
impossible to choose the grace period long enough in a reliable way.
282284

283-
If this step is not performed, we must choose
285+
Furthermore, if this step is not performed, we must choose
284286
the grace period long enough to avoid any risk, as explained in the
285287
previous section. However, this has a disadvantage which has nothing to
286288
do with ArangoDB: We have observed, that some k8s internal services like
@@ -308,10 +310,10 @@ POST /_admin/cluster/cleanOutServer
308310
{"server":"DBServer0006"}
309311
```
310312

311-
(please compare the above output of the `/_admin/cluster/health` API).
312313
The value of the `"server"` attribute should be the name of the DBserver
313314
which is the one in the pod which resides on the node that shall be
314-
drained next. This uses the UI short name, alternatively one can use the
315+
drained next. This uses the UI short name (`ShortName` in the
316+
`/_admin/cluster/health` API), alternatively one can use the
315317
internal name, which corresponds to the pod name. In our example, the
316318
pod name is:
317319

@@ -328,6 +330,12 @@ could use the body:
328330
{"server":"PRMR-wbsq47rz"}
329331
```
330332

333+
You can use this command line to achieve this:
334+
335+
```bash
336+
curl -k https://arangodb.9hoeffer.de:8529/_admin/cluster/cleanOutServer --user root: -d '{"server":"PRMR-wbsq47rz"}'
337+
```
338+
331339
The API call will return immediately with a body like this:
332340

333341
```JSON
@@ -360,6 +368,12 @@ GET /_admin/cluster/queryAgencyJob?id=38029195
360368
}
361369
```
362370

371+
Use this command line to check progress:
372+
373+
```bash
374+
curl -k https://arangodb.9hoeffer.de:8529/_admin/cluster/queryAgencyJob?id=38029195 --user root:
375+
```
376+
363377
It indicates that the job is still ongoing (`"Pending"`). As soon as
364378
the job has completed, the answer will be:
365379

@@ -391,8 +405,8 @@ completely risk-free, even with a small grace period.
391405
## Performing the drain
392406

393407
After all above [checks before a node drain](#things-to-check-in-arangodb-before-a-node-drain)
394-
have been done successfully, it is safe to perform the drain
395-
operation, similar to this command:
408+
and the [manual clean out of the DBServer](#clean-out-a-dbserver-manually)
409+
have been done successfully, it is safe to perform the drain operation, similar to this command:
396410

397411
```bash
398412
kubectl drain gke-draintest-default-pool-394fe601-glts --delete-local-data --ignore-daemonsets --grace-period=300
@@ -402,12 +416,12 @@ As described above, the options `--delete-local-data` for ArangoDB and
402416
`--ignore-daemonsets` for other services have been added. A `--grace-period` of
403417
300 seconds has been chosen because for this example we are confident that all the data on our _DBServer_ pod
404418
can be moved to a different server within 5 minutes. Note that this is
405-
**not saying** that 300 seconds will always be enough, regardless of how
419+
**not saying** that 300 seconds will always be enough. Regardless of how
406420
much data is stored in the pod, your mileage may vary, moving a terabyte
407421
of data can take considerably longer!
408422

409-
If the optional step of
410-
[cleaning out a DBserver manually](#clean-out-a-dbserver-manually-optional)
423+
If the highly recommended step of
424+
[cleaning out a DBserver manually](#clean-out-a-dbserver-manually)
411425
has been performed beforehand, the grace period can easily be reduced to 60
412426
seconds - at least from the perspective of ArangoDB, since the server is already
413427
cleaned out, so it can be dropped readily and there is still no risk.

docs/Manual/Tutorials/Kubernetes/bare-metal.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ sudo chown $(id -u):$(id -g) $HOME/.kube/config
109109
For this guide, we go with **flannel**, as it is an easy way of setting up a layer 3 network, which uses the Kubernetes API and just works anywhere, where a network between the involved machines works:
110110

111111
```
112-
kubectl apply -f \
113-
https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
112+
kubectl apply -f \
113+
https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
114114
```
115115
```
116116
clusterrole.rbac.authorization.k8s.io/flannel created
@@ -220,8 +220,8 @@ kubectl get all --all-namespaces
220220
- Attach `tiller` to proper role
221221

222222
```
223-
kubectl create clusterrolebinding tiller-cluster-rule \
224-
--clusterrole=cluster-admin --serviceaccount=kube-system:tiller
223+
kubectl create clusterrolebinding tiller-cluster-rule \
224+
--clusterrole=cluster-admin --serviceaccount=kube-system:tiller
225225
```
226226
```
227227
clusterrolebinding.rbac.authorization.k8s.io/tiller-cluster-rule created
@@ -330,7 +330,7 @@ for how to get started.
330330
- As unlike cloud k8s offerings no file volume infrastructure exists, we need to still deploy the storage operator chart:
331331

332332
```
333-
helm install \
333+
helm install \
334334
https://github.com/arangodb/kube-arangodb/releases/download/0.3.7/kube-arangodb-storage.tgz
335335
```
336336
```

manifests/templates/test/rbac.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ rules:
1010
resources: ["nodes"]
1111
verbs: ["list"]
1212
- apiGroups: [""]
13-
resources: ["pods", "services", "persistentvolumes", "persistentvolumeclaims", "secrets", "serviceaccounts"]
13+
resources: ["pods", "services", "persistentvolumes", "persistentvolumeclaims", "secrets", "serviceaccounts", "pods/log"]
1414
verbs: ["*"]
1515
- apiGroups: ["apps"]
1616
resources: ["daemonsets", "deployments"]

pkg/apis/deployment/v1alpha/deployment_spec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ func (s DeploymentSpec) GetImage() string {
9999
return util.StringOrDefault(s.Image)
100100
}
101101

102+
// GetSyncImage returns, if set, Sync.Image or the default image.
103+
func (s DeploymentSpec) GetSyncImage() string {
104+
if s.Sync.HasSyncImage() {
105+
return s.Sync.GetSyncImage()
106+
}
107+
return s.GetImage()
108+
}
109+
102110
// GetImagePullPolicy returns the value of imagePullPolicy.
103111
func (s DeploymentSpec) GetImagePullPolicy() v1.PullPolicy {
104112
return util.PullPolicyOrDefault(s.ImagePullPolicy)

pkg/apis/deployment/v1alpha/sync_spec.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,24 @@ type SyncSpec struct {
3636
Authentication SyncAuthenticationSpec `json:"auth"`
3737
TLS TLSSpec `json:"tls"`
3838
Monitoring MonitoringSpec `json:"monitoring"`
39+
Image *string `json:"image"`
3940
}
4041

4142
// IsEnabled returns the value of enabled.
4243
func (s SyncSpec) IsEnabled() bool {
4344
return util.BoolOrDefault(s.Enabled)
4445
}
4546

47+
// GetSyncImage returns the syncer image or empty string
48+
func (s SyncSpec) GetSyncImage() string {
49+
return util.StringOrDefault(s.Image)
50+
}
51+
52+
// HasSyncImage returns whether a special sync image is set
53+
func (s SyncSpec) HasSyncImage() bool {
54+
return s.GetSyncImage() != ""
55+
}
56+
4657
// Validate the given spec
4758
func (s SyncSpec) Validate(mode DeploymentMode) error {
4859
if s.IsEnabled() && !mode.SupportsSync() {
@@ -78,6 +89,9 @@ func (s *SyncSpec) SetDefaultsFrom(source SyncSpec) {
7889
if s.Enabled == nil {
7990
s.Enabled = util.NewBoolOrNil(source.Enabled)
8091
}
92+
if s.Image == nil {
93+
s.Image = util.NewStringOrNil(source.Image)
94+
}
8195
s.ExternalAccess.SetDefaultsFrom(source.ExternalAccess)
8296
s.Authentication.SetDefaultsFrom(source.Authentication)
8397
s.TLS.SetDefaultsFrom(source.TLS)
@@ -95,5 +109,8 @@ func (s SyncSpec) ResetImmutableFields(fieldPrefix string, target *SyncSpec) []s
95109
if list := s.Authentication.ResetImmutableFields(fieldPrefix+".auth", &target.Authentication); len(list) > 0 {
96110
resetFields = append(resetFields, list...)
97111
}
112+
if s.GetSyncImage() != target.GetSyncImage() {
113+
resetFields = append(resetFields, fieldPrefix+".image")
114+
}
98115
return resetFields
99116
}

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

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

pkg/deployment/access_package.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ func (d *Deployment) ensureAccessPackage(apSecretName string) error {
196196
},
197197
Data: map[string][]byte{
198198
constants.SecretAccessPackageYaml: []byte(allYaml),
199+
constants.SecretCACertificate: []byte(tlsCACert),
200+
constants.SecretTLSKeyfile: []byte(keyfile),
199201
},
200202
}
201203
// Attach secret to owner

pkg/deployment/resources/pod_creator.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,11 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
598598
log.Debug().Str("image", spec.GetImage()).Msg("Image is not an enterprise image")
599599
return maskAny(fmt.Errorf("Image '%s' does not contain an Enterprise version of ArangoDB", spec.GetImage()))
600600
}
601+
// Check if the sync image is overwritten by the SyncSpec
602+
imageID := imageInfo.ImageID
603+
if spec.Sync.HasSyncImage() {
604+
imageID = spec.Sync.GetSyncImage()
605+
}
601606
var tlsKeyfileSecretName, clientAuthCASecretName, masterJWTSecretName, clusterJWTSecretName string
602607
// Check master JWT secret
603608
masterJWTSecretName = spec.Sync.Authentication.GetJWTSecretName()
@@ -664,7 +669,7 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
664669
if group == api.ServerGroupSyncWorkers {
665670
affinityWithRole = api.ServerGroupDBServers.AsRole()
666671
}
667-
if err := k8sutil.CreateArangoSyncPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, imageInfo.ImageID, lifecycleImage, spec.GetImagePullPolicy(), terminationGracePeriod, args, env,
672+
if err := k8sutil.CreateArangoSyncPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, imageID, lifecycleImage, spec.GetImagePullPolicy(), terminationGracePeriod, args, env,
668673
livenessProbe, tolerations, serviceAccountName, tlsKeyfileSecretName, clientAuthCASecretName, masterJWTSecretName, clusterJWTSecretName, affinityWithRole, groupSpec.GetNodeSelector()); err != nil {
669674
return maskAny(err)
670675
}

pkg/util/k8sutil/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ func NewKubeClient() (kubernetes.Interface, error) {
4444
return c, nil
4545
}
4646

47+
// MustNewKubeClient calls NewKubeClient an panics if it fails
48+
func MustNewKubeClient() kubernetes.Interface {
49+
i, err := NewKubeClient()
50+
if err != nil {
51+
panic(err)
52+
}
53+
return i
54+
}
55+
4756
// NewKubeExtClient creates a new k8s api extensions client
4857
func NewKubeExtClient() (apiextensionsclient.Interface, error) {
4958
cfg, err := InClusterConfig()

0 commit comments

Comments
 (0)