From 283577cb4b7707858a31f4a864056ba06b5acd86 Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Tue, 11 May 2021 19:19:29 +0100 Subject: [PATCH] [Issue#200] Add persistent storage to make the scale-down e2e test involving transaction recovery Fixes #200 --- .../transaction_recovery_test.go | 2 +- test/framework/common.go | 2 +- test/framework/wildlfyserver.go | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/pkg/controller/wildflyserver/transaction_recovery_test.go b/pkg/controller/wildflyserver/transaction_recovery_test.go index c135d5fe..5fe20c9d 100644 --- a/pkg/controller/wildflyserver/transaction_recovery_test.go +++ b/pkg/controller/wildflyserver/transaction_recovery_test.go @@ -90,7 +90,7 @@ func setupBeforeScaleDown(t *testing.T, wildflyServer *wildflyv1alpha1.WildFlySe s := scheme.Scheme s.AddKnownTypes(wildflyv1alpha1.SchemeGroupVersion, wildflyServer) // Create a fake client to mock API calls. - cl = fake.NewFakeClient(objs...) + cl = fake.NewFakeClientWithScheme(s, objs...) // Create a ReconcileWildFlyServer object with the scheme and fake client. r = &ReconcileWildFlyServer{client: cl, scheme: s, recorder: eventRecorderMock{}, isOpenShift: false} diff --git a/test/framework/common.go b/test/framework/common.go index 0d5246a1..34e72be8 100644 --- a/test/framework/common.go +++ b/test/framework/common.go @@ -144,7 +144,7 @@ func WildflyScaleDownTest(t *testing.T, applicationTag string) { name := "example-wildfly-" + unixEpoch() // create wildflyserver custom resource - wildflyServer := MakeBasicWildFlyServer(namespace, name, "quay.io/wildfly-quickstarts/wildfly-operator-quickstart:"+applicationTag, 2, false) + wildflyServer := MakeBasicWildFlyServerWithStorage(namespace, name, "quay.io/wildfly-quickstarts/wildfly-operator-quickstart:"+applicationTag, 2, false) // waiting for number of pods matches the desired state err = CreateAndWaitUntilReady(f, ctx, t, wildflyServer) if err != nil { diff --git a/test/framework/wildlfyserver.go b/test/framework/wildlfyserver.go index 6df2c747..70736ec5 100644 --- a/test/framework/wildlfyserver.go +++ b/test/framework/wildlfyserver.go @@ -6,6 +6,7 @@ import ( goctx "context" "fmt" "io" + "k8s.io/apimachinery/pkg/api/resource" "regexp" "strings" "testing" @@ -48,6 +49,37 @@ func MakeBasicWildFlyServer(ns, name, applicationImage string, size int32, boota } } +// MakeBasicWildFlyServerWithStorage creates a basic WildFlyServer resource configured with a persistent storage assuming it will be provisioned +// dynamically by the cluster provider +func MakeBasicWildFlyServerWithStorage(ns, name, applicationImage string, size int32, bootableJar bool) *wildflyv1alpha1.WildFlyServer { + return &wildflyv1alpha1.WildFlyServer{ + TypeMeta: metav1.TypeMeta{ + Kind: "WildFlyServer", + APIVersion: "wildfly.org/v1alpha1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: ns, + }, + Spec: wildflyv1alpha1.WildFlyServerSpec{ + ApplicationImage: applicationImage, + Replicas: size, + BootableJar: bootableJar, + Storage: &wildflyv1alpha1.StorageSpec{ + VolumeClaimTemplate: corev1.PersistentVolumeClaim{ + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("5Mi"), + }, + }, + }, + }, + }, + }, + } +} + // CreateStandaloneConfigMap creates a ConfigMap for the standalone configuration func CreateStandaloneConfigMap(f *framework.Framework, ctx *framework.Context, ns string, name string, key string, file []byte) error { configMap := &corev1.ConfigMap{