Skip to content

Commit

Permalink
US-646756 : containerLifecycleHooks for pega deployments (#841)
Browse files Browse the repository at this point in the history
Co-authored-by: Saurabh <[email protected]>
  • Loading branch information
pega-Abhinav and Saurabh-16 authored Nov 15, 2024
1 parent b74a3fa commit a25db94
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions charts/pega/templates/_pega-deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ spec:
# Additional custom ports
{{ toYaml .custom.ports | indent 8 }}
{{- end }}
{{- end }}
{{- if .custom }}
{{- if .custom.containerLifecycleHooks }}
lifecycle:
{{ toYaml .custom.containerLifecycleHooks | indent 10 }}
{{- end }}
{{- end }}
# Specify any of the container environment variables here
env:
Expand Down
23 changes: 23 additions & 0 deletions terratest/src/test/pega/data/values_custom_lifecycle_hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
global:
tier:
- name: "web"
nodeType: "WebUser"
requestor:
passivationTimeSec: 900
replicas: 1
deploymentStrategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
livenessProbe:
port: 8081
# Values for test - web
custom:
containerLifecycleHooks:
preStop:
exec:
command:
- sleep
- '15'
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package pega

import (
"github.com/gruntwork-io/terratest/modules/helm"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
"path/filepath"
"strings"
"testing"
)

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

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

for _, vendor := range supportedVendors {
for _, operation := range supportedOperations {
for _, depName := range deploymentNames {
var options = &helm.Options{
ValuesFiles: []string{"data/values_custom_lifecycle_hooks.yaml"},
SetValues: map[string]string{
"global.deployment.name": depName,
"global.provider": vendor,
"global.actions.execute": operation,
"installer.upgrade.upgradeType": "zero-downtime",
},
}
deploymentYaml := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-deployment.yaml"})
yamlSplit := strings.Split(deploymentYaml, "---")
assertWeb(t, yamlSplit[1], options)
assertLifecycleHook(t, yamlSplit[1], options)
}
}
}
}

func assertLifecycleHook(t *testing.T, tierYaml string, options *helm.Options) {
var deploymentObj appsv1.Deployment
UnmarshalK8SYaml(t, tierYaml, &deploymentObj)
pod := deploymentObj.Spec.Template.Spec
require.Equal(t, 1, len(pod.Containers))
require.Equal(t, "pega-web-tomcat", pod.Containers[0].Name)
require.Equal(t, "pegasystems/pega", pod.Containers[0].Image)
require.Equal(t, []string{"sleep", "15"}, pod.Containers[0].Lifecycle.PreStop.Exec.Command)
}

0 comments on commit a25db94

Please sign in to comment.