Skip to content

Commit f007ab0

Browse files
authored
[Feature] Single mode (#600)
1 parent 8fd654c commit f007ab0

29 files changed

+521
-38
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ fmt:
187187
@echo ">> Ensuring style of files"
188188
@go run golang.org/x/tools/cmd/goimports -w $(SOURCES)
189189

190+
.PHONY: license
191+
license:
192+
@echo ">> Ensuring license of files"
193+
@go run github.com/google/addlicense -f "./tools/codegen/boilerplate.go.txt" $(SOURCES)
194+
190195
.PHONY: fmt-verify
191196
fmt-verify: license-verify
192197
@echo ">> Verify files style"

chart/kube-arangodb/templates/deployment.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ spec:
8585
- --operator.backup
8686
{{- end }}
8787
- --chaos.allowed={{ .Values.operator.allowChaos }}
88+
{{- if .Values.operator.args }}
89+
{{- range .Values.operator.args }}
90+
- {{ . | quote }}
91+
{{- end }}
92+
{{- end }}
8893
env:
8994
- name: MY_POD_NAMESPACE
9095
valueFrom:

chart/kube-arangodb/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ operator:
55
imagePullPolicy: IfNotPresent
66
imagePullSecrets: []
77

8+
args: []
9+
810
service:
911
type: ClusterIP
1012

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
"strings"
3232
"time"
3333

34+
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
35+
3436
"github.com/rs/zerolog/log"
3537

3638
deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
@@ -105,6 +107,8 @@ var (
105107
enableBackup bool // Run backup operator
106108

107109
alpineImage, metricsExporterImage, arangoImage string
110+
111+
singleMode bool
108112
}
109113
chaosOptions struct {
110114
allowed bool
@@ -133,7 +137,9 @@ func init() {
133137
f.StringVar(&operatorOptions.metricsExporterImage, "operator.metrics-exporter-image", MetricsExporterImageEnv.GetOrDefault(defaultMetricsExporterImage), "Docker image used for metrics containers by default")
134138
f.StringVar(&operatorOptions.arangoImage, "operator.arango-image", ArangoImageEnv.GetOrDefault(defaultArangoImage), "Docker image used for arango by default")
135139
f.BoolVar(&chaosOptions.allowed, "chaos.allowed", false, "Set to allow chaos in deployments. Only activated when allowed and enabled in deployment")
140+
f.BoolVar(&operatorOptions.singleMode, "mode.single", false, "Enable single mode in Operator. WARNING: There should be only one replica of Operator, otherwise Operator can take unexpected actions")
136141

142+
features.Init(&cmdMain)
137143
}
138144

139145
func main() {
@@ -300,6 +306,7 @@ func newOperatorConfigAndDeps(id, namespace, name string) (operator.Config, oper
300306
AlpineImage: operatorOptions.alpineImage,
301307
MetricsExporterImage: operatorOptions.metricsExporterImage,
302308
ArangoImage: operatorOptions.arangoImage,
309+
SingleMode: operatorOptions.singleMode,
303310
}
304311
deps := operator.Dependencies{
305312
LogService: logService,

pkg/deployment/context_impl.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
"strconv"
3232
"time"
3333

34+
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
35+
3436
"github.com/arangodb/go-driver/http"
3537
"github.com/arangodb/go-driver/jwt"
3638
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
@@ -245,7 +247,7 @@ func (d *Deployment) getAuth() (driver.Authentication, error) {
245247
secrets := d.GetKubeCli().CoreV1().Secrets(d.apiObject.GetNamespace())
246248

247249
var secret string
248-
if i := d.apiObject.Status.CurrentImage; i == nil || i.ArangoDBVersion.CompareTo("3.7.0") < 0 || !i.Enterprise {
250+
if i := d.apiObject.Status.CurrentImage; i == nil || !features.JWTRotation().Supported(i.ArangoDBVersion, i.Enterprise) {
249251
s, err := secrets.Get(d.apiObject.Spec.Authentication.GetJWTSecretName(), meta.GetOptions{})
250252
if err != nil {
251253
return nil, goErrors.Errorf("JWT Secret is missing")

pkg/deployment/deployment_encryption_test.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func TestEnsurePod_ArangoDB_Encryption(t *testing.T) {
199199
},
200200
},
201201
{
202-
Name: "Agent EE 3.7.0 Pod with encrypted rocksdb",
202+
Name: "Agent EE 3.7.0 Pod with encrypted rocksdb, disabled feature",
203203
ArangoDeployment: &api.ArangoDeployment{
204204
Spec: api.DeploymentSpec{
205205
Image: util.NewString(testImage),
@@ -225,6 +225,70 @@ func TestEnsurePod_ArangoDB_Encryption(t *testing.T) {
225225
k8sutil.CreateEncryptionKeySecret(secrets, testRocksDBEncryptionKey, key)
226226
},
227227
ExpectedEvent: "member agent is created",
228+
ExpectedPod: core.Pod{
229+
Spec: core.PodSpec{
230+
Volumes: []core.Volume{
231+
k8sutil.CreateVolumeEmptyDir(k8sutil.ArangodVolumeName),
232+
k8sutil.CreateVolumeWithSecret(k8sutil.RocksdbEncryptionVolumeName, testRocksDBEncryptionKey),
233+
},
234+
Containers: []core.Container{
235+
{
236+
Name: k8sutil.ServerContainerName,
237+
Image: testImage,
238+
Command: BuildTestAgentArgs(t, firstAgentStatus.ID,
239+
AgentArgsWithTLS(firstAgentStatus.ID, false),
240+
ArgsWithAuth(false),
241+
ArgsWithEncryptionKey()),
242+
Ports: createTestPorts(),
243+
VolumeMounts: []core.VolumeMount{
244+
k8sutil.ArangodVolumeMount(),
245+
k8sutil.RocksdbEncryptionVolumeMount(),
246+
},
247+
Resources: emptyResources,
248+
LivenessProbe: createTestLivenessProbe(cmd, false, "", k8sutil.ArangoPort),
249+
ImagePullPolicy: core.PullIfNotPresent,
250+
SecurityContext: securityContext.NewSecurityContext(),
251+
},
252+
},
253+
RestartPolicy: core.RestartPolicyNever,
254+
TerminationGracePeriodSeconds: &defaultAgentTerminationTimeout,
255+
Hostname: testDeploymentName + "-" + api.ServerGroupAgentsString + "-" + firstAgentStatus.ID,
256+
Subdomain: testDeploymentName + "-int",
257+
Affinity: k8sutil.CreateAffinity(testDeploymentName, api.ServerGroupAgentsString,
258+
false, ""),
259+
},
260+
},
261+
},
262+
{
263+
Name: "Agent EE 3.7.0 Pod with encrypted rocksdb, enabled feature",
264+
ArangoDeployment: &api.ArangoDeployment{
265+
Spec: api.DeploymentSpec{
266+
Image: util.NewString(testImage),
267+
Authentication: noAuthentication,
268+
TLS: noTLS,
269+
RocksDB: rocksDBSpec,
270+
},
271+
},
272+
Features: testCaseFeatures{
273+
EncryptionRotation: true,
274+
},
275+
Helper: func(t *testing.T, deployment *Deployment, testCase *testCaseStruct) {
276+
deployment.status.last = api.DeploymentStatus{
277+
Members: api.DeploymentStatusMembers{
278+
Agents: api.MemberStatusList{
279+
firstAgentStatus,
280+
},
281+
},
282+
Images: createTestImagesWithVersion(true, "3.7.0"),
283+
}
284+
285+
testCase.createTestPodData(deployment, api.ServerGroupAgents, firstAgentStatus)
286+
287+
secrets := deployment.GetKubeCli().CoreV1().Secrets(testNamespace)
288+
key := make([]byte, 32)
289+
k8sutil.CreateEncryptionKeySecret(secrets, testRocksDBEncryptionKey, key)
290+
},
291+
ExpectedEvent: "member agent is created",
228292
ExpectedPod: core.Pod{
229293
Spec: core.PodSpec{
230294
Volumes: []core.Volume{

pkg/deployment/deployment_pod_tls_sni_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) {
8383
}(),
8484
},
8585
},
86+
Features: testCaseFeatures{
87+
TLSSNI: true,
88+
},
8689
Resources: func(t *testing.T, deployment *Deployment) {
8790
createTLSSNISecret(t, deployment.GetKubeCli(), "sni1", deployment.Namespace(), constants.SecretTLSKeyfile, "")
8891
createTLSSNISecret(t, deployment.GetKubeCli(), "sni2", deployment.Namespace(), constants.SecretTLSKeyfile, "")
@@ -155,6 +158,9 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) {
155158
}(),
156159
},
157160
},
161+
Features: testCaseFeatures{
162+
TLSSNI: true,
163+
},
158164
Resources: func(t *testing.T, deployment *Deployment) {
159165
createTLSSNISecret(t, deployment.GetKubeCli(), "sni1", deployment.Namespace(), constants.SecretTLSKeyfile, "")
160166
createTLSSNISecret(t, deployment.GetKubeCli(), "sni2", deployment.Namespace(), constants.SecretTLSKeyfile, "")
@@ -227,6 +233,9 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) {
227233
}(),
228234
},
229235
},
236+
Features: testCaseFeatures{
237+
TLSSNI: true,
238+
},
230239
Resources: func(t *testing.T, deployment *Deployment) {
231240
createTLSSNISecret(t, deployment.GetKubeCli(), "sni1", deployment.Namespace(), constants.SecretTLSKeyfile, "")
232241
createTLSSNISecret(t, deployment.GetKubeCli(), "sni2", deployment.Namespace(), constants.SecretTLSKeyfile, "")
@@ -299,6 +308,9 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) {
299308
}(),
300309
},
301310
},
311+
Features: testCaseFeatures{
312+
TLSSNI: true,
313+
},
302314
Resources: func(t *testing.T, deployment *Deployment) {
303315
createTLSSNISecret(t, deployment.GetKubeCli(), "sni1", deployment.Namespace(), constants.SecretTLSKeyfile, "")
304316
createTLSSNISecret(t, deployment.GetKubeCli(), "sni2", deployment.Namespace(), constants.SecretTLSKeyfile, "")
@@ -404,6 +416,9 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) {
404416
}(),
405417
},
406418
},
419+
Features: testCaseFeatures{
420+
TLSSNI: true,
421+
},
407422
Resources: func(t *testing.T, deployment *Deployment) {
408423
createTLSSNISecret(t, deployment.GetKubeCli(), "sni1", deployment.Namespace(), constants.SecretTLSKeyfile, "")
409424
createTLSSNISecret(t, deployment.GetKubeCli(), "sni2", deployment.Namespace(), constants.SecretTLSKeyfile, "")

pkg/deployment/deployment_run_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"fmt"
2828
"testing"
2929

30+
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
31+
3032
"github.com/rs/zerolog/log"
3133

3234
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
@@ -92,6 +94,15 @@ func runTestCase(t *testing.T, testCase testCaseStruct) {
9294
testCase.Resources(t, d)
9395
}
9496

97+
// Set features
98+
{
99+
*features.EncryptionRotation().EnabledPointer() = testCase.Features.EncryptionRotation
100+
require.Equal(t, testCase.Features.EncryptionRotation, *features.EncryptionRotation().EnabledPointer())
101+
*features.JWTRotation().EnabledPointer() = testCase.Features.JWTRotation
102+
*features.TLSSNI().EnabledPointer() = testCase.Features.TLSSNI
103+
*features.TLSRotation().EnabledPointer() = testCase.Features.TLSRotation
104+
}
105+
95106
// Act
96107
cache, err := inspector.NewInspector(d.GetKubeCli(), d.GetNamespace())
97108
require.NoError(t, err)

pkg/deployment/deployment_suite_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const (
6868
testYes = "yes"
6969
)
7070

71+
type testCaseFeatures struct {
72+
TLSSNI, TLSRotation, JWTRotation, EncryptionRotation bool
73+
}
74+
7175
type testCaseStruct struct {
7276
Name string
7377
ArangoDeployment *api.ArangoDeployment
@@ -78,6 +82,7 @@ type testCaseStruct struct {
7882
ExpectedError error
7983
ExpectedEvent string
8084
ExpectedPod core.Pod
85+
Features testCaseFeatures
8186
}
8287

8388
func createTestTLSVolume(serverGroupString, ID string) core.Volume {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package features
22+
23+
func init() {
24+
registerFeature(encryptionRotation)
25+
}
26+
27+
var encryptionRotation = &feature{
28+
name: "encryption-rotation",
29+
description: "Encryption Key rotation in runtime",
30+
version: "3.7.0",
31+
enterpriseRequired: true,
32+
enabledByDefault: false,
33+
}
34+
35+
func EncryptionRotation() Feature {
36+
return encryptionRotation
37+
}

0 commit comments

Comments
 (0)