Skip to content

Commit 46938ae

Browse files
piotrszymaAgalin
authored andcommitted
fix: parallelarchive e2e test not executed by test runner (#59)
1. Renamed the test file 2. Added initial backup to setup 3. Changed log reading func to use pgbackrest plugin container Signed-off-by: Piotr Szyma <thompson2908@gmail.com>
1 parent 420c5db commit 46938ae

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

internal/cnpgi/operator/lifecycle.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ func reconcilePodSpec(
375375
resources *corev1.ResourceRequirements,
376376
securityContext *corev1.SecurityContext,
377377
) error {
378+
//nolint:prealloc
378379
envs := []corev1.EnvVar{
379380
{
380381
Name: "NAMESPACE",

internal/pgbackrest/archiver/archiver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func (archiver *WALArchiver) PgbackrestCheckWalArchiveOptions(
150150
configuration *pgbackrestApi.PgbackrestConfiguration,
151151
clusterName string,
152152
) ([]string, error) {
153+
//nolint:prealloc
153154
var options []string
154155

155156
options, err := pgbackrestCommand.AppendCloudProviderOptionsFromConfiguration(ctx, options, configuration)

internal/pgbackrest/backup/backup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func (b *Command) getStanzaCreateOptions(
178178
ctx context.Context,
179179
stanza string,
180180
) ([]string, error) {
181+
//nolint:prealloc
181182
options := []string{
182183
"stanza-create",
183184
}

internal/pgbackrest/command/backuplist.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func executeQueryCommand(
6060
) (string, error) {
6161
contextLogger := log.FromContext(ctx).WithName("pgbackrest")
6262

63+
//nolint:prealloc
6364
options := []string{"info", "--output", "json"}
6465

6566
options, err := AppendCloudProviderOptionsFromConfiguration(ctx, options, pgbackrestConfiguration)

test/e2e/internal/tests/parallelarchive/fixtures.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type parallelArchiveTestResources struct {
3737
ObjectStoreResources *objectstore.Resources
3838
Archive *pluginPgbackrestV1.Archive
3939
Cluster *cloudnativepgv1.Cluster
40+
Backup *cloudnativepgv1.Backup
4041
}
4142

4243
// createParallelArchiveTestResources creates test resources for parallel archive testing
@@ -46,6 +47,7 @@ func createParallelArchiveTestResources(namespace string, maxParallel int) paral
4647
resources.ObjectStoreResources = objectstore.NewMinioObjectStoreResources(namespace, minio)
4748
resources.Archive = objectstore.NewMinioArchive(namespace, archiveName, minio, maxParallel)
4849
resources.Cluster = createClusterWithArchive(namespace, clusterName, archiveName)
50+
resources.Backup = createPluginBackup(namespace)
4951

5052
return resources
5153
}
@@ -85,3 +87,28 @@ func createClusterWithArchive(namespace, clusterName, archiveName string) *cloud
8587

8688
return cluster
8789
}
90+
91+
// createPluginBackup creates a backup resource to initialize the pgBackRest stanza
92+
func createPluginBackup(namespace string) *cloudnativepgv1.Backup {
93+
backup := &cloudnativepgv1.Backup{
94+
TypeMeta: metav1.TypeMeta{
95+
Kind: "Backup",
96+
APIVersion: "postgresql.cnpg.io/v1",
97+
},
98+
ObjectMeta: metav1.ObjectMeta{
99+
Name: "plugin-backup",
100+
Namespace: namespace,
101+
},
102+
Spec: cloudnativepgv1.BackupSpec{
103+
Cluster: cloudnativepgv1.LocalObjectReference{
104+
Name: clusterName,
105+
},
106+
Method: "plugin",
107+
Target: "primary",
108+
PluginConfiguration: &cloudnativepgv1.BackupPluginConfiguration{
109+
Name: "pgbackrest.cnpg.opera.com",
110+
},
111+
},
112+
}
113+
return backup
114+
}

test/e2e/internal/tests/parallelarchive/parallel_archive_test.go renamed to test/e2e/internal/tests/parallelarchive/parallel_archive.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"time"
2222

23+
v1 "github.com/cloudnative-pg/api/pkg/api/v1"
2324
corev1 "k8s.io/api/core/v1"
2425
"k8s.io/apimachinery/pkg/types"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -79,10 +80,10 @@ var _ = Describe("Parallel WAL Archive", func() {
7980
g.Expect(internalCluster.IsReady(*cluster)).To(BeTrue())
8081
}).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())
8182

82-
By("creating initial data to generate some WAL traffic")
8383
clientSet, cfg, err := internalClient.NewClientSet()
8484
Expect(err).NotTo(HaveOccurred())
8585

86+
By("adding initial data to PostgreSQL")
8687
_, _, err = command.ExecuteInContainer(ctx,
8788
*clientSet,
8889
cfg,
@@ -95,6 +96,17 @@ var _ = Describe("Parallel WAL Archive", func() {
9596
[]string{"psql", "-tAc", "CREATE TABLE parallel_test (id int, data text);"})
9697
Expect(err).NotTo(HaveOccurred())
9798

99+
By("creating a backup to initialize pgBackRest stanza")
100+
backup := testResources.Backup
101+
Expect(cl.Create(ctx, backup)).To(Succeed())
102+
103+
By("waiting for the backup to complete")
104+
Eventually(func(g Gomega) {
105+
g.Expect(cl.Get(ctx, types.NamespacedName{Name: backup.Name, Namespace: backup.Namespace},
106+
backup)).To(Succeed())
107+
g.Expect(backup.Status.Phase).To(BeEquivalentTo(v1.BackupPhaseCompleted))
108+
}).Within(2 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
109+
98110
By("rapidly generating multiple WAL files to queue them for archiving")
99111
// Generate 10 WAL switches in quick succession to create a backlog
100112
// that can be processed in parallel
@@ -124,7 +136,7 @@ var _ = Describe("Parallel WAL Archive", func() {
124136
clientSet,
125137
cluster.Namespace,
126138
fmt.Sprintf("%s-1", cluster.Name),
127-
"postgres",
139+
"plugin-pgbackrest",
128140
nil,
129141
)
130142
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)