Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post-upgrade hook to helm installer job in case of upgrade #312

Merged
merged 42 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
132bc42
Update _pega-installer-job.tpl
amansharma00a Jun 20, 2021
6873acd
Update pega-installer-config.yaml
amansharma00a Jun 22, 2021
1905e61
Update _helpers.tpl
amansharma00a Jun 22, 2021
ff33d09
Update _helpers.tpl
amansharma00a Jun 23, 2021
86281c9
Update pega-installer-config.yaml
amansharma00a Jun 23, 2021
21075b5
Update _helpers.tpl
amansharma00a Jun 23, 2021
d4adf1f
Update _pega-installer-job.tpl
amansharma00a Jun 23, 2021
7a9906d
Update _pega-credentials-secret.tpl
amansharma00a Jun 24, 2021
ba3d5c9
Update _pega-registry-secret.tpl
amansharma00a Jun 24, 2021
02a32cb
Update _pega-installer-job.tpl
amansharma00a Jun 24, 2021
c38e3ab
Update _pega-installer-job.tpl
amansharma00a Jun 24, 2021
2e835e6
Update _helpers.tpl
amansharma00a Jun 24, 2021
ff4573d
Update _pega-installer-job.tpl
amansharma00a Jun 24, 2021
029c260
Update _helpers.tpl
amansharma00a Jun 24, 2021
5a771d3
Update _helpers.tpl
amansharma00a Jun 24, 2021
7d67019
Update _pega-installer-job.tpl
amansharma00a Jun 24, 2021
fa49306
Update _pega-installer-job.tpl
amansharma00a Jun 24, 2021
faa945f
Update pega-installer-job_test.go
amansharma00a Jun 24, 2021
8af3c2b
Update _helpers.tpl
amansharma00a Jun 24, 2021
4d1b3ac
Update _pega-installer-job.tpl
amansharma00a Jun 24, 2021
f73553a
Update _pega-installer-job.tpl
amansharma00a Jun 24, 2021
bb97e91
Merge branch 'pegasystems:master' into master
amansharma00a Jun 24, 2021
190a7a1
Update _pega-credentials-secret.tpl
amansharma00a Jun 25, 2021
7379f5f
Update _pega-registry-secret.tpl
amansharma00a Jun 25, 2021
e70f25c
Update _pega-installer-job.tpl
amansharma00a Jun 25, 2021
f446336
Update _helpers.tpl
amansharma00a Jun 27, 2021
b7e3187
Update _pega-installer-job.tpl
amansharma00a Jun 27, 2021
5ff0f9a
Update _pega-installer-job.tpl
amansharma00a Jun 27, 2021
49f3aea
Update _pega-installer-job.tpl
amansharma00a Jun 27, 2021
822248c
Update _pega-installer-job.tpl
amansharma00a Jun 27, 2021
40c4ec8
Merge branch 'pegasystems:master' into master
amansharma00a Jun 27, 2021
ba3acef
Update _pega-installer-job.tpl
amansharma00a Jun 27, 2021
676a45c
Update _pega-installer-job.tpl
amansharma00a Jun 27, 2021
2a0c84f
Merge branch 'master' into master
MadhuriArugula Jul 5, 2021
a96b80d
Update _helpers.tpl
amansharma00a Jul 7, 2021
33c3782
Merge branch 'master' into master
MadhuriArugula Jul 7, 2021
225391f
Merge branch 'pegasystems:master' into master
amansharma00a Jul 9, 2021
fff688e
Merge branch 'master' into master
MadhuriArugula Jul 13, 2021
73671c1
Update pega-installer-job_test.go
amansharma00a Jul 14, 2021
adaf6c6
Update pega-installer-job_test.go
amansharma00a Jul 14, 2021
f1a3b72
Create pega-custom-upgrade_test.go
amansharma00a Jul 14, 2021
88bd564
Update pega-custom-upgrade_test.go
amansharma00a Jul 14, 2021
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
14 changes: 11 additions & 3 deletions charts/pega/charts/installer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{{- define "pegaVolumeInstall" }}pega-volume-installer{{- end }}
{{- define "pegaInstallConfig" }}pega-installer-config{{- end }}
{{- define "pegaInstallConfig" }}pega-install-config{{- end }}
{{- define "pegaUpgradeConfig" }}pega-upgrade-config{{- end }}
{{- define "pegaDBInstall" -}}pega-db-install{{- end -}}
{{- define "pegaDBCustomUpgrade" -}}pega-db-custom-upgrade{{- end -}}
{{- define "pegaDBCustomUpgrade" -}}
{{- if (contains "," .Values.upgrade.upgradeSteps) -}}
pega-db-custom-upgrade
{{- else -}}
{{- $jobName := printf "%s-%s" "pega-db-upgrade" .Values.upgrade.upgradeSteps -}}
{{- $jobName | replace "_" "-" -}}
{{- end -}}
{{- end -}}
{{- define "pegaDBOOPRulesUpgrade" -}}pega-db-ooprules-upgrade{{- end -}}
{{- define "pegaDBOOPDataUpgrade" -}}pega-db-oopdata-upgrade{{- end -}}
{{- define "pegaDBZDTUpgrade" -}}pega-zdt-upgrade{{- end -}}
Expand Down Expand Up @@ -98,4 +106,4 @@
- name: KUBERNETES_SERVICE_PORT
value: {{ $apiserver.httpsServicePort | quote }}
{{- end }}
{{- end }}
{{- end }}
16 changes: 13 additions & 3 deletions charts/pega/charts/installer/templates/_pega-installer-job.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ metadata:
name: {{ .name }}
namespace: {{ .root.Release.Namespace }}
annotations:
{{- if and (eq .root.Values.waitForJobCompletion "true") (or (eq .root.Values.global.actions.execute "install") (eq .root.Values.global.actions.execute "upgrade")) }}
# Forces Helm to wait for the install or upgrade to complete.
"helm.sh/hook": post-install
{{- if (eq .root.Values.waitForJobCompletion "true") }}
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": {{ if .root.Values.cleanAfterInstall -}} before-hook-creation,hook-succeeded {{- else -}} before-hook-creation {{- end }}
{{- if (eq .root.Values.global.actions.execute "install") }}
# Forces Helm to wait for the install to complete.
"helm.sh/hook": post-install
{{- end }}
{{- if (eq .root.Values.global.actions.execute "upgrade") }}
# Forces Helm to wait for the upgrade to complete.
"helm.sh/hook": post-install, post-upgrade
{{- end }}
{{- end }}
{{- if .root.Values.global.pegaJob }}{{- if .root.Values.global.pegaJob.annotations }}
{{ toYaml .root.Values.global.pegaJob.annotations | indent 4 }}
Expand All @@ -34,7 +40,11 @@ spec:
- name: {{ template "pegaVolumeInstall" }}
configMap:
# This name will be referred in the volume mounts kind.
{{- if or (eq $arg "install") (eq $arg "install-deploy") }}
name: {{ template "pegaInstallConfig"}}
{{- else }}
name: {{ template "pegaUpgradeConfig"}}
{{- end }}
amansharma00a marked this conversation as resolved.
Show resolved Hide resolved
# Used to specify permissions on files within the volume.
defaultMode: 420
initContainers:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{{ if or (eq (include "performInstall" .) "true") (eq (include "performUpgrade" .) "true") }}
{{ if (eq (include "performInstall" .) "true") }}
{{ template "pega.installer.config" dict "root" $ "dbType" .Values.global.jdbc.dbType "name" (include "pegaInstallConfig" .) "mode" (include "installerConfig" .) }}
{{ end }}
{{ end }}

{{ if (eq (include "performUpgrade" .) "true") }}
{{ template "pega.installer.config" dict "root" $ "dbType" .Values.global.jdbc.dbType "name" (include "pegaUpgradeConfig" .) "mode" (include "installerConfig" .) }}
{{ end }}
6 changes: 5 additions & 1 deletion charts/pega/templates/_pega-credentials-secret.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ apiVersion: v1
metadata:
name: {{ template "pegaCredentialsSecret" $ }}
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install, pre-upgrade
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation
data:
# Base64 encoded username for connecting to the Pega DB
DB_USERNAME: {{ .Values.global.jdbc.username | b64enc }}
Expand Down Expand Up @@ -39,4 +43,4 @@ data:
{{ end }}
{{ end }}
type: Opaque
{{- end }}
{{- end }}
6 changes: 5 additions & 1 deletion charts/pega/templates/_pega-registry-secret.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ apiVersion: v1
metadata:
name: {{ template "pegaRegistrySecret" $ }}
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install, pre-upgrade
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation
data:
.dockerconfigjson: {{ template "imagePullSecret" . }}
type: kubernetes.io/dockerconfigjson
{{- end }}
{{- end }}
101 changes: 101 additions & 0 deletions terratest/src/test/pega/pega-custom-upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package pega

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

func TestPegaUpgradeJob(t *testing.T) {

var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"}
var supportedOperations = []string{"upgrade"}
var deploymentNames = []string{"pega", "myapp-dev"}
var upgradeType = []string{"custom"}
var upgradeSteps = []string{"rules-migration", "rules-upgrade", "data-upgrade"}

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

for _, vendor := range supportedVendors {
for _, operation := range supportedOperations {
for _, depName := range deploymentNames {
for _, upType := range upgradeType {
for _, upSteps := range upgradeSteps {
var options = &helm.Options{
SetValues: map[string]string{
"global.deployment.name": depName,
"global.provider": vendor,
"global.actions.execute": operation,
"installer.upgrade.upgradeType": upType,
"installer.upgrade.upgradeSteps": upSteps,
},
}

yamlContent := RenderTemplate(t, options, helmChartPath, []string{"charts/installer/templates/pega-installer-job.yaml"})
yamlSplit := strings.Split(yamlContent, "---")

assertUpgradeJob(t, yamlSplit[1], pegaDbJob{"pega-db-custom-upgrade", []string{}, "pega-upgrade-environment-config"}, options)


}
}
}
}
}
}

func assertUpgradeJob(t *testing.T, jobYaml string, expectedJob pegaDbJob, options *helm.Options) {
var jobObj k8sbatch.Job
UnmarshalK8SYaml(t, jobYaml, &jobObj)

jobSpec := jobObj.Spec.Template.Spec
jobContainers := jobObj.Spec.Template.Spec.Containers

var containerPort int32 = 8080

require.Equal(t, jobSpec.Volumes[0].Name, "pega-volume-credentials")
require.Equal(t, jobSpec.Volumes[0].VolumeSource.Secret.SecretName, getObjName(options, "-credentials-secret"))
require.Equal(t, jobSpec.Volumes[0].VolumeSource.Secret.DefaultMode, volDefaultModePointer)
require.Equal(t, jobSpec.Volumes[1].Name, "pega-volume-installer")

require.Equal(t, jobSpec.Volumes[1].VolumeSource.ConfigMap.LocalObjectReference.Name, "pega-upgrade-config")

require.Equal(t, jobSpec.Volumes[1].VolumeSource.ConfigMap.DefaultMode, volDefaultModePointer)

if(jobContainers[0].Name=="pega-db-upgrade-rules-migration") {
require.Equal(t, jobContainers[0].Name, "pega-db-upgrade-rules-migration")
}
if(jobContainers[0].Name=="pega-db-upgrade-rules-upgrade") {
require.Equal(t, jobContainers[0].Name, "pega-db-upgrade-rules-upgrade")
}
if(jobContainers[0].Name=="pega-db-upgrade-data-upgrade") {
require.Equal(t, jobContainers[0].Name, "pega-db-upgrade-data-upgrade")
}

require.Equal(t, "YOUR_INSTALLER_IMAGE:TAG", jobContainers[0].Image)
require.Equal(t, jobContainers[0].Ports[0].ContainerPort, containerPort)
require.Equal(t, jobContainers[0].VolumeMounts[0].Name, "pega-volume-installer")
require.Equal(t, jobContainers[0].VolumeMounts[0].MountPath, "/opt/pega/config")
require.Equal(t, jobContainers[0].VolumeMounts[1].Name, "pega-volume-credentials")
require.Equal(t, jobContainers[0].VolumeMounts[1].MountPath, "/opt/pega/secrets")
require.Equal(t, jobContainers[0].EnvFrom[0].ConfigMapRef.LocalObjectReference.Name, expectedJob.configMapName)

require.Equal(t, jobSpec.ImagePullSecrets[0].Name, getObjName(options, "-registry-secret"))

require.Equal(t, jobSpec.RestartPolicy, k8score.RestartPolicy("Never"))

actualInitContainers := jobSpec.InitContainers
count := len(actualInitContainers)
actualInitContainerNames := make([]string, count)
for i := 0; i < count; i++ {
actualInitContainerNames[i] = actualInitContainers[i].Name
}

require.Equal(t, expectedJob.initContainers, actualInitContainerNames)
VerifyInitContinerData(t, actualInitContainers, options)
}
10 changes: 8 additions & 2 deletions terratest/src/test/pega/pega-installer-job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestPegaInstallerJob(t *testing.T) {
}
}


func assertJob(t *testing.T, jobYaml string, expectedJob pegaDbJob, options *helm.Options) {
var jobObj k8sbatch.Job
UnmarshalK8SYaml(t, jobYaml, &jobObj)
Expand All @@ -86,9 +87,14 @@ func assertJob(t *testing.T, jobYaml string, expectedJob pegaDbJob, options *hel
require.Equal(t, jobSpec.Volumes[0].VolumeSource.Secret.SecretName, getObjName(options, "-credentials-secret"))
require.Equal(t, jobSpec.Volumes[0].VolumeSource.Secret.DefaultMode, volDefaultModePointer)
require.Equal(t, jobSpec.Volumes[1].Name, "pega-volume-installer")
require.Equal(t, jobSpec.Volumes[1].VolumeSource.ConfigMap.LocalObjectReference.Name, "pega-installer-config")
if(jobSpec.Volumes[1].VolumeSource.ConfigMap.LocalObjectReference.Name=="pega-install-config") {
require.Equal(t, jobSpec.Volumes[1].VolumeSource.ConfigMap.LocalObjectReference.Name, "pega-install-config")
}
if(jobSpec.Volumes[1].VolumeSource.ConfigMap.LocalObjectReference.Name=="pega-upgrade-config") {
require.Equal(t, jobSpec.Volumes[1].VolumeSource.ConfigMap.LocalObjectReference.Name, "pega-upgrade-config")
}
require.Equal(t, jobSpec.Volumes[1].VolumeSource.ConfigMap.DefaultMode, volDefaultModePointer)
amansharma00a marked this conversation as resolved.
Show resolved Hide resolved

require.Equal(t, jobContainers[0].Name, expectedJob.name)
require.Equal(t, "YOUR_INSTALLER_IMAGE:TAG", jobContainers[0].Image)
require.Equal(t, jobContainers[0].Ports[0].ContainerPort, containerPort)
Expand Down