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

95 lines
3 KiB
Go
Raw Normal View History

2018-04-06 09:56:16 +00:00
//
// DISCLAIMER
//
2020-03-04 10:25:14 +00:00
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
2018-04-06 09:56:16 +00:00
//
// 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 Ewout Prangsma
//
2018-02-27 08:30:00 +00:00
package tests
import (
2018-02-27 10:19:46 +00:00
"context"
2018-02-27 08:30:00 +00:00
"crypto/rand"
2021-03-23 15:47:28 +00:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2018-02-27 08:30:00 +00:00
"strings"
"testing"
"github.com/stretchr/testify/assert"
2018-02-27 08:30:00 +00:00
"github.com/dchest/uniuri"
2019-11-04 07:49:24 +00:00
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2018-03-13 15:25:33 +00:00
"github.com/arangodb/kube-arangodb/pkg/client"
2018-03-23 09:03:39 +00:00
"github.com/arangodb/kube-arangodb/pkg/util"
2018-03-13 15:25:33 +00:00
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
2018-02-27 08:30:00 +00:00
)
// TestRocksDBEncryptionSingle tests the creating of a single server deployment
// with RocksDB & Encryption.
func TestRocksDBEncryptionSingle(t *testing.T) {
2018-03-01 10:15:18 +00:00
longOrSkip(t)
2018-02-27 08:30:00 +00:00
image := getEnterpriseImageOrSkip(t)
2020-04-06 11:20:33 +00:00
c := client.MustNewClient()
2018-02-27 08:30:00 +00:00
kubecli := mustNewKubeClient(t)
ns := getNamespace(t)
2018-08-30 14:57:08 +00:00
secrets := kubecli.CoreV1().Secrets(ns)
2018-02-27 08:30:00 +00:00
// Prepull enterprise images
assert.NoError(t, prepullArangoImage(kubecli, image, ns))
2018-02-27 08:30:00 +00:00
// Prepare deployment config
depl := newDeployment("test-rocksdb-enc-sng-" + uniuri.NewLen(4))
2018-03-23 09:03:39 +00:00
depl.Spec.Mode = api.NewMode(api.DeploymentModeSingle)
depl.Spec.Image = util.NewString(image)
depl.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineRocksDB)
depl.Spec.RocksDB.Encryption.KeySecretName = util.NewString(strings.ToLower(uniuri.New()))
2018-02-27 08:30:00 +00:00
// Create encryption key secret
key := make([]byte, 32)
rand.Read(key)
2018-08-30 14:57:08 +00:00
if err := k8sutil.CreateEncryptionKeySecret(secrets, depl.Spec.RocksDB.Encryption.GetKeySecretName(), key); err != nil {
2018-02-27 08:30:00 +00:00
t.Fatalf("Create encryption key secret failed: %v", err)
}
// Create deployment
2021-03-23 15:47:28 +00:00
_, err := c.DatabaseV1().ArangoDeployments(ns).Create(context.Background(), depl, metav1.CreateOptions{})
2018-02-27 08:30:00 +00:00
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
defer deferedCleanupDeployment(c, depl.GetName(), ns)
2018-02-27 08:30:00 +00:00
// Wait for deployment to be ready
2018-03-27 13:53:02 +00:00
apiObject, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentIsReady())
2018-02-27 08:30:00 +00:00
if err != nil {
2018-03-28 09:05:49 +00:00
t.Fatalf("Deployment not running in time: %v", err)
2018-02-27 08:30:00 +00:00
}
// Create database client
2018-02-27 10:19:46 +00:00
ctx := context.Background()
2018-08-06 13:46:19 +00:00
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t, nil)
2018-02-27 08:30:00 +00:00
// Wait for single server available
2018-03-27 06:46:05 +00:00
if err := waitUntilVersionUp(client, nil); err != nil {
2018-02-27 08:30:00 +00:00
t.Fatalf("Single server not running returning version in time: %v", err)
}
// Cleanup
removeDeployment(c, depl.GetName(), ns)
2018-03-23 09:03:39 +00:00
removeSecret(kubecli, depl.Spec.RocksDB.Encryption.GetKeySecretName(), ns)
2018-02-27 08:30:00 +00:00
}