-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post-upgrade hook to helm installer job to support upgrades (#312)
* Update _pega-installer-job.tpl added post upgrade hook * Update pega-installer-config.yaml config changes in case of upgrade * Update _helpers.tpl added pega-upgrade-config * Update _helpers.tpl * Update pega-installer-config.yaml * Update _helpers.tpl pega-installer-config -> pega-install-config * Update _pega-installer-job.tpl config map changes for pegaUpgradeConfig in case of upgrade * Update _pega-credentials-secret.tpl added delete hook policy so that it recreates next time on helm upgrade * Update _pega-registry-secret.tpl added delete hook policy so that it recreates again on helm upgrade * Update _pega-installer-job.tpl * Update _pega-installer-job.tpl config map changes * Update _helpers.tpl * Update _pega-installer-job.tpl * Update _helpers.tpl * Update _helpers.tpl * Update _pega-installer-job.tpl * Update _pega-installer-job.tpl * Update pega-installer-job_test.go * Update _helpers.tpl * Update _pega-installer-job.tpl * Update _pega-installer-job.tpl * Update _pega-credentials-secret.tpl * Update _pega-registry-secret.tpl * Update _pega-installer-job.tpl * Update _helpers.tpl * Update _pega-installer-job.tpl * Update _pega-installer-job.tpl * Update _pega-installer-job.tpl * Update _pega-installer-job.tpl * Update _pega-installer-job.tpl * Update _pega-installer-job.tpl * Update _helpers.tpl pegaDBCustomUpgrade * Update pega-installer-job_test.go * Update pega-installer-job_test.go * Create pega-custom-upgrade_test.go test case for upgradeType -> custom * Update pega-custom-upgrade_test.go Co-authored-by: MadhuriArugula <madhuriarugula77@gmail.com>
- Loading branch information
1 parent
05ad482
commit a39c99f
Showing
7 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
charts/pega/charts/installer/templates/pega-installer-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters