Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

E2E: test HPA scale down as well #4087

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions test/e2e/kubernetes/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func (d *Deployment) Pods() ([]pod.Pod, error) {
return pod.GetAllByPrefix(d.Metadata.Name, d.Metadata.Namespace)
}

// WaitForReplicas waits for a minimum of n pod replicas
func (d *Deployment) WaitForReplicas(n int, sleep, duration time.Duration) ([]pod.Pod, error) {
// WaitForReplicas waits for a pod replica count between min and max
func (d *Deployment) WaitForReplicas(min, max int, sleep, duration time.Duration) ([]pod.Pod, error) {
readyCh := make(chan bool, 1)
errCh := make(chan error)
ctx, cancel := context.WithTimeout(context.Background(), duration)
Expand All @@ -206,18 +206,27 @@ func (d *Deployment) WaitForReplicas(n int, sleep, duration time.Duration) ([]po
for {
select {
case <-ctx.Done():
errCh <- errors.Errorf("Timeout exceeded (%s) while waiting for %d Pod replicas from Deployment %s", duration.String(), n, d.Metadata.Name)
errCh <- errors.Errorf("Timeout exceeded (%s) while waiting for minimum %d and maximum %d Pod replicas from Deployment %s", duration.String(), min, max, d.Metadata.Name)
default:
pods, err := pod.GetAllByPrefix(d.Metadata.Name, d.Metadata.Namespace)
if err != nil {
errCh <- err
return
}
if len(pods) >= n {
readyCh <- true
if min == -1 {
if len(pods) <= max {
readyCh <- true
}
} else if max == -1 {
if len(pods) >= min {
readyCh <- true
}
} else {
time.Sleep(sleep)
if len(pods) >= min && len(pods) <= max {
readyCh <- true
}
}
time.Sleep(sleep)
}
}
}()
Expand Down
12 changes: 9 additions & 3 deletions test/e2e/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu

It("should be able to autoscale", func() {
if eng.HasLinuxAgents() && eng.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.EnableAggregatedAPIs {
By("Creating a test php-apache deployment with request limit thresholds")
By("Getting the long-running php-apache deployment")
// Inspired by http://blog.kubernetes.io/2016/07/autoscaling-in-kubernetes.html
r := rand.New(rand.NewSource(time.Now().UnixNano()))
phpApacheDeploy, err := deployment.Get(longRunningApacheDeploymentName, "default")
Expand Down Expand Up @@ -769,14 +769,20 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu
Expect(len(loadTestPods)).To(Equal(numLoadTestPods))

By("Ensuring we have more than 1 apache-php pods due to hpa enforcement")
_, err = phpApacheDeploy.WaitForReplicas(2, 5*time.Second, cfg.Timeout)
_, err = phpApacheDeploy.WaitForReplicas(2, -1, 5*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())

By("Cleaning up after ourselves")
By("Stopping load")
err = loadTestDeploy.Delete(deleteResourceRetries)
Expect(err).NotTo(HaveOccurred())

By("Ensuring we only have 1 apache-php pod after stopping load")
_, err = phpApacheDeploy.WaitForReplicas(-1, 1, 5*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
h, err := hpa.Get(longRunningApacheDeploymentName, "default")
Expect(err).NotTo(HaveOccurred())

By("Deleting HPA configuration")
err = h.Delete(deleteResourceRetries)
Expect(err).NotTo(HaveOccurred())
} else {
Expand Down