-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue-635: Pod level security context configuration for Pega chart & …
…Hazelcast sub chart (#750) * Issue-635: Use entire securityConext from values for Pega chrts * Issue-635: Added securityContext option for hazelcast sub chart and template tests
- Loading branch information
Showing
6 changed files
with
196 additions
and
17 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
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
147 changes: 147 additions & 0 deletions
147
terratest/src/test/pega/pega-tier-deployment_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,147 @@ | ||
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 TestPegaTierDeploymentSecurityContextDefaults(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) | ||
|
||
if vendor != "openshift" { | ||
// for openshift and for others | ||
require.Equal(t, int64(0), *depObj.Spec.Template.Spec.SecurityContext.FSGroup) | ||
require.Equal(t, int64(9001), *depObj.Spec.Template.Spec.SecurityContext.RunAsUser) | ||
} else { | ||
require.Nil(t, depObj.Spec.Template.Spec.SecurityContext) | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
func TestPegaTierDeploymentSecurityContextAdditional(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].securityContext.runAsNonRoot": "true", | ||
"global.tier[0].securityContext.supplementalGroups[0]": "2000", | ||
}, | ||
} | ||
|
||
yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-deployment.yaml"}) | ||
yamlSplit := strings.Split(yamlContent, "---") | ||
UnmarshalK8SYaml(t, yamlSplit[1], &depObj) | ||
|
||
require.Equal(t, bool(true), *depObj.Spec.Template.Spec.SecurityContext.RunAsNonRoot) | ||
require.Equal(t, int64(2000), *&depObj.Spec.Template.Spec.SecurityContext.SupplementalGroups[0]) | ||
|
||
if vendor != "openshift" { | ||
// for openshift and for others | ||
require.Equal(t, int64(0), *depObj.Spec.Template.Spec.SecurityContext.FSGroup) | ||
require.Equal(t, int64(9001), *depObj.Spec.Template.Spec.SecurityContext.RunAsUser) | ||
} else { | ||
require.Nil(t, depObj.Spec.Template.Spec.SecurityContext.FSGroup) | ||
require.Nil(t, depObj.Spec.Template.Spec.SecurityContext.RunAsUser) | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
func TestPegaTierDeploymentSecurityContextOverrideDefault(t *testing.T) { | ||
var supportedVendors = []string{"k8s", "eks", "gke"} | ||
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].securityContext.fsGroup": "2", | ||
}, | ||
} | ||
|
||
yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-deployment.yaml"}) | ||
yamlSplit := strings.Split(yamlContent, "---") | ||
UnmarshalK8SYaml(t, yamlSplit[1], &depObj) | ||
|
||
if vendor != "openshift" { | ||
// for openshift and for others | ||
require.Equal(t, int64(2), *depObj.Spec.Template.Spec.SecurityContext.FSGroup) | ||
require.Equal(t, int64(9001), *depObj.Spec.Template.Spec.SecurityContext.RunAsUser) | ||
} else { | ||
require.Equal(t, int64(2), *depObj.Spec.Template.Spec.SecurityContext.FSGroup) | ||
require.Nil(t, depObj.Spec.Template.Spec.SecurityContext.RunAsUser) | ||
} | ||
} | ||
} | ||
} | ||
} |