Skip to content

Commit

Permalink
Drop single namespace assumption from E2E tests (#1446)
Browse files Browse the repository at this point in the history
* Drop single namespace assumption from E2E tests

Also adds a test for cross namespace association that currently only
works in local mode.

* CR Fix: Change test function comment

* Fix test failure
  • Loading branch information
charith-elastic committed Aug 2, 2019
1 parent a2aa835 commit bd233c1
Show file tree
Hide file tree
Showing 22 changed files with 120 additions and 76 deletions.
23 changes: 12 additions & 11 deletions operators/test/e2e/apm/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func TestUpdateConfiguration(t *testing.T) {
}

name := "test-apm-configuration"
namespace := test.Ctx().ManagedNamespace(0)
esBuilder := elasticsearch.NewBuilder(name).
WithESMasterDataNodes(3, elasticsearch.DefaultResources)
apmBuilder := apmserver.NewBuilder(name).
WithNamespace(test.Ctx().ManagedNamespace(0)).
WithNamespace(namespace).
WithVersion(test.Ctx().ElasticStackVersion).
WithRestrictedSecurityContext()

Expand All @@ -77,7 +78,7 @@ func TestUpdateConfiguration(t *testing.T) {
},
},
// Keystore should be empty
test.CheckKeystoreEntries(k, test.ApmServerPodListOptions(name), APMKeystoreCmd, nil),
test.CheckKeystoreEntries(k, test.ApmServerPodListOptions(namespace, name), APMKeystoreCmd, nil),
}
}
apmNamespacedName := types.NamespacedName{
Expand All @@ -90,7 +91,7 @@ func TestUpdateConfiguration(t *testing.T) {
{
Name: "Check the value of a parameter in the configuration",
Test: func(t *testing.T) {
config, err := partialAPMConfiguration(k, name)
config, err := partialAPMConfiguration(k, namespace, name)
require.NoError(t, err)
esHost := services.ExternalServiceURL(esBuilder.Elasticsearch)
require.Equal(t, config.Output.Elasticsearch.Hosts[0], esHost)
Expand All @@ -101,7 +102,7 @@ func TestUpdateConfiguration(t *testing.T) {
Name: "Add a Keystore to the APM server",
Test: func(t *testing.T) {
// get current pod id
pods, err := k.GetPods(test.ApmServerPodListOptions(name))
pods, err := k.GetPods(test.ApmServerPodListOptions(namespace, name))
require.NoError(t, err)
require.True(t, len(pods) == 1)
previousPodUID = &pods[0].UID
Expand All @@ -118,7 +119,7 @@ func TestUpdateConfiguration(t *testing.T) {
Name: "APM Pod should be recreated",
Test: test.Eventually(func() error {
// get current pod id
pods, err := k.GetPods(test.ApmServerPodListOptions(name))
pods, err := k.GetPods(test.ApmServerPodListOptions(namespace, name))
if err != nil {
return err
}
Expand All @@ -132,13 +133,13 @@ func TestUpdateConfiguration(t *testing.T) {
}),
},

test.CheckKeystoreEntries(k, test.ApmServerPodListOptions(name), APMKeystoreCmd, []string{"logging.verbose"}),
test.CheckKeystoreEntries(k, test.ApmServerPodListOptions(namespace, name), APMKeystoreCmd, []string{"logging.verbose"}),

test.Step{
Name: "Customize configuration of the APM server",
Test: func(t *testing.T) {
// get current pod id
pods, err := k.GetPods(test.ApmServerPodListOptions(name))
pods, err := k.GetPods(test.ApmServerPodListOptions(namespace, name))
require.NoError(t, err)
require.True(t, len(pods) == 1)
previousPodUID = &pods[0].UID
Expand All @@ -156,7 +157,7 @@ func TestUpdateConfiguration(t *testing.T) {
Name: "APM Pod should be recreated",
Test: test.Eventually(func() error {
// get current pod id
pods, err := k.GetPods(test.ApmServerPodListOptions(name))
pods, err := k.GetPods(test.ApmServerPodListOptions(namespace, name))
if err != nil {
return err
}
Expand All @@ -173,7 +174,7 @@ func TestUpdateConfiguration(t *testing.T) {
test.Step{
Name: "Check the value of a parameter in the configuration",
Test: func(t *testing.T) {
config, err := partialAPMConfiguration(k, name)
config, err := partialAPMConfiguration(k, namespace, name)
require.NoError(t, err)
require.Equal(t, config.Output.Elasticsearch.CompressionLevel, 1) // value should be updated to 1
},
Expand All @@ -194,10 +195,10 @@ func TestUpdateConfiguration(t *testing.T) {

}

func partialAPMConfiguration(k *test.K8sClient, name string) (PartialApmConfiguration, error) {
func partialAPMConfiguration(k *test.K8sClient, namespace, name string) (PartialApmConfiguration, error) {
var config PartialApmConfiguration
// get current pod id
pods, err := k.GetPods(test.ApmServerPodListOptions(name))
pods, err := k.GetPods(test.ApmServerPodListOptions(namespace, name))
if err != nil {
return config, err
}
Expand Down
14 changes: 7 additions & 7 deletions operators/test/e2e/es/failure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestKillOneDataNode(t *testing.T) {
}

test.RunFailure(t,
test.KillNodeSteps(test.ESPodListOptions(b.Elasticsearch.Name), matchDataNode),
test.KillNodeSteps(test.ESPodListOptions(b.Elasticsearch.Namespace, b.Elasticsearch.Name), matchDataNode),
b)
}

Expand All @@ -47,7 +47,7 @@ func TestKillOneMasterNode(t *testing.T) {
}

test.RunFailure(t,
test.KillNodeSteps(test.ESPodListOptions(b.Elasticsearch.Name), matchMasterNode),
test.KillNodeSteps(test.ESPodListOptions(b.Elasticsearch.Namespace, b.Elasticsearch.Name), matchMasterNode),
b)
}

Expand All @@ -60,7 +60,7 @@ func TestKillSingleNodeReusePV(t *testing.T) {
}

test.RunFailure(t,
test.KillNodeSteps(test.ESPodListOptions(b.Elasticsearch.Name), matchNode),
test.KillNodeSteps(test.ESPodListOptions(b.Elasticsearch.Namespace, b.Elasticsearch.Name), matchNode),
b)
}

Expand Down Expand Up @@ -93,7 +93,7 @@ func TestKillCorrectPVReuse(t *testing.T) {
{
Name: "Kill a node",
Test: func(t *testing.T) {
pods, err := k.GetPods(test.ESPodListOptions(b.Elasticsearch.Name))
pods, err := k.GetPods(test.ESPodListOptions(b.Elasticsearch.Namespace, b.Elasticsearch.Name))
require.NoError(t, err)
require.True(t, len(pods) > 0, "need at least one pod to kill")
for i, pod := range pods {
Expand All @@ -108,7 +108,7 @@ func TestKillCorrectPVReuse(t *testing.T) {
{
Name: "Wait for pod to be deleted",
Test: test.Eventually(func() error {
pod, err := k.GetPod(killedPod.Name)
pod, err := k.GetPod(killedPod.Namespace, killedPod.Name)
if err != nil && !apierrors.IsNotFound(err) {
return err
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestKillCorrectPVReuse(t *testing.T) {
Test: func(t *testing.T) {
// should be resurrected with same name due to second PVC still around and forcing the pods name
// back to the old one
pod, err := k.GetPod(killedPod.Name)
pod, err := k.GetPod(killedPod.Namespace, killedPod.Name)
require.NoError(t, err)
var checkedVolumes bool
for _, v := range pod.Spec.Volumes {
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestDeleteServices(t *testing.T) {
{
Name: "Delete external service",
Test: func(t *testing.T) {
s, err := k.GetService(esname.HTTPService(b.Elasticsearch.Name))
s, err := k.GetService(b.Elasticsearch.Namespace, esname.HTTPService(b.Elasticsearch.Name))
require.NoError(t, err)
err = k.Client.Delete(s)
require.NoError(t, err)
Expand Down
41 changes: 41 additions & 0 deletions operators/test/e2e/kb/association_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package kb

import (
"testing"

"github.com/elastic/cloud-on-k8s/operators/test/e2e/test"
"github.com/elastic/cloud-on-k8s/operators/test/e2e/test/elasticsearch"
"github.com/elastic/cloud-on-k8s/operators/test/e2e/test/kibana"
)

// TestCrossNSAssociation tests associating Elasticsearch and Kibana running in different namespaces.
func TestCrossNSAssociation(t *testing.T) {
// This test currently does not work in the E2E environment because each namespace has a dedicated
// controller (see https://github.com/elastic/cloud-on-k8s/issues/1438)
if !test.Ctx().Local {
t.SkipNow()
}

esNamespace := test.Ctx().ManagedNamespace(0)
kbNamespace := test.Ctx().ManagedNamespace(1)
name := "test-cross-ns-assoc"

esBuilder := elasticsearch.NewBuilder(name).
WithNamespace(esNamespace).
WithESMasterDataNodes(1, elasticsearch.DefaultResources).
WithRestrictedSecurityContext()

kbBuilder := kibana.NewBuilder(name).
WithNamespace(kbNamespace).
WithNodeCount(1).
WithRestrictedSecurityContext()
kbBuilder.Kibana.Spec.ElasticsearchRef.Name = name
kbBuilder.Kibana.Spec.ElasticsearchRef.Namespace = esNamespace

builders := []test.Builder{esBuilder, kbBuilder}
test.RunMutations(t, builders, builders)
}
2 changes: 1 addition & 1 deletion operators/test/e2e/kb/failure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestKillKibanaPod(t *testing.T) {
return true
}
test.RunFailure(t,
test.KillNodeSteps(test.KibanaPodListOptions(kbBuilder.Kibana.Name), matchFirst),
test.KillNodeSteps(test.KibanaPodListOptions(kbBuilder.Kibana.Namespace, kbBuilder.Kibana.Name), matchFirst),
esBuilder, kbBuilder)
}

Expand Down
8 changes: 5 additions & 3 deletions operators/test/e2e/kb/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func TestUpdateKibanaSecureSettings(t *testing.T) {
WithNodeCount(1).
WithKibanaSecureSettings(secureSettings.Name)

namespace := kbBuilder.Kibana.Namespace

initStepsFn := func(k *test.K8sClient) test.StepList {
return test.StepList{
{
Expand All @@ -61,7 +63,7 @@ func TestUpdateKibanaSecureSettings(t *testing.T) {
}
stepsFn := func(k *test.K8sClient) test.StepList {
return test.StepList{
test.CheckKeystoreEntries(k, test.KibanaPodListOptions(name), KibanaKeystoreCmd, []string{"logging.verbose"}),
test.CheckKeystoreEntries(k, test.KibanaPodListOptions(namespace, name), KibanaKeystoreCmd, []string{"logging.verbose"}),
// modify the secure settings secret
test.Step{
Name: "Modify secure settings secret",
Expand All @@ -77,7 +79,7 @@ func TestUpdateKibanaSecureSettings(t *testing.T) {
},

// keystore should be updated accordingly
test.CheckKeystoreEntries(k, test.KibanaPodListOptions(name), KibanaKeystoreCmd, []string{"logging.json", "logging.verbose"}),
test.CheckKeystoreEntries(k, test.KibanaPodListOptions(namespace, name), KibanaKeystoreCmd, []string{"logging.json", "logging.verbose"}),

// remove the secure settings reference
test.Step{
Expand All @@ -95,7 +97,7 @@ func TestUpdateKibanaSecureSettings(t *testing.T) {
},

// keystore should be updated accordingly
test.CheckKeystoreEntries(k, test.KibanaPodListOptions(name), KibanaKeystoreCmd, nil),
test.CheckKeystoreEntries(k, test.KibanaPodListOptions(namespace, name), KibanaKeystoreCmd, nil),

// cleanup extra resources
test.Step{
Expand Down
2 changes: 1 addition & 1 deletion operators/test/e2e/kb/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestUpdateKibanaResources(t *testing.T) {
test.Step{
Name: "Check resources are propagated to the pod spec",
Test: func(t *testing.T) {
pods, err := k.GetPods(test.KibanaPodListOptions(name))
pods, err := k.GetPods(test.KibanaPodListOptions(kbBuilder.Kibana.Namespace, name))
require.NoError(t, err)
for _, p := range pods {
require.Equal(t, resources, p.Spec.Containers[0].Resources)
Expand Down
8 changes: 4 additions & 4 deletions operators/test/e2e/test/apmserver/checks_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func CheckApmServerPodsCount(b Builder, k *test.K8sClient) test.Step {
return test.Step{
Name: "ApmServer pods count should match the expected one",
Test: test.Eventually(func() error {
return k.CheckPodCount(test.ApmServerPodListOptions(b.ApmServer.Name), int(b.ApmServer.Spec.NodeCount))
return k.CheckPodCount(test.ApmServerPodListOptions(b.ApmServer.Namespace, b.ApmServer.Name), int(b.ApmServer.Spec.NodeCount))
}),
}
}
Expand All @@ -63,7 +63,7 @@ func CheckApmServerPodsRunning(b Builder, k *test.K8sClient) test.Step {
return test.Step{
Name: "ApmServer pods should eventually be running",
Test: test.Eventually(func() error {
pods, err := k.GetPods(test.ApmServerPodListOptions(b.ApmServer.Name))
pods, err := k.GetPods(test.ApmServerPodListOptions(b.ApmServer.Namespace, b.ApmServer.Name))
if err != nil {
return err
}
Expand All @@ -85,7 +85,7 @@ func CheckServices(b Builder, k *test.K8sClient) test.Step {
for _, s := range []string{
b.ApmServer.Name + "-apm-http",
} {
if _, err := k.GetService(s); err != nil {
if _, err := k.GetService(b.ApmServer.Namespace, s); err != nil {
return err
}
}
Expand All @@ -102,7 +102,7 @@ func CheckServicesEndpoints(b Builder, k *test.K8sClient) test.Step {
for endpointName, addrCount := range map[string]int{
b.ApmServer.Name + "-apm-http": int(b.ApmServer.Spec.NodeCount),
} {
endpoints, err := k.GetEndpoints(endpointName)
endpoints, err := k.GetEndpoints(b.ApmServer.Namespace, endpointName)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion operators/test/e2e/test/apmserver/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewApmServerClient(as apmtype.ApmServer, k *test.K8sClient) (*ApmClient, er
var caCerts []*x509.Certificate
if as.Spec.HTTP.TLS.Enabled() {
scheme = "https"
crts, err := k.GetHTTPCerts(name.APMNamer, as.Name)
crts, err := k.GetHTTPCerts(name.APMNamer, as.Namespace, as.Name)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion operators/test/e2e/test/apmserver/steps_deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (b Builder) DeletionTestSteps(k *test.K8sClient) test.StepList {
{
Name: "APM Server pods should be eventually be removed",
Test: test.Eventually(func() error {
return k.CheckPodCount(test.ApmServerPodListOptions(b.ApmServer.Name), 0)
return k.CheckPodCount(test.ApmServerPodListOptions(b.ApmServer.Namespace, b.ApmServer.Name), 0)
}),
},
}
Expand Down
2 changes: 1 addition & 1 deletion operators/test/e2e/test/apmserver/steps_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList {
}
// wait for ES pods to disappear
test.Eventually(func() error {
return k.CheckPodCount(test.ApmServerPodListOptions(b.ApmServer.Name), 0)
return k.CheckPodCount(test.ApmServerPodListOptions(b.ApmServer.Namespace, b.ApmServer.Name), 0)
})(t)
},
},
Expand Down
Loading

0 comments on commit bd233c1

Please sign in to comment.