Skip to content

Commit

Permalink
US-392813 Make HPA targets independently optional in the HPA template
Browse files Browse the repository at this point in the history
US-392813 Small fix

US-392813 Small fix

US-392813 Add automatic test

US-392813 Update README.md
  • Loading branch information
pmaslak92 committed Dec 18, 2020
1 parent 1d8a004 commit 339e0fc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
2 changes: 2 additions & 0 deletions charts/pega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ Parameter | Description | Default value
`hpa.maxReplicas` | Maximum number of replicas that HPA can scale-up | `5`
`hpa.targetAverageCPUUtilization` | Threshold value for scaling based on initial CPU request utilization (The default value is `70` which corresponds to 70% of 2) | `70`
`hpa.targetAverageMemoryUtilization` | Threshold value for scaling based on initial memory utilization (The default value is `85` which corresponds to 85% of 6Gi ) | `85`
`hpa.disableCPUTarget` | Set to true if you want to remove scaling based on CPU utilization and only rely on memory utilization | false
`hpa.disableMemoryTarget` | Set to true if you want to remove scaling based on memory utilization and only rely on CPU utilization | false

### Volume claim template

Expand Down
5 changes: 5 additions & 0 deletions charts/pega/templates/_pega_hpa.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spec:
maxReplicas: 5
{{- end }}
metrics:
{{- if not .hpa.disableCPUTarget }}
- type: Resource
resource:
name: cpu
Expand All @@ -30,6 +31,8 @@ spec:
{{- else }}
targetAverageUtilization: 70
{{- end }}
{{- end }}
{{- if not .hpa.disableMemoryTarget }}
- type: Resource
resource:
name: memory
Expand All @@ -38,6 +41,8 @@ spec:
{{- else }}
targetAverageUtilization: 85
{{- end }}
{{- end }}

---
{{- end -}}
{{- end -}}
11 changes: 11 additions & 0 deletions terratest/src/test/pega/data/values_hpa_disabletarget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
global:
tier:
- name: "web"
hpa:
enabled: true
disableCPUTarget: true
- name: "batch"
hpa:
enabled: true
disableMemoryTarget: true
59 changes: 57 additions & 2 deletions terratest/src/test/pega/pega-tier-hpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import (



func TestPegaTierHPA(t *testing.T){
func TestPegaTierHPA(t *testing.T) {
var supportedVendors = []string{"k8s", "openshift", "eks","gke","aks","pks"}
var supportedOperations = []string{"deploy","install-deploy","upgrade-deploy"}

helmChartPath, err := filepath.Abs(PegaHelmChartPath)
require.NoError(t, err)


for _,vendor := range supportedVendors{

for _,operation := range supportedOperations{
Expand All @@ -42,6 +41,36 @@ func TestPegaTierHPA(t *testing.T){


}

func TestPegaTierHPADisableTarget(t *testing.T) {
var supportedVendors = []string{"k8s", "openshift", "eks","gke","aks","pks"}
var supportedOperations = []string{"deploy","install-deploy","upgrade-deploy"}

helmChartPath, err := filepath.Abs(PegaHelmChartPath)
require.NoError(t, err)

testsPath,err := filepath.Abs(PegaHelmChartTestsPath)
require.NoError(t, err)

for _,vendor := range supportedVendors{

for _,operation := range supportedOperations{

fmt.Println(vendor + "-" + operation)

var options = &helm.Options{
SetValues: map[string]string{
"global.provider": vendor,
"global.actions.execute": operation,
},
}

yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}, "--values" , testsPath + "/data/values_hpa_disabletarget.yaml")
VerifyTargets(t, yamlContent)
}
}
}

// VerifyPegaHPAs - Splits the HPA object from the rendered template and asserts each HPA object
func VerifyPegaHPAs(t *testing.T, yamlContent string, options *helm.Options) {
var pegaHpaObj autoscaling.HorizontalPodAutoscaler
Expand All @@ -68,6 +97,32 @@ func VerifyPegaHpa(t *testing.T, hpaObj *autoscaling.HorizontalPodAutoscaler, ex
require.Equal(t, hpaObj.Spec.MaxReplicas, int32(5))
}


func VerifyTargets(t *testing.T, yamlContent string) {
var pegaHpaObj autoscaling.HorizontalPodAutoscaler
hpaSlice := strings.SplitAfter(yamlContent, "85")
for index, hpaInfo := range hpaSlice {
if index >= 0 && index <= 1 {
UnmarshalK8SYaml(t, hpaInfo, &pegaHpaObj)
if index == 0 {
VerifyWebNoCpuTarget(t, &pegaHpaObj)
} else {
VerifyBatchNoMemoryTarget(t, &pegaHpaObj)
}
}
}
}

func VerifyWebNoCpuTarget(t *testing.T, pegaHpaObj *autoscaling.HorizontalPodAutoscaler) {
require.Equal(t, len(pegaHpaObj.Spec.Metrics),1)
require.Equal(t, pegaHpaObj.Spec.Metrics[0].Resource.Name, api.ResourceName("memory"))
}

func VerifyBatchNoMemoryTarget(t *testing.T, pegaHpaObj *autoscaling.HorizontalPodAutoscaler) {
require.Equal(t, len(pegaHpaObj.Spec.Metrics),1)
require.Equal(t, pegaHpaObj.Spec.Metrics[0].Resource.Name, api.ResourceName("cpu"))
}

type hpa struct {
name string
targetRefName string
Expand Down

0 comments on commit 339e0fc

Please sign in to comment.