Skip to content
Open
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
17 changes: 17 additions & 0 deletions charts/pega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,23 @@ tier:
name: my-configmap
```

### Custom /etc/hosts entries

You can optionally specify custom entries to add in the /etc/hosts file for your deployment tier by adding `hostAliases`. For an overview of `hostAliases` and their use, refer to [Adding entries to Pod /etc/hosts with HostAliases](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/).

Example:

```yaml
tier:
- name: my-tier
custom:
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "test1.local"
- "test2.local"
```

### Sidecar Containers

Pega supports adding sidecar containers to manage requirements for your Pega application services that live outside of the primary tomcat container. This may include company policy requirements, utility images, networking containers, or other examples. For an overview of the versatility sidecar containers present, see [How Pods manage multiple containers](https://kubernetes.io/docs/concepts/workloads/pods/#how-pods-manage-multiple-containers).
Expand Down
4 changes: 4 additions & 0 deletions charts/pega/templates/_pega-deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ spec:
{{- if .custom.serviceAccountName }}
serviceAccountName: {{ .custom.serviceAccountName }}
{{- end }}
{{- if .custom.hostAliases }}
hostAliases:
{{ toYaml .custom.hostAliases | indent 6 }}
{{- end }}
{{- end }}
volumes:
# Volume used to mount config files.
Expand Down
10 changes: 10 additions & 0 deletions terratest/src/test/pega/data/values_hostAliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
global:
tier:
- name: "web"
custom:
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "test1.local"
- "test2.local"
76 changes: 76 additions & 0 deletions terratest/src/test/pega/pega-tier-hostAliases_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package pega

import (
"testing"
"bytes"

"github.com/gruntwork-io/terratest/modules/helm"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"path/filepath"
"k8s.io/apimachinery/pkg/util/yaml"
)

func TestPegaHostAliases(t *testing.T) {
var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"}
var supportedOperations = []string{"deploy", "install-deploy"}
var deploymentNames = []string{"pega", "myapp-dev"}
helmChartPath, err := filepath.Abs(PegaHelmChartPath)
require.NoError(t, err, "Failed to resolve Helm chart path")

for _, vendor := range supportedVendors {
for _, operation := range supportedOperations {
for _, deploymentName := range deploymentNames {
// Set the Helm values to configure the labels
options := &helm.Options{
ValuesFiles: []string{"data/values_hostAliases.yaml"},
SetValues: map[string]string{
"global.provider": vendor,
"global.actions.execute": operation,
"global.deployment.name": deploymentName,
},
}

// Render the Kubernetes manifests using Helm
output := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-deployment.yaml"})

// Create a YAML decoder from the output
decoder := yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(output)), 4096)
for {
var resource unstructured.Unstructured
err := decoder.Decode(&resource)
if err != nil {
// Break on EOF
break
}

// Only check Deployment resources
if resource.GetKind() == "Deployment" {
// Extract and validate hostAliases
spec, found, err := unstructured.NestedMap(resource.Object, "spec", "template", "spec")
require.NoError(t, err, "Error extracting spec from resource")
if !found {
t.Errorf("spec.template.spec not found in Deployment %s", resource.GetName())
continue
}

hostAliases, found, err := unstructured.NestedSlice(spec, "hostAliases")
require.NoError(t, err, "Error extracting hostAliases from spec")
if !found {
t.Errorf("hostAliases not found in Deployment %s", resource.GetName())
continue
}

// Validate the content of hostAliases
assert.Equal(t, 1, len(hostAliases), "Expected exactly 1 hostAliases entry in Deployment %s", resource.GetName())
entry := hostAliases[0].(map[string]interface{})
assert.Equal(t, "127.0.0.1", entry["ip"], "Unexpected IP in hostAliases of Deployment %s", resource.GetName())
assert.Contains(t, entry["hostnames"], "test1.local", "Expected hostname test1.local in hostAliases of Deployment %s", resource.GetName())
assert.Contains(t, entry["hostnames"], "test2.local", "Expected hostname test2.local in hostAliases of Deployment %s", resource.GetName())
}
}
}
}
}
}