diff --git a/charts/pega/README.md b/charts/pega/README.md index 624d49c94..2a6fc0c96 100644 --- a/charts/pega/README.md +++ b/charts/pega/README.md @@ -1258,6 +1258,7 @@ here: [Additional Parameters](charts/hazelcast/README.md) Parameter | Description | Default value --- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| --- +`hazelcast.deployment.name` | Name used for the hazelcast deployment. | `pega-hazelcast` `hazelcast.image` | Reference the `platform/clustering-service` Docker image that you downloaded and pushed to your Docker registry that your deployment can access. | `YOUR_HAZELCAST_IMAGE:TAG` `hazelcast.clusteringServiceImage` | Reference the `platform/clustering-service` Docker image that you downloaded and pushed to your Docker registry that your deployment can access. | `YOUR_CLUSTERING_SERVICE_IMAGE:TAG` `hazelcast.enabled` | Set to `true` if client-server deployment of Pega Platform is required; otherwise leave set to `false`. Note: To avoid an installation failure, you must set this value to `false` for Pega platform deployments using versions before 8.6. | `true` @@ -1275,6 +1276,8 @@ Parameter | Description #### Example ```yaml hazelcast: + deployment: + name: "pega-hazelcast" image: "YOUR_HAZELCAST_IMAGE:TAG" clusteringServiceImage: "YOUR_CLUSTERING_SERVICE_IMAGE:TAG" enabled: true diff --git a/charts/pega/charts/hazelcast/README.md b/charts/pega/charts/hazelcast/README.md index 599dbcb2e..67c863d9c 100644 --- a/charts/pega/charts/hazelcast/README.md +++ b/charts/pega/charts/hazelcast/README.md @@ -53,6 +53,8 @@ Name | Description #### Example ```yaml +deployment: + name: pega-hazelcast image: "YOUR_HAZELCAST_IMAGE:TAG" clusteringServiceImage: "YOUR_CLUSTERING_SERVICE_IMAGE:TAG" imagePullPolicy: "Always" diff --git a/charts/pega/charts/hazelcast/templates/_helpers.tpl b/charts/pega/charts/hazelcast/templates/_helpers.tpl index 944ff12ff..de0e6395a 100644 --- a/charts/pega/charts/hazelcast/templates/_helpers.tpl +++ b/charts/pega/charts/hazelcast/templates/_helpers.tpl @@ -1,9 +1,10 @@ -{{- define "hazelcastName" -}} pega-hazelcast {{- end -}} -{{- define "hazelcastEnvironmentConfig" -}} pega-hz-env-config {{- end -}} +{{- define "hazelcastDeploymentName" }}{{ $hazelcastDeploymentName := .defaultname }}{{ if (.root.deployment) }}{{ if (.root.deployment.name) }}{{ $hazelcastDeploymentName = .root.deployment.name }}{{ end }}{{ end }}{{ $hazelcastDeploymentName }}{{- end -}} -{{- define "clusteringServiceName" -}} clusteringservice {{- end -}} -{{- define "clusteringServiceEnvironmentConfig" -}} clusteringservice-env-config {{- end -}} +{{- define "hazelcastName" -}}{{ include "hazelcastDeploymentName" (dict "root" .Values "defaultname" "pega-hazelcast" )}}{{- end -}} +{{- define "hazelcastEnvironmentConfig" -}}{{include "hazelcastName" .}}-env-config {{- end -}} +{{- define "clusteringServiceName" -}}{{ include "hazelcastDeploymentName" (dict "root" .Values "defaultname" "clusteringservice" )}}{{- end -}} +{{- define "clusteringServiceEnvironmentConfig" -}}{{include "clusteringServiceName" .}}-env-config {{- end -}} {{- define "isHazelcastEnabled" }} {{- if .Values.enabled -}} diff --git a/charts/pega/charts/hazelcast/templates/clustering-service-deployment.yaml b/charts/pega/charts/hazelcast/templates/clustering-service-deployment.yaml index fc772f082..821ba96d9 100644 --- a/charts/pega/charts/hazelcast/templates/clustering-service-deployment.yaml +++ b/charts/pega/charts/hazelcast/templates/clustering-service-deployment.yaml @@ -43,7 +43,7 @@ spec: {{- end }} envFrom: - configMapRef: - name: {{ template "clusteringServiceEnvironmentConfig" }} + name: {{ template "clusteringServiceEnvironmentConfig" .}} {{- if .Values.containerSecurityContext }} securityContext: {{ toYaml .Values.containerSecurityContext | indent 10 }} diff --git a/charts/pega/charts/hazelcast/templates/clustering-service-environment-config.yaml b/charts/pega/charts/hazelcast/templates/clustering-service-environment-config.yaml index 793429a55..a397321fc 100644 --- a/charts/pega/charts/hazelcast/templates/clustering-service-environment-config.yaml +++ b/charts/pega/charts/hazelcast/templates/clustering-service-environment-config.yaml @@ -2,7 +2,7 @@ kind: ConfigMap apiVersion: v1 metadata: - name: {{ template "clusteringServiceEnvironmentConfig" }} + name: {{ template "clusteringServiceEnvironmentConfig" . }} namespace: {{ .Release.Namespace }} data: # Key Value pairs diff --git a/charts/pega/charts/hazelcast/templates/pega-hz-deployment.yaml b/charts/pega/charts/hazelcast/templates/pega-hz-deployment.yaml index 494c116ca..4683aa41d 100644 --- a/charts/pega/charts/hazelcast/templates/pega-hz-deployment.yaml +++ b/charts/pega/charts/hazelcast/templates/pega-hz-deployment.yaml @@ -35,7 +35,7 @@ spec: mountPath: "/opt/hazelcast/secrets" envFrom: - configMapRef: - name: {{ template "hazelcastEnvironmentConfig" }} + name: {{ template "hazelcastEnvironmentConfig" . }} resources: requests: cpu: "{{ .Values.resources.requests.cpu }}" diff --git a/charts/pega/charts/hazelcast/templates/pega-hz-environment-config.yaml b/charts/pega/charts/hazelcast/templates/pega-hz-environment-config.yaml index 53237e968..791da2632 100644 --- a/charts/pega/charts/hazelcast/templates/pega-hz-environment-config.yaml +++ b/charts/pega/charts/hazelcast/templates/pega-hz-environment-config.yaml @@ -2,13 +2,13 @@ kind: ConfigMap apiVersion: v1 metadata: - name: {{ template "hazelcastEnvironmentConfig" }} + name: {{ template "hazelcastEnvironmentConfig" .}} namespace: {{ .Release.Namespace }} data: # Key Value pairs NAMESPACE: {{ .Release.Namespace }} JAVA_OPTS: {{ .Values.server.java_opts | quote }} - SERVICE_NAME: {{ template "hazelcastName" }}-service + SERVICE_NAME: {{ template "hazelcastName" .}}-service MIN_CLUSTER_SIZE: {{ .Values.replicas | quote }} {{- if .Values.server.jmx_enabled }} JMX_ENABLED: {{ .Values.server.jmx_enabled | quote }} diff --git a/charts/pega/charts/hazelcast/values.yaml b/charts/pega/charts/hazelcast/values.yaml index 94b0f3393..6fc57a5a5 100644 --- a/charts/pega/charts/hazelcast/values.yaml +++ b/charts/pega/charts/hazelcast/values.yaml @@ -1,5 +1,8 @@ --- image: "YOUR_HAZELCAST_IMAGE:TAG" +# Change the name of the hazelcast deployment +# deployment: +# name: "pega-hazelcast" clusteringServiceImage: "YOUR_CLUSTERING_SERVICE_IMAGE:TAG" imagePullPolicy: "Always" # Enter the number of initial members in Hazelcast cluster. diff --git a/charts/pega/templates/_helpers.tpl b/charts/pega/templates/_helpers.tpl index 4b89c8f9f..0e6634c51 100644 --- a/charts/pega/templates/_helpers.tpl +++ b/charts/pega/templates/_helpers.tpl @@ -484,10 +484,11 @@ servicePort: use-annotation {{- end -}} {{- define "hzServiceName" -}} +{{- $hzDict := dict "Values" .Values.hazelcast -}} {{- if and (not .Values.hazelcast.enabled) .Values.hazelcast.clusteringServiceEnabled -}} - {{ template "clusteringServiceName" }} + {{ template "clusteringServiceName" $hzDict }} {{- else -}} - {{ template "hazelcastName" }} + {{ template "hazelcastName" $hzDict }} {{- end -}} {{- end -}} diff --git a/terratest/src/test/pega/clustering-service-deployment_test.go b/terratest/src/test/pega/clustering-service-deployment_test.go index 06497602d..330681358 100644 --- a/terratest/src/test/pega/clustering-service-deployment_test.go +++ b/terratest/src/test/pega/clustering-service-deployment_test.go @@ -103,6 +103,47 @@ func VerifyClusteringServiceDeployment(t *testing.T, yamlContent string, ssl boo } } +func TestClusteringServiceDeploymentName(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy"} + + helmChartPath, err := filepath.Abs(PegaHelmChartPath) + require.NoError(t, err) + + for _, vendor := range supportedVendors { + + for _, operation := range supportedOperations { + + fmt.Println(vendor + "-" + operation) + + var options = &helm.Options{ + SetValues: map[string]string{ + "global.provider": vendor, + "global.actions.execute": operation, + "hazelcast.clusteringServiceEnabled": "true", + "hazelcast.deployment.name": "clusteringservice-test", + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"charts/hazelcast/templates/clustering-service-deployment.yaml"}) + VerifyClusteringServiceDeploymentName(t, yamlContent) + + } + } +} + +func VerifyClusteringServiceDeploymentName(t *testing.T, yamlContent string) { + var statefulsetObj appsv1beta2.StatefulSet + statefulSlice := strings.Split(yamlContent, "---") + for index, statefulInfo := range statefulSlice { + if index >= 1 { + UnmarshalK8SYaml(t, statefulInfo, &statefulsetObj) + require.Equal(t, statefulsetObj.Name, "clusteringservice-test") + require.Equal(t, statefulsetObj.Spec.ServiceName, "clusteringservice-test-service") + } + } +} + func TestClusteringServiceDeploymentSecurityContext(t *testing.T) { var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} var supportedOperations = []string{"deploy", "install-deploy"} diff --git a/terratest/src/test/pega/clustering-service-service_test.go b/terratest/src/test/pega/clustering-service-service_test.go index 29d810ca0..0fbd88b30 100644 --- a/terratest/src/test/pega/clustering-service-service_test.go +++ b/terratest/src/test/pega/clustering-service-service_test.go @@ -1,42 +1,40 @@ package pega import ( + "fmt" + "path/filepath" + "strings" + "testing" + "github.com/gruntwork-io/terratest/modules/helm" "github.com/stretchr/testify/require" k8score "k8s.io/api/core/v1" intstr "k8s.io/apimachinery/pkg/util/intstr" - "path/filepath" - "strings" - "testing" - "fmt" ) - - -func TestClusteringService(t *testing.T){ - var supportedVendors = []string{"k8s","openshift","eks","gke","aks","pks"} - var supportedOperations = []string{"deploy","install-deploy"} +func TestClusteringService(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy"} helmChartPath, err := filepath.Abs(PegaHelmChartPath) require.NoError(t, err) + for _, vendor := range supportedVendors { - for _,vendor := range supportedVendors{ - - for _,operation := range supportedOperations{ + for _, operation := range supportedOperations { fmt.Println(vendor + "-" + operation) var options = &helm.Options{ SetValues: map[string]string{ - "global.provider": vendor, - "global.actions.execute": operation, - "hazelcast.clusteringServiceEnabled": "true", + "global.provider": vendor, + "global.actions.execute": operation, + "hazelcast.clusteringServiceEnabled": "true", }, } yamlContent := RenderTemplate(t, options, helmChartPath, []string{"charts/hazelcast/templates/clustering-service-service.yaml"}) - VerifyClusteringService(t,yamlContent,options) + VerifyClusteringService(t, yamlContent, options) } } } @@ -55,4 +53,45 @@ func VerifyClusteringService(t *testing.T, yamlContent string, options *helm.Opt require.Equal(t, intstr.FromInt(5701), clusteringServiceObj.Spec.Ports[0].TargetPort) } } -} \ No newline at end of file +} + +func TestClusteringServiceName(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy"} + + helmChartPath, err := filepath.Abs(PegaHelmChartPath) + require.NoError(t, err) + + for _, vendor := range supportedVendors { + + for _, operation := range supportedOperations { + + fmt.Println(vendor + "-" + operation) + + var options = &helm.Options{ + SetValues: map[string]string{ + "global.provider": vendor, + "global.actions.execute": operation, + "hazelcast.clusteringServiceEnabled": "true", + "hazelcast.deployment.name": "clustering-test", + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"charts/hazelcast/templates/clustering-service-service.yaml"}) + VerifyClusteringServiceName(t, yamlContent, options) + } + } +} + +func VerifyClusteringServiceName(t *testing.T, yamlContent string, options *helm.Options) { + var clusteringServiceObj k8score.Service + serviceSlice := strings.Split(yamlContent, "---") + for index, serviceInfo := range serviceSlice { + if index >= 1 { + UnmarshalK8SYaml(t, serviceInfo, &clusteringServiceObj) + require.Equal(t, "clustering-test-service", clusteringServiceObj.Name) + require.Equal(t, "Hazelcast", clusteringServiceObj.Spec.Selector["component"]) + require.Equal(t, "clustering-test", clusteringServiceObj.Spec.Selector["app"]) + } + } +} diff --git a/terratest/src/test/pega/pega-hz-deployment_test.go b/terratest/src/test/pega/pega-hz-deployment_test.go index 172b5dd4a..22c0c4ddf 100644 --- a/terratest/src/test/pega/pega-hz-deployment_test.go +++ b/terratest/src/test/pega/pega-hz-deployment_test.go @@ -65,6 +65,47 @@ func VerifyHazelcastDeployment(t *testing.T, yamlContent string) { } } +func TestHazelcastDeploymentName(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy"} + + helmChartPath, err := filepath.Abs(PegaHelmChartPath) + require.NoError(t, err) + + for _, vendor := range supportedVendors { + + for _, operation := range supportedOperations { + + var options = &helm.Options{ + SetValues: map[string]string{ + "global.provider": vendor, + "global.actions.execute": operation, + "hazelcast.enabled": "true", + "hazelcast.deployment.name": "hz-test", + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"charts/hazelcast/templates/pega-hz-deployment.yaml"}) + VerifyHazelcastDeploymentName(t, yamlContent) + + } + } +} + +func VerifyHazelcastDeploymentName(t *testing.T, yamlContent string) { + var statefulsetObj appsv1beta2.StatefulSet + statefulSlice := strings.Split(yamlContent, "---") + for index, statefulInfo := range statefulSlice { + if index >= 1 { + UnmarshalK8SYaml(t, statefulInfo, &statefulsetObj) + require.Equal(t, statefulsetObj.Name, "hz-test") + require.Equal(t, statefulsetObj.Spec.ServiceName, "hz-test-service") + statefulsetSpec := statefulsetObj.Spec.Template.Spec + require.Equal(t, statefulsetSpec.Volumes[1].Projected.Sources[0].Secret.Name, "pega-hz-secret") + } + } +} + func TestHazelcastDeploymentWithPodAffinity(t *testing.T) { var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} var supportedOperations = []string{"deploy", "install-deploy"} diff --git a/terratest/src/test/pega/pega-hz-service_test.go b/terratest/src/test/pega/pega-hz-service_test.go index b918a85c2..b15b8a163 100644 --- a/terratest/src/test/pega/pega-hz-service_test.go +++ b/terratest/src/test/pega/pega-hz-service_test.go @@ -1,29 +1,27 @@ package pega import ( + "fmt" + "path/filepath" + "strings" + "testing" + "github.com/gruntwork-io/terratest/modules/helm" "github.com/stretchr/testify/require" k8score "k8s.io/api/core/v1" intstr "k8s.io/apimachinery/pkg/util/intstr" - "path/filepath" - "strings" - "testing" - "fmt" ) - - -func TestHazelcastService(t *testing.T){ - var supportedVendors = []string{"k8s","openshift","eks","gke","aks","pks"} - var supportedOperations = []string{"deploy","install-deploy"} +func TestHazelcastService(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy"} helmChartPath, err := filepath.Abs(PegaHelmChartPath) require.NoError(t, err) + for _, vendor := range supportedVendors { - for _,vendor := range supportedVendors{ - - for _,operation := range supportedOperations{ + for _, operation := range supportedOperations { fmt.Println(vendor + "-" + operation) @@ -31,12 +29,12 @@ func TestHazelcastService(t *testing.T){ SetValues: map[string]string{ "global.provider": vendor, "global.actions.execute": operation, - "hazelcast.enabled": "true", + "hazelcast.enabled": "true", }, } yamlContent := RenderTemplate(t, options, helmChartPath, []string{"charts/hazelcast/templates/pega-hz-service.yaml"}) - VerifyHazelcastService(t,yamlContent,options) + VerifyHazelcastService(t, yamlContent, options) } } } @@ -55,4 +53,45 @@ func VerifyHazelcastService(t *testing.T, yamlContent string, options *helm.Opti require.Equal(t, intstr.FromInt(5701), hazelcastServiceObj.Spec.Ports[0].TargetPort) } } -} \ No newline at end of file +} + +func TestHazelcastServiceName(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy"} + + helmChartPath, err := filepath.Abs(PegaHelmChartPath) + require.NoError(t, err) + + for _, vendor := range supportedVendors { + + for _, operation := range supportedOperations { + + fmt.Println(vendor + "-" + operation) + + var options = &helm.Options{ + SetValues: map[string]string{ + "global.provider": vendor, + "global.actions.execute": operation, + "hazelcast.enabled": "true", + "hazelcast.deployment.name": "hz-test", + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"charts/hazelcast/templates/pega-hz-service.yaml"}) + VerifyHazelcastServiceName(t, yamlContent, options) + } + } +} + +func VerifyHazelcastServiceName(t *testing.T, yamlContent string, options *helm.Options) { + var hazelcastServiceObj k8score.Service + serviceSlice := strings.Split(yamlContent, "---") + for index, serviceInfo := range serviceSlice { + if index >= 1 { + UnmarshalK8SYaml(t, serviceInfo, &hazelcastServiceObj) + require.Equal(t, "hz-test-service", hazelcastServiceObj.Name) + require.Equal(t, "Hazelcast", hazelcastServiceObj.Spec.Selector["component"]) + require.Equal(t, "hz-test", hazelcastServiceObj.Spec.Selector["app"]) + } + } +}