-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
US-625432 Configure securityContext for Pega containers (#789)
Co-authored-by: arugm <Madhuri.Arugula@in.pega.com> Co-authored-by: PEGA-NarasimhaRao-Meda <109585795+PEGA-NarasimhaRao-Meda@users.noreply.github.com>
- Loading branch information
1 parent
c594128
commit 7e1bac1
Showing
3 changed files
with
116 additions
and
0 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
85 changes: 85 additions & 0 deletions
85
terratest/src/test/pega/pega-tier-deployment_container_security_context_test.go
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,85 @@ | ||
package pega | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/helm" | ||
"github.com/stretchr/testify/require" | ||
appsv1 "k8s.io/api/apps/v1" | ||
) | ||
|
||
func TestPegaTierDeploymentContainerSecurityContext(t *testing.T) { | ||
var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} | ||
var supportedOperations = []string{"deploy"} | ||
var deploymentNames = []string{"myapp-dev"} | ||
|
||
helmChartPath, err := filepath.Abs(PegaHelmChartPath) | ||
require.NoError(t, err) | ||
|
||
for _, vendor := range supportedVendors { | ||
|
||
var depObj appsv1.Deployment | ||
|
||
for _, operation := range supportedOperations { | ||
|
||
for _, depName := range deploymentNames { | ||
|
||
fmt.Println(vendor + "-" + operation) | ||
|
||
var options = &helm.Options{ | ||
SetValues: map[string]string{ | ||
"global.provider": vendor, | ||
"global.actions.execute": operation, | ||
"global.deployment.name": depName, | ||
}, | ||
} | ||
|
||
yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-deployment.yaml"}) | ||
yamlSplit := strings.Split(yamlContent, "---") | ||
UnmarshalK8SYaml(t, yamlSplit[1], &depObj) | ||
require.Nil(t, depObj.Spec.Template.Spec.Containers[0].SecurityContext) | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
func TestPegaTierDeploymentSecurityContextForPegaContainer(t *testing.T) { | ||
var supportedVendors = []string{"k8s", "openshift"} | ||
var supportedOperations = []string{"deploy"} | ||
var deploymentNames = []string{"myapp-dev"} | ||
|
||
helmChartPath, err := filepath.Abs(PegaHelmChartPath) | ||
require.NoError(t, err) | ||
|
||
for _, vendor := range supportedVendors { | ||
|
||
var depObj appsv1.Deployment | ||
|
||
for _, operation := range supportedOperations { | ||
|
||
for _, depName := range deploymentNames { | ||
|
||
fmt.Println(vendor + "-" + operation) | ||
|
||
var options = &helm.Options{ | ||
SetValues: map[string]string{ | ||
"global.provider": vendor, | ||
"global.actions.execute": operation, | ||
"global.deployment.name": depName, | ||
"global.tier[0].containerSecurityContext.runAsUser": "7009", | ||
}, | ||
} | ||
|
||
yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-deployment.yaml"}) | ||
yamlSplit := strings.Split(yamlContent, "---") | ||
UnmarshalK8SYaml(t, yamlSplit[1], &depObj) | ||
|
||
require.Equal(t, int64(7009), *depObj.Spec.Template.Spec.Containers[0].SecurityContext.RunAsUser) | ||
} | ||
} | ||
} | ||
} |