Skip to content

Commit

Permalink
Merge branch 'master' into feature/US-598183-1
Browse files Browse the repository at this point in the history
  • Loading branch information
MadhuriArugula authored Feb 22, 2024
2 parents 2b11cc6 + 8c960b9 commit 9f0e284
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 11 deletions.
9 changes: 9 additions & 0 deletions charts/pega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1307,3 +1307,12 @@ tls:
insecureSkipVerify: true
```

```yaml
# To enable HorizontalPodAutoscaler behavior specifications, configure the following settings against each tier:
behavior:
scaleDown:
stabilizationWindowSeconds: << provide scaleDown stabilization window in seconds >>
scaleUp:
stabilizationWindowSeconds: << provide scaleUp stabilization window in seconds >>
```
6 changes: 5 additions & 1 deletion charts/pega/templates/_pega_hpa.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
maxReplicas: {{ .hpa.maxReplicas }}
{{- else }}
maxReplicas: 5
{{- end }}
{{- end }}
metrics:
{{- if (hasKey .hpa "enableCpuTarget" | ternary .hpa.enableCpuTarget true) }}
- type: Resource
Expand Down Expand Up @@ -58,6 +58,10 @@ spec:
averageUtilization: 85
{{- end }}
{{- end }}
{{- if .hpa.behavior}}
behavior:
{{ toYaml .hpa.behavior | indent 4 }}
{{- end }}

---
{{- end -}}
Expand Down
5 changes: 5 additions & 0 deletions charts/pega/values-large.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ global:

hpa:
enabled: true
# To configure behavior specifications for hpa, set the required scaleUp & scaleDown values.
# See, https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#stabilization-window
# behavior:
# scaleDown:
# stabilizationWindowSeconds: 600

# key/value pairs that are attached to the pods (https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/)
# podLabels:
Expand Down
5 changes: 5 additions & 0 deletions charts/pega/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ global:

hpa:
enabled: true
# To configure behavior specifications for hpa, set the required scaleUp & scaleDown values.
# See, https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#stabilization-window
# behavior:
# scaleDown:
# stabilizationWindowSeconds: 600

# key/value pairs that are attached to the pods (https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/)
# podLabels:
Expand Down
17 changes: 17 additions & 0 deletions terratest/src/test/pega/data/values_hpa_behavior.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
global:
tier:
- name: "web"
hpa:
enabled: true
behavior:
scaleDown:
stabilizationWindowSeconds: 300
scaleUp:
stabilizationWindowSeconds: 0
- name: "batch"
hpa:
enabled: true
behavior:
scaleDown:
stabilizationWindowSeconds: 200
82 changes: 72 additions & 10 deletions terratest/src/test/pega/pega-tier-hpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,61 @@ func TestPegaTierOverrideValues(t *testing.T) {
}
}

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

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 {

for _, depName := range deploymentNames {
fmt.Println(vendor + "-" + operation + "-" + depName)

var options = &helm.Options{
SetValues: map[string]string{
"global.provider": vendor,
"global.actions.execute": operation,
"installer.upgrade.upgradeType": "zero-downtime",
},
}

yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}, "--values", testsPath+"/data/values_hpa_behavior.yaml")
verifyPegaHPAs(t, yamlContent, options, []hpa{
{
name: getObjName(options, "-web-hpa"),
targetRefName: getObjName(options, "-web"),
kind: "Deployment",
apiversion: "apps/v1",
cpu: true,
cpuValue: parseResourceValue(t, "2.55"),
behavior: true,
scaleDownStabilizationWindow: 300,
scaleUpStabilizationWindow: 0,
},
{
name: getObjName(options, "-batch-hpa"),
targetRefName: getObjName(options, "-batch"),
kind: "Deployment",
apiversion: "apps/v1",
cpu: true,
cpuValue: parseResourceValue(t, "2.55"),
behavior: true,
scaleDownStabilizationWindow: 200,
},
})
}
}
}
}

// verifyPegaHPAs - Splits the HPA object from the rendered template and asserts each HPA object
func verifyPegaHPAs(t *testing.T, yamlContent string, options *helm.Options, expectedHpas []hpa) {
var pegaHpaObj autoscaling.HorizontalPodAutoscaler
Expand Down Expand Up @@ -270,20 +325,27 @@ func verifyPegaHpa(t *testing.T, hpaObj *autoscaling.HorizontalPodAutoscaler, ex
require.Equal(t, expectedValue, actual)
}

if expectedHpa.behavior {
require.Equal(t, *hpaObj.Spec.Behavior.ScaleDown.StabilizationWindowSeconds, expectedHpa.scaleDownStabilizationWindow)
require.Equal(t, *hpaObj.Spec.Behavior.ScaleUp.StabilizationWindowSeconds, expectedHpa.scaleUpStabilizationWindow)
}
require.Equal(t, int32(5), hpaObj.Spec.MaxReplicas)
}

type hpa struct {
name string
targetRefName string
kind string
apiversion string
labels map[string]string
cpu bool
cpuValue resource.Quantity
cpuPercent int32
mem bool
memPercent int32
name string
targetRefName string
kind string
apiversion string
labels map[string]string
cpu bool
cpuValue resource.Quantity
cpuPercent int32
mem bool
memPercent int32
behavior bool
scaleDownStabilizationWindow int32
scaleUpStabilizationWindow int32
}

func (h hpa) expectedMetricCount() int {
Expand Down

0 comments on commit 9f0e284

Please sign in to comment.