Skip to content

Commit

Permalink
e2e tests: test different scale up/down order and instance deltas
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Mar 9, 2022
1 parent 12607b1 commit 1485df3
Showing 1 changed file with 59 additions and 52 deletions.
111 changes: 59 additions & 52 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

v1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -114,12 +115,12 @@ var _ = Describe("Whereabouts functionality", func() {
})

AfterEach(func() {
const noReplicas = 0
Expect(clientInfo.deleteStatefulSet(namespace, serviceName, selector)).To(Succeed())
Expect(
clientInfo.Client.CoreV1().Pods(namespace).List(
context.TODO(), metav1.ListOptions{LabelSelector: selector})).To(
WithTransform(func(podList *core.PodList) int { return len(podList.Items) }, Equal(noReplicas)))
WithTransform(func(podList *core.PodList) []core.Pod { return podList.Items }, BeEmpty()),
"cannot have leaked pods in the system")

poolAllocations := func(ipPool *v1alpha1.IPPool) map[string]v1alpha1.IPAllocation {
return ipPool.Spec.Allocations
Expand All @@ -129,7 +130,8 @@ var _ = Describe("Whereabouts functionality", func() {
context.TODO(),
wbstorage.NormalizeRange(ipv4TestRange),
metav1.GetOptions{})).To(
WithTransform(poolAllocations, BeEmpty()))
WithTransform(poolAllocations, BeEmpty()),
"cannot have leaked IPAllocations in the system")
})

It("IPPools feature allocations", func() {
Expand All @@ -138,38 +140,47 @@ var _ = Describe("Whereabouts functionality", func() {
Expect(len(ipPool.Spec.Allocations)).To(Equal(initialReplicaNumber))
})

When("the statefulset is scaled up then down", func() {
const deltaInstances = 5
table.DescribeTable("stateful sets scale up / down", func(testSetup func(int), instanceDelta int) {
const scaleTimeout = createTimeout * 6

BeforeEach(func() {
testSetup(instanceDelta)

Eventually(func() (int, error) {
ipPool, err := clientInfo.WbClient.WhereaboutsV1alpha1().IPPools(ipPoolNamespace).Get(
context.TODO(), wbstorage.NormalizeRange(ipv4TestRange), metav1.GetOptions{})
if err != nil {
return -1, err
}

return len(ipPool.Spec.Allocations), nil
}, scaleTimeout).Should(
Equal(initialReplicaNumber), "we should have one allocation for each live pod")
},
table.Entry("scale up then down 5 replicas", func(deltaInstances int) {
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, deltaInstances)).To(Succeed())
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, -deltaInstances)).To(Succeed())
})

It("scale down then up does not leave stale addresses", func() {
const scaleTimeout = createTimeout * 2

Eventually(func() (int, error) {
associatedPods, err := clientInfo.Client.CoreV1().Pods(namespace).List(
context.TODO(), metav1.ListOptions{LabelSelector: selector})
if err != nil {
return -1, err
}

return len(associatedPods.Items), nil
}, scaleTimeout).Should(Equal(initialReplicaNumber), "we should have the original pod number again")

Eventually(func() (int, error) {
ipPool, err := clientInfo.WbClient.WhereaboutsV1alpha1().IPPools(ipPoolNamespace).Get(
context.TODO(), wbstorage.NormalizeRange(ipv4TestRange), metav1.GetOptions{})
if err != nil {
return -1, err
}

return len(ipPool.Spec.Allocations), nil
}, scaleTimeout).Should(Equal(initialReplicaNumber), "we should have one allocation for each live pod")
})
})
}, 5),
table.Entry("scale up then down 10 replicas", func(deltaInstances int) {
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, deltaInstances)).To(Succeed())
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, -deltaInstances)).To(Succeed())
}, 10),
table.Entry("scale up then down 20 replicas", func(deltaInstances int) {
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, deltaInstances)).To(Succeed())
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, -deltaInstances)).To(Succeed())
}, 20),
table.Entry("scale down then up 5 replicas", func(deltaInstances int) {
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, -deltaInstances)).To(Succeed())
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, deltaInstances)).To(Succeed())
}, 5),
table.Entry("scale down then up 10 replicas", func(deltaInstances int) {
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, -deltaInstances)).To(Succeed())
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, deltaInstances)).To(Succeed())
}, 10),
table.Entry("scale down then up 20 replicas", func(deltaInstances int) {
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, -deltaInstances)).To(Succeed())
Expect(clientInfo.scaleStatefulSet(serviceName, namespace, deltaInstances)).To(Succeed())
}, 20),
)
})
})
})
Expand Down Expand Up @@ -267,7 +278,7 @@ func (c *ClientInfo) deletePod(pod *core.Pod) error {
}

func (c *ClientInfo) provisionStatefulSet(statefulSetName string, namespace string, serviceName string, replicas int) (*v1.StatefulSet, error) {
const statefulSetCreateTimeout = 2 * createTimeout
const statefulSetCreateTimeout = 6 * createTimeout
statefulSet, err := c.Client.AppsV1().StatefulSets(namespace).Create(
context.TODO(),
statefulSetSpec(statefulSetName, serviceName, replicas, podNetworkSelectionElements(testNetworkName)),
Expand All @@ -288,8 +299,9 @@ func (c *ClientInfo) provisionStatefulSet(statefulSetName string, namespace stri
}

func (c *ClientInfo) deleteStatefulSet(namespace string, serviceName string, labelSelector string) error {
const statefulSetDeleteTimeout = 2 * deleteTimeout
if err := c.Client.AppsV1().StatefulSets(namespace).Delete(context.TODO(), serviceName, metav1.DeleteOptions{}); err != nil {
const statefulSetDeleteTimeout = 6 * deleteTimeout
rightNow := int64(0)
if err := c.Client.AppsV1().StatefulSets(namespace).Delete(context.TODO(), serviceName, metav1.DeleteOptions{GracePeriodSeconds: &rightNow}); err != nil {
return err
}

Expand Down Expand Up @@ -330,23 +342,18 @@ func generateNetAttachDefSpec(name, namespace, config string) *nettypes.NetworkA
func macvlanNetworkWithWhereaboutsIPAMNetwork() *nettypes.NetworkAttachmentDefinition {
macvlanConfig := `{
"cniVersion": "0.3.0",
"disableCheck": true,
"plugins": [
{
"type": "macvlan",
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "whereabouts",
"leader_lease_duration": 1500,
"leader_renew_deadline": 1000,
"leader_retry_period": 500,
"range": "10.10.0.0/16",
"log_level": "debug",
"log_file": "/tmp/wb"
}
}
]
"type": "macvlan",
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "whereabouts",
"leader_lease_duration": 1500,
"leader_renew_deadline": 1000,
"leader_retry_period": 500,
"range": "10.10.0.0/16",
"log_level": "debug",
"log_file": "/tmp/wb"
}
}`
return generateNetAttachDefSpec(testNetworkName, testNamespace, macvlanConfig)
}
Expand Down

0 comments on commit 1485df3

Please sign in to comment.