Skip to content

Commit

Permalink
[bitnami/postgresql-ha] test: ✅ Improve ginkgo test reliability (#29166)
Browse files Browse the repository at this point in the history
* [bitnami/postgresql-ha] test: ✅ Improve ginkgo test reliability

Signed-off-by: Javier J. Salmerón García <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Bitnami Containers <[email protected]>

---------

Signed-off-by: Javier J. Salmerón García <[email protected]>
Signed-off-by: Bitnami Containers <[email protected]>
Co-authored-by: Bitnami Containers <[email protected]>
  • Loading branch information
javsalgar and bitnami-bot authored Sep 3, 2024
1 parent 5e5609c commit 7e4276d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
22 changes: 13 additions & 9 deletions .vib/postgresql-ha/ginkgo/postgresql_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 Down Expand Up @@ -38,6 +39,9 @@ var _ = Describe("Postgresql", Ordered, func() {
getAvailableReplicas := func(ss *appsv1.StatefulSet) int32 { return ss.Status.AvailableReplicas }
getSucceededJobs := func(j *batchv1.Job) int32 { return j.Status.Succeeded }
getOpts := metav1.GetOptions{}
restartKey := "kubectl.kubernetes.io/restartedAt"
restartAnnotation := map[string]string{restartKey: time.Now().Format(time.RFC3339)}
getRestartedAtAnnotation := func(pod *v1.Pod) string { return pod.Annotations[restartKey] }

By("checking all the replicas are available")
ss, err := c.AppsV1().StatefulSets(namespace).Get(ctx, stsName, getOpts)
Expand Down Expand Up @@ -72,17 +76,17 @@ var _ = Describe("Postgresql", Ordered, func() {
return c.BatchV1().Jobs(namespace).Get(ctx, createDBJobName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getSucceededJobs, Equal(int32(1))))

By("scaling down to 0 replicas")
ss, err = utils.StsScale(ctx, c, ss, 0)
By("running rollout restart")
// Annotate pods to force a rollout restart
ss, err = utils.StsAnnotateTemplate(ctx, c, ss, restartAnnotation)
Expect(err).NotTo(HaveOccurred())

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

By("scaling up to the original replicas")
ss, err = utils.StsScale(ctx, c, ss, origReplicas)
Expect(err).NotTo(HaveOccurred())
// Wait for the new annotation in the existing pods
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, Equal(restartAnnotation[restartKey])))
}

Eventually(func() (*appsv1.StatefulSet, error) {
return c.AppsV1().StatefulSets(namespace).Get(ctx, stsName, getOpts)
Expand Down
8 changes: 6 additions & 2 deletions bitnami/postgresql-ha/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 14.2.19 (2024-08-30)
## 14.2.20 (2024-09-03)

* [bitnami/postgresql-ha] Release 14.2.19 ([#29123](https://github.com/bitnami/charts/pull/29123))
* [bitnami/postgresql-ha] test: :white_check_mark: Improve ginkgo test reliability ([#29166](https://github.com/bitnami/charts/pull/29166))

## <small>14.2.19 (2024-08-30)</small>

* [bitnami/postgresql-ha] Release 14.2.19 (#29123) ([2f2875a](https://github.com/bitnami/charts/commit/2f2875a13ca7fdf326da080d5c733bd2c0b25f67)), closes [#29123](https://github.com/bitnami/charts/issues/29123)

## <small>14.2.18 (2024-08-24)</small>

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

0 comments on commit 7e4276d

Please sign in to comment.