Skip to content

Commit

Permalink
Skip pvc expansion test on github PR workflow
Browse files Browse the repository at this point in the history
- kinD does not support volume expansion
  • Loading branch information
ChunyiLyu committed Feb 16, 2021
1 parent 0e73117 commit 8ab7f0c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
make install-tools
kind create cluster --image kindest/node:"$K8S_VERSION"
DOCKER_REGISTRY_SERVER=local-server OPERATOR_IMAGE=local-operator make deploy-kind
make system-tests
SUPPORT_VOLUME_EXPANSION=false make system-tests
kubectl_tests:
name: kubectl rabbitmq tests
Expand Down
94 changes: 57 additions & 37 deletions system_tests/system_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
storagev1 "k8s.io/api/storage/v1"
k8sresource "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -239,11 +240,12 @@ CONSOLE_LOG=new`
password string
)

AfterEach(func() {
Expect(rmqClusterClient.Delete(context.TODO(), cluster)).To(Succeed())
})

BeforeEach(func() {
cluster = newRabbitmqCluster(namespace, "persistence-rabbit")
cluster.Spec.Persistence = rabbitmqv1beta1.RabbitmqClusterPersistenceSpec{
StorageClassName: pointer.StringPtr("persistent-test"),
}
Expect(createRabbitmqCluster(ctx, rmqClusterClient, cluster)).To(Succeed())

waitForRabbitmqRunning(cluster)
Expand All @@ -257,10 +259,6 @@ CONSOLE_LOG=new`
assertHttpReady(hostname, port)
})

AfterEach(func() {
Expect(rmqClusterClient.Delete(context.TODO(), cluster)).To(Succeed())
})

It("persists messages", func() {
By("publishing a message", func() {
Expect(publishToQueue(hostname, port, username, password)).To(Succeed())
Expand All @@ -287,42 +285,64 @@ CONSOLE_LOG=new`
Expect(pvc.OwnerReferences).To(HaveLen(1))
Expect(pvc.OwnerReferences[0].Name).To(Equal(cluster.Name))
})
})
})

By("allowing volume expansion", func() {
podUID := pod(ctx, clientSet, cluster, 0).UID
output, err := kubectlExec(namespace, statefulSetPodName(cluster, 0), "df", "/var/lib/rabbitmq/mnesia")
Expect(err).ToNot(HaveOccurred())
previousDiskSize, err := strconv.Atoi(strings.Fields(strings.Split(string(output), "\n")[1])[1])
Context("PVC resize", func() {
var cluster *rabbitmqv1beta1.RabbitmqCluster

storageClass := &storagev1.StorageClass{}
Expect(rmqClusterClient.Get(ctx, types.NamespacedName{Name: storageClassName, Namespace: namespace}, storageClass)).To(Succeed())
Expect(*storageClass.AllowVolumeExpansion).To(BeTrue(), fmt.Sprintf(" 'AllowVolumeExpansion' set to false for storage class %s", storageClassName))
AfterEach(func() {
Expect(rmqClusterClient.Delete(context.TODO(), cluster)).To(Succeed())
})

newCapacity, _ := k8sresource.ParseQuantity("12Gi")
Expect(updateRabbitmqCluster(ctx, rmqClusterClient, cluster.Name, cluster.Namespace, func(cluster *rabbitmqv1beta1.RabbitmqCluster) {
cluster.Spec.Persistence.Storage = &newCapacity
})).To(Succeed())
BeforeEach(func() {
// volume expansion is supported in kinD which is use in github action
if os.Getenv("SUPPORT_VOLUME_EXPANSION") == "false" {
Skip("SUPPORT_VOLUME_EXPANSION is set to false; skipping volume expansion test")
}

// PVC storage capacity updated
Eventually(func() k8sresource.Quantity {
pvcName := cluster.PVCName(0)
pvc, err := clientSet.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, pvcName, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return pvc.Spec.Resources.Requests["storage"]
}, 120, 5).Should(Equal(newCapacity))
cluster = newRabbitmqCluster(namespace, "resize-rabbit")
cluster.Spec.Persistence = rabbitmqv1beta1.RabbitmqClusterPersistenceSpec{
StorageClassName: pointer.StringPtr("persistent-test"),
}
Expect(createRabbitmqCluster(ctx, rmqClusterClient, cluster)).To(Succeed())
waitForRabbitmqRunning(cluster)
})

// storage capacity reflected in the pod
Eventually(func() int {
output, err = kubectlExec(namespace, statefulSetPodName(cluster, 0), "df", "/var/lib/rabbitmq/mnesia")
Expect(err).ToNot(HaveOccurred())
updatedDiskSize, err := strconv.Atoi(strings.Fields(strings.Split(string(output), "\n")[1])[1])
Expect(err).ToNot(HaveOccurred())
return updatedDiskSize
}, 120, 5).Should(BeNumerically(">", previousDiskSize))
It("allows volume expansion", func() {
podUID := pod(ctx, clientSet, cluster, 0).UID
output, err := kubectlExec(namespace, statefulSetPodName(cluster, 0), "df", "/var/lib/rabbitmq/mnesia")
Expect(err).ToNot(HaveOccurred())
previousDiskSize, err := strconv.Atoi(strings.Fields(strings.Split(string(output), "\n")[1])[1])

// pod was not recreated
Expect(pod(ctx, clientSet, cluster, 0).UID).To(Equal(podUID))
})
storageClass := &storagev1.StorageClass{}
Expect(rmqClusterClient.Get(ctx, types.NamespacedName{Name: storageClassName, Namespace: namespace}, storageClass)).To(Succeed())
Expect(*storageClass.AllowVolumeExpansion).To(BeTrue(), fmt.Sprintf(" 'AllowVolumeExpansion' set to false for storage class %s", storageClassName))

newCapacity, _ := k8sresource.ParseQuantity("12Gi")
Expect(updateRabbitmqCluster(ctx, rmqClusterClient, cluster.Name, cluster.Namespace, func(cluster *rabbitmqv1beta1.RabbitmqCluster) {
cluster.Spec.Persistence.Storage = &newCapacity
})).To(Succeed())

// PVC storage capacity updated
Eventually(func() k8sresource.Quantity {
pvcName := cluster.PVCName(0)
pvc, err := clientSet.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, pvcName, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return pvc.Spec.Resources.Requests["storage"]
}, 120, 5).Should(Equal(newCapacity))

// storage capacity reflected in the pod
Eventually(func() int {
output, err = kubectlExec(namespace, statefulSetPodName(cluster, 0), "df", "/var/lib/rabbitmq/mnesia")
Expect(err).ToNot(HaveOccurred())
updatedDiskSize, err := strconv.Atoi(strings.Fields(strings.Split(string(output), "\n")[1])[1])
Expect(err).ToNot(HaveOccurred())
return updatedDiskSize
}, 120, 5).Should(BeNumerically(">", previousDiskSize))

// pod was not recreated
Expect(pod(ctx, clientSet, cluster, 0).UID).To(Equal(podUID))
})
})

Expand Down

0 comments on commit 8ab7f0c

Please sign in to comment.