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

make sure certificates defaults to dict #697

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion charts/pega/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ global:
# to support multiple custom certificates as external secrets, specify each of your external secrets
# as an array of comma-separated strings using the certificatesSecrets parameter.
certificatesSecrets: []
certificates:
certificates: {}

# Add krb5.conf file content here.
# Feature is used for Decisioning data flows to fetch data from Kafka or HBase streams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"path/filepath"
"strings"
"testing"

"github.com/gruntwork-io/terratest/modules/helm"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -20,68 +21,67 @@ func TestPegaDeploymentWithAndWithoutCustomCerts(t *testing.T) {
for _, vendor := range supportedVendors {
for _, operation := range supportedOperations {

var options = &helm.Options{
ValuesFiles: []string{"data/values_with_customcerts.yaml"},
SetValues: map[string]string{
"global.deployment.name": "pega",
"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)
assertVolumeAndMount(t, yamlSplit[1], options, true)

assertBatch(t, yamlSplit[2], options)
assertVolumeAndMount(t, yamlSplit[2], options, true)

assertStream(t, yamlSplit[3], options)
assertVolumeAndMount(t, yamlSplit[3], options, true)

options.ValuesFiles = []string{"data/values_without_customcerts.yaml"}

deploymentYaml = RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-deployment.yaml"})
yamlSplit = strings.Split(deploymentYaml, "---")
assertWeb(t, yamlSplit[1], options)
assertVolumeAndMount(t, yamlSplit[1], options, false)

assertBatch(t, yamlSplit[2], options)
assertVolumeAndMount(t, yamlSplit[2], options, false)

assertStream(t, yamlSplit[3], options)
assertVolumeAndMount(t, yamlSplit[3], options, false)
}
var options = &helm.Options{
ValuesFiles: []string{"data/values_with_customcerts.yaml"},
SetValues: map[string]string{
"global.deployment.name": "pega",
"global.provider": vendor,
"global.actions.execute": operation,
"installer.upgrade.upgradeType": "zero-downtime",
},
}
renderTierForCertTest(t, options, helmChartPath, true)

options.ValuesFiles = []string{"data/values_without_customcerts.yaml"}

renderTierForCertTest(t, options, helmChartPath, false)
}
}
}

func renderTierForCertTest(t *testing.T, options *helm.Options, helmChartPath string, shouldHaveVol bool) {

deploymentYaml := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-deployment.yaml"})

yamlSplit := strings.Split(deploymentYaml, "---")
assertWeb(t, yamlSplit[1], options)
assertVolumeAndMount(t, yamlSplit[1], options, shouldHaveVol)

assertBatch(t, yamlSplit[2], options)
assertVolumeAndMount(t, yamlSplit[2], options, shouldHaveVol)

assertStream(t, yamlSplit[3], options)
assertVolumeAndMount(t, yamlSplit[3], options, shouldHaveVol)

require.False(t, strings.Contains(deploymentYaml, "Conflict: cannot merge map onto non-map"), "'cannot merge map onto non-map' warning should not be logged")
}

func assertVolumeAndMount(t *testing.T, tierYaml string, options *helm.Options, shouldHaveVol bool) {
var deploymentObj appsv1.Deployment
UnmarshalK8SYaml(t, tierYaml, &deploymentObj)
pod := deploymentObj.Spec.Template.Spec

var foundVol = false
var foundVol = false
for _, vol := range pod.Volumes {
if vol.Name == "pega-volume-import-certificates" {
foundVol = true
break
}
if vol.Name == "pega-volume-import-certificates" {
foundVol = true
break
}
}
require.Equal(t, shouldHaveVol, foundVol)

var foundVolMount = false
var foundVolMount = false
for _, container := range pod.Containers {
if container.Name == "pega-web-tomcat" {
for _, volMount := range container.VolumeMounts {
if volMount.Name == "pega-volume-import-certificates" {
require.Equal(t, "/opt/pega/certs", volMount.MountPath)
foundVolMount = true
break
}
}
break
}
if container.Name == "pega-web-tomcat" {
for _, volMount := range container.VolumeMounts {
if volMount.Name == "pega-volume-import-certificates" {
require.Equal(t, "/opt/pega/certs", volMount.MountPath)
foundVolMount = true
break
}
}
break
}
}
require.Equal(t, shouldHaveVol, foundVolMount)

Expand Down
Loading