Skip to content

Commit

Permalink
[bitnami/nats] Improve Ginkgo tests (#29462)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan131 committed Sep 17, 2024
1 parent 429ff90 commit 3ec3cfb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
39 changes: 27 additions & 12 deletions .vib/nats/ginkgo/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand All @@ -32,8 +33,8 @@ var _ = Describe("NATS", Ordered, func() {

When("a bucket is created and is scaled down to 0 replicas and back up", func() {
It("should have access to the created database", func() {

getAvailableReplicas := func(ss *appsv1.StatefulSet) int32 { return ss.Status.AvailableReplicas }
getRestartedAtAnnotation := func(pod *v1.Pod) string { return pod.Annotations["kubectl.kubernetes.io/restartedAt"] }
getSucceededJobs := func(j *batchv1.Job) int32 { return j.Status.Succeeded }
getOpts := metav1.GetOptions{}

Expand Down Expand Up @@ -68,6 +69,10 @@ var _ = Describe("NATS", Ordered, func() {
return c.BatchV1().Jobs(namespace).Get(ctx, createDBJobName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getSucceededJobs, Equal(int32(1))))

By("deleting the job once it has succeeded")
err = c.BatchV1().Jobs(namespace).Delete(ctx, createDBJobName, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())

By("puting a value into a key")
putJobName := fmt.Sprintf("%s-putbc-%s",
stsName, jobSuffix)
Expand All @@ -78,26 +83,28 @@ var _ = Describe("NATS", Ordered, func() {
return c.BatchV1().Jobs(namespace).Get(ctx, putJobName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getSucceededJobs, Equal(int32(1))))

// Give the application some time to sync the data
time.Sleep(10*time.Second)

By("scaling down to 0 replicas")
ss, err = utils.StsScale(ctx, c, ss, 0)
By("deleting the job once it has succeeded")
err = c.BatchV1().Jobs(namespace).Delete(ctx, putJobName, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())

Eventually(func() (*appsv1.StatefulSet, error) {
return c.AppsV1().StatefulSets(namespace).Get(ctx, stsName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getAvailableReplicas, BeZero()))
// Give the application some time to sync the data
time.Sleep(10 * time.Second)

By("scaling up to the original replicas")
ss, err = utils.StsScale(ctx, c, ss, origReplicas)
By("rollout restart the statefulset")
_, err = utils.StsRolloutRestart(ctx, c, ss)
Expect(err).NotTo(HaveOccurred())

for i := int(origReplicas) - 1; i >= 0; i-- {
Eventually(func() (*v1.Pod, error) {
return c.CoreV1().Pods(namespace).Get(ctx, fmt.Sprintf("%s-%d", stsName, i), getOpts)
}, timeout, PollingInterval).Should(WithTransform(getRestartedAtAnnotation, Not(BeEmpty())))
}

Eventually(func() (*appsv1.StatefulSet, error) {
return c.AppsV1().StatefulSets(namespace).Get(ctx, stsName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getAvailableReplicas, Equal(origReplicas)))

By("getting a value for a key")
By("creating a job to get a value for a key")
getJobName := fmt.Sprintf("%s-getbc-%s",
stsName, jobSuffix)
err = createJob(ctx, c, getJobName, port, "get", bucketName, "testKey")
Expand All @@ -107,6 +114,10 @@ var _ = Describe("NATS", Ordered, func() {
return c.BatchV1().Jobs(namespace).Get(ctx, getJobName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getSucceededJobs, Equal(int32(1))))

By("deleting the job once it has succeeded")
err = c.BatchV1().Jobs(namespace).Delete(ctx, getJobName, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())

By("creating a job to get the test bucket")
deleteDBJobName := fmt.Sprintf("%s-delbc-%s",
stsName, jobSuffix)
Expand All @@ -116,6 +127,10 @@ var _ = Describe("NATS", Ordered, func() {
Eventually(func() (*batchv1.Job, error) {
return c.BatchV1().Jobs(namespace).Get(ctx, deleteDBJobName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getSucceededJobs, Equal(int32(1))))

By("deleting the job once it has succeeded")
err = c.BatchV1().Jobs(namespace).Delete(ctx, deleteDBJobName, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())
})
})

Expand Down
8 changes: 6 additions & 2 deletions bitnami/nats/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 8.4.1 (2024-09-13)
## 8.4.2 (2024-09-17)

* [bitnami/nats] Fix single replica Jetstream ([#29379](https://github.com/bitnami/charts/pull/29379))
* [bitnami/nats] Improve Ginkgo tests ([#29462](https://github.com/bitnami/charts/pull/29462))

## <small>8.4.1 (2024-09-16)</small>

* [bitnami/nats] Fix single replica Jetstream (#29379) ([4959500](https://github.com/bitnami/charts/commit/4959500b4987deb760d38e06d181022bacc3308d)), closes [#29379](https://github.com/bitnami/charts/issues/29379)

## 8.4.0 (2024-09-12)

Expand Down
2 changes: 1 addition & 1 deletion bitnami/nats/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ maintainers:
name: nats
sources:
- https://github.com/bitnami/charts/tree/main/bitnami/nats
version: 8.4.1
version: 8.4.2

0 comments on commit 3ec3cfb

Please sign in to comment.