Skip to content

Feature/add tests for immutable cluster parameters #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions tests/immutable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//
// DISCLAIMER
//
// Copyright 2018 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 Kaveh Vahedipour
// Author Ewout Prangsma
//

package tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add file header


import (
"context"
"fmt"
"testing"
"time"

"github.com/dchest/uniuri"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
"github.com/arangodb/kube-arangodb/pkg/client"
)

// TestImmutableFields tests that several immutable fields in the deployment
// spec are reverted to their original value.
func TestImmutableFields(t *testing.T) {
longOrSkip(t)
c := client.MustNewInCluster()
kubecli := mustNewKubeClient(t)
ns := getNamespace(t)
revertTimeout := time.Second * 30

// Prepare deployment config
depl := newDeployment("test-ise-" + uniuri.NewLen(4))
depl.Spec.Mode = api.NewMode(api.DeploymentModeSingle)
depl.Spec.SetDefaults(depl.GetName())

// Create deployment
apiObject, err := c.DatabaseV1alpha().ArangoDeployments(ns).Create(depl)
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}

// Wait for deployment to be ready
if _, err := waitUntilDeployment(c, depl.GetName(), ns, deploymentHasState(api.DeploymentStateRunning)); err != nil {
t.Fatalf("Deployment not running in time: %v", err)
}

// Create a database client
ctx := context.Background()
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)

// Wait for single server to be completely ready
if err := waitUntilVersionUp(client); err != nil {
t.Fatalf("Single server not up in time: %v", err)
}

// Try to reset storageEngine ===============================================
if _, err := updateDeployment(c, depl.GetName(), ns,
func(spec *api.DeploymentSpec) {
spec.StorageEngine = api.NewStorageEngine(api.StorageEngineMMFiles)
}); err != nil {
t.Fatalf("Failed to update the StorageEngine setting: %v", err)
}

// Wait for StorageEngine parameter to be back to RocksDB
if _, err := waitUntilDeployment(c, depl.GetName(), ns,
func(depl *api.ArangoDeployment) error {
if api.StorageEngineOrDefault(depl.Spec.StorageEngine) == api.StorageEngineRocksDB {
return nil
}
return fmt.Errorf("StorageEngine not back to %s", api.StorageEngineRocksDB)
}, revertTimeout); err != nil {
t.Errorf("StorageEngine parameter is immutable: %v", err)
}

/*
Secrets are a special case that we'll deal with later
// Try to reset the RocksDB encryption key ==================================
if _, err := updateDeployment(c, depl.GetName(), ns,
func(spec *api.DeploymentSpec) {
spec.RocksDB.Encryption.KeySecretName = util.NewString("foobarbaz")
}); err != nil {
t.Fatalf("Failed to update the RocksDB encryption key: %v", err)
}

// Wait for deployment mode to be set back to cluster
if _, err := waitUntilDeployment(c, depl.GetName(), ns,
func(depl *api.ArangoDeployment) error {
if util.StringOrDefault(depl.Spec.RocksDB.Encryption.KeySecretName) == "test.encryption.keySecretName" {
return nil
}
return fmt.Errorf("RocksDB encryption key not back to %s", "test.encryption.keySecretName")
}, revertTimeout); err != nil {
t.Errorf("RocksDB encryption key is mutable: %v", err)
}
*/

// Try to reset the deployment type ==========================================
if _, err := updateDeployment(c, depl.GetName(), ns,
func(spec *api.DeploymentSpec) {
spec.Mode = api.NewMode(api.DeploymentModeCluster)
}); err != nil {
t.Fatalf("Failed to update the deployment mode: %v", err)
}

// Wait for deployment mode to be set back to cluster
if _, err := waitUntilDeployment(c, depl.GetName(), ns,
func(depl *api.ArangoDeployment) error {
expected := api.DeploymentModeSingle
if api.ModeOrDefault(depl.Spec.Mode) == expected {
return nil
}
return fmt.Errorf("Deployment mode not back to %s", expected)
}, revertTimeout); err != nil {
t.Errorf("Deployment mode is mutable: %v", err)
}

// Cleanup
removeDeployment(c, depl.GetName(), ns)
}
8 changes: 6 additions & 2 deletions tests/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func newDeployment(name string) *api.ArangoDeployment {

// waitUntilDeployment waits until a deployment with given name in given namespace
// reached a state where the given predicate returns true.
func waitUntilDeployment(cli versioned.Interface, deploymentName, ns string, predicate func(*api.ArangoDeployment) error) (*api.ArangoDeployment, error) {
func waitUntilDeployment(cli versioned.Interface, deploymentName, ns string, predicate func(*api.ArangoDeployment) error, timeout ...time.Duration) (*api.ArangoDeployment, error) {
var result *api.ArangoDeployment
op := func() error {
obj, err := cli.DatabaseV1alpha().ArangoDeployments(ns).Get(deploymentName, metav1.GetOptions{})
Expand All @@ -132,7 +132,11 @@ func waitUntilDeployment(cli versioned.Interface, deploymentName, ns string, pre
}
return nil
}
if err := retry.Retry(op, deploymentReadyTimeout); err != nil {
actualTimeout := deploymentReadyTimeout
if len(timeout) > 0 {
actualTimeout = timeout[0]
}
if err := retry.Retry(op, actualTimeout); err != nil {
return nil, maskAny(err)
}
return result, nil
Expand Down