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

E2E: HPA as a property of Deployments #2291

Merged
merged 1 commit into from
Feb 16, 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
26 changes: 26 additions & 0 deletions test/e2e/kubernetes/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deployment

import (
"encoding/json"
"fmt"
"log"
"os/exec"
"strconv"
Expand All @@ -27,6 +28,7 @@ type Metadata struct {
Labels map[string]string `json:"labels"`
Name string `json:"name"`
Namespace string `json:"namespace"`
HasHPA bool `json:"hasHPA"`
}

// Spec holds information the deployment strategy and number of replicas
Expand Down Expand Up @@ -142,6 +144,16 @@ func (d *Deployment) Delete() error {
log.Printf("Error while trying to delete deployment %s in namespace %s:%s\n", d.Metadata.Namespace, d.Metadata.Name, string(out))
return err
}
// Delete any associated HPAs
if d.Metadata.HasHPA {
cmd := exec.Command("kubectl", "delete", "hpa", "-n", d.Metadata.Namespace, d.Metadata.Name)
util.PrintCommand(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Deployment %s has associated HPA but unable to delete in namespace %s:%s\n", d.Metadata.Namespace, d.Metadata.Name, string(out))
return err
}
}
return nil
}

Expand All @@ -157,6 +169,20 @@ func (d *Deployment) Expose(svcType string, targetPort, exposedPort int) error {
return nil
}

// CreateDeploymentHPA applies autoscale characteristics to deployment
func (d *Deployment) CreateDeploymentHPA(cpuPercent, min, max int) error {
cmd := exec.Command("kubectl", "autoscale", "deployment", d.Metadata.Name, fmt.Sprintf("--cpu-percent=%d", cpuPercent),
fmt.Sprintf("--min=%d", min), fmt.Sprintf("--max=%d", max))
util.PrintCommand(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error while configuring autoscale against deployment %s:%s\n", d.Metadata.Name, string(out))
return err
}
d.Metadata.HasHPA = true
return nil
}

// Pods will return all pods related to a deployment
func (d *Deployment) Pods() ([]pod.Pod, error) {
return pod.GetAllByPrefix(d.Metadata.Name, d.Metadata.Namespace)
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,7 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu

By("Assigning hpa configuration to the php-apache deployment")
// Apply autoscale characteristics to deployment
cmd := exec.Command("kubectl", "autoscale", "deployment", phpApacheName, "--cpu-percent=5", "--min=1", "--max=10")
util.PrintCommand(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error while configuring autoscale against deployment %s:%s\n", phpApacheName, string(out))
}
err = phpApacheDeploy.CreateDeploymentHPA(5, 1, 10)
Expect(err).NotTo(HaveOccurred())

By("Sending load to the php-apache service by creating a 3 replica deployment")
Expand Down