Skip to content

Commit

Permalink
test: add e2e case of declarative database with delete reclaim policy
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriele Quaresima <[email protected]>
  • Loading branch information
gabriele-wolfox committed Oct 1, 2024
1 parent 25281f5 commit 7cb2e75
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 15 deletions.
93 changes: 82 additions & 11 deletions tests/e2e/declarative_database_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ import (
// - spinning up a cluster, apply a declarative database on it

// Set of tests in which we use the declarative database CRD to add new databases on an existing cluster
var _ = Describe("Declarative databases management test", Label(tests.LabelSmoke, tests.LabelBasic), func() {
var _ = FDescribe("Declarative databases management test", Label(tests.LabelSmoke, tests.LabelBasic,
tests.LabelDeclarativeDatabases), func() {
const (
clusterManifest = fixturesDir + "/declarative_databases/cluster.yaml.template"
databaseManifest = fixturesDir + "/declarative_databases/database.yaml.template"
level = tests.Medium
clusterManifest = fixturesDir + "/declarative_databases/cluster.yaml.template"
databaseManifest = fixturesDir + "/declarative_databases/database.yaml.template"
databaseManifestWithDeleteReclaimPolicy = fixturesDir +
"/declarative_databases/database-with-delete-reclaim-policy.yaml.template"
level = tests.Medium
)

BeforeEach(func() {
Expand All @@ -47,13 +50,15 @@ var _ = Describe("Declarative databases management test", Label(tests.LabelSmoke

Context("plain vanilla cluster", Ordered, func() {
const (
namespacePrefix = "declarative-db"
databaseCrdName = "db-declarative"
dbname = "declarative"
namespacePrefix = "declarative-db"
databaseCrdName = "db-declarative"
databaseWithDeleteRetainPolicyCrdName = "db-declarative-delete"
dbname = "declarative"
)
var (
clusterName, namespace string
database *apiv1.Database
clusterName, namespace string
database *apiv1.Database
databaseWithDeleteRetainPolicy *apiv1.Database
)

BeforeAll(func() {
Expand Down Expand Up @@ -110,7 +115,7 @@ var _ = Describe("Declarative databases management test", Label(tests.LabelSmoke
}, 300).WithPolling(10 * time.Second).Should(Succeed())
})

By("verifying new database has been added", func() {
By("verifying the db exists", func() {
primaryPodInfo, err := env.GetClusterPrimary(namespace, clusterName)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -123,13 +128,79 @@ var _ = Describe("Declarative databases management test", Label(tests.LabelSmoke
Expect(utils.DeleteObject(env, database)).To(Succeed())
})

By("verifying database is still existing", func() {
By("verifying db is still existing", func() {
primaryPodInfo, err := env.GetClusterPrimary(namespace, clusterName)
Expect(err).ToNot(HaveOccurred())

assertDatabaseExists(namespace, primaryPodInfo.Name, dbname, true)
})
})
})
When("Database CRD reclaim policy is set to delete inside spec", func() {
It("can add a declarative database", func() {
By("applying Database CRD manifest", func() {
CreateResourceFromFile(namespace, databaseManifestWithDeleteReclaimPolicy)
_, err := env.GetResourceNameFromYAML(databaseManifestWithDeleteReclaimPolicy)
Expect(err).NotTo(HaveOccurred())
})
By("ensuring the Database CRD succeeded reconciliation", func() {
// get database object
databaseWithDeleteRetainPolicy = &apiv1.Database{}
databaseNamespacedName := types.NamespacedName{
Namespace: namespace,
Name: databaseWithDeleteRetainPolicyCrdName,
}

Eventually(func(g Gomega) {
err := env.Client.Get(env.Ctx, databaseNamespacedName, databaseWithDeleteRetainPolicy)
Expect(err).ToNot(HaveOccurred())
g.Expect(databaseWithDeleteRetainPolicy.Status.Ready).Should(BeTrue())
}, 300).WithPolling(10 * time.Second).Should(Succeed())
})

By("verifying the db exists", func() {
primaryPodInfo, err := env.GetClusterPrimary(namespace, clusterName)
Expect(err).ToNot(HaveOccurred())

assertDatabaseExists(namespace, primaryPodInfo.Name, dbname, true)
})
})

It("maintains the db when Database CRD is removed", func() {
By("remove Database CRD", func() {
Expect(utils.DeleteObject(env, databaseWithDeleteRetainPolicy)).To(Succeed())
})

By("verifying db has been removed", func() {
primaryPodInfo, err := env.GetClusterPrimary(namespace, clusterName)
Expect(err).ToNot(HaveOccurred())

assertDatabaseExists(namespace, primaryPodInfo.Name, dbname, false)
})
})

It("applies the Database CRD one last time to exercise finalizers removal when the namespace "+
"will be deleted", func() {
By("applying Database CRD manifest", func() {
CreateResourceFromFile(namespace, databaseManifestWithDeleteReclaimPolicy)
_, err := env.GetResourceNameFromYAML(databaseManifestWithDeleteReclaimPolicy)
Expect(err).NotTo(HaveOccurred())
})
By("ensuring the Database CRD succeeded reconciliation", func() {
// get database object
databaseWithDeleteRetainPolicy = &apiv1.Database{}
databaseNamespacedName := types.NamespacedName{
Namespace: namespace,
Name: databaseWithDeleteRetainPolicyCrdName,
}

Eventually(func(g Gomega) {
err := env.Client.Get(env.Ctx, databaseNamespacedName, databaseWithDeleteRetainPolicy)
Expect(err).ToNot(HaveOccurred())
g.Expect(databaseWithDeleteRetainPolicy.Status.Ready).Should(BeTrue())
}, 300).WithPolling(10 * time.Second).Should(Succeed())
})
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: db-declarative-delete
spec:
name: declarative
owner: app
databaseReclaimPolicy: delete
cluster:
name: cluster-with-declarative-databases
11 changes: 7 additions & 4 deletions tests/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ const (
// LabelBackupRestore is a label for only selecting backup and restore tests
LabelBackupRestore = "backup-restore"

// LabelBasic is a label for selecting basic test
// LabelBasic is a label for selecting basic test
LabelBasic = "basic"

// LabelClusterMetadata is a label for selecting cluster-metadata test
LabelClusterMetadata = "cluster-metadata"

// LabelDeclarativeDatabases is a label for selecting the test exercising declarative databases
LabelDeclarativeDatabases = "declarative-databases"

// LabelDisruptive is the string for labelling disruptive tests
LabelDisruptive = "disruptive"

Expand Down Expand Up @@ -74,7 +77,7 @@ const (
// LabelServiceConnectivity is a label for selecting service connections test
LabelServiceConnectivity = "service-connectivity"

// LabelSmoke is a label for selecting smoke test
// LabelSmoke is a label for selecting smoke test
LabelSmoke = "smoke"

// LabelSnapshot is a label for selecting snapshot tests
Expand All @@ -83,9 +86,9 @@ const (
// LabelStorage is a label for selecting storage test
LabelStorage = "storage"

// LabelTablespaces is a lable for selectin the tablespaces tests
// LabelTablespaces is a label for selecting the tablespaces tests
LabelTablespaces = "tablespaces"

// LabelUpgrade is the string for labelling upgrade tests
// LabelUpgrade is a label for upgrade tests
LabelUpgrade = "upgrade"
)

0 comments on commit 7cb2e75

Please sign in to comment.