diff --git a/charts/pega/README.md b/charts/pega/README.md index 624d49c94..b4f33376b 100644 --- a/charts/pega/README.md +++ b/charts/pega/README.md @@ -1271,6 +1271,9 @@ Parameter | Description `hazelcast.password` | Configures the password to be used in a client-server Hazelcast model for authentication between the nodes in the Pega deployment and the nodes in the Hazelcast cluster. This parameter configures the password credential in Hazelcast cluster and your Pega nodes so authentication occurs automatically. | `""` `hazelcast.external_secret_name` | If you configured a secret in an external secrets operator, enter the secret name. For details, see [this section](#optional-support-for-providing-credentialscertificates-using-external-secrets-operator). | `""` `hazelcast.affinity` | Configures policy to assign the pods to the nodes. See the official [Kubernetes Documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). | `""` +`hazelcast.podLabels` | Provide custom labels for Pods as metadata to be consumed by other tools and libraries. | `""` +`hazelcast.deployment.labels` | Provide custom labels for the deployment (more precisely the StatefulSet) as metadata to be consumed by other tools and libraries. | `""` + #### Example ```yaml diff --git a/charts/pega/charts/hazelcast/templates/clustering-service-deployment.yaml b/charts/pega/charts/hazelcast/templates/clustering-service-deployment.yaml index fc772f082..48f60d14e 100644 --- a/charts/pega/charts/hazelcast/templates/clustering-service-deployment.yaml +++ b/charts/pega/charts/hazelcast/templates/clustering-service-deployment.yaml @@ -4,6 +4,10 @@ apiVersion: apps/v1 metadata: name: {{ template "clusteringServiceName" . }} namespace: {{ .Release.Namespace }} + labels: +{{- if and (.Values.deployment) (.Values.deployment.labels) }} +{{ toYaml .Values.deployment.labels | indent 4 }} +{{- end }} spec: selector: matchLabels: @@ -17,6 +21,9 @@ spec: app: {{ template "clusteringServiceName" . }} component: "Hazelcast" ops.identifier: "hazelcast" +{{- if .Values.podLabels }} +{{ toYaml .Values.podLabels | indent 8 }} +{{- end }} {{- include "generatedClusteringServicePodLabels" . | indent 8 }} annotations: {{- include "generatedClusteringServicePodAnnotations" . | indent 8 }} diff --git a/charts/pega/charts/hazelcast/templates/pega-hz-deployment.yaml b/charts/pega/charts/hazelcast/templates/pega-hz-deployment.yaml index 494c116ca..de861ca27 100644 --- a/charts/pega/charts/hazelcast/templates/pega-hz-deployment.yaml +++ b/charts/pega/charts/hazelcast/templates/pega-hz-deployment.yaml @@ -4,6 +4,10 @@ apiVersion: apps/v1 metadata: name: {{ template "hazelcastName" . }} namespace: {{ .Release.Namespace }} + labels: +{{- if and (.Values.deployment) (.Values.deployment.labels) }} +{{ toYaml .Values.deployment.labels | indent 4 }} +{{- end }} spec: selector: matchLabels: @@ -17,6 +21,9 @@ spec: app: {{ template "hazelcastName" . }} component: "Hazelcast" ops.identifier: "hazelcast" +{{- if .Values.podLabels }} +{{ toYaml .Values.podLabels | indent 8 }} +{{- end }} {{- include "generatedHazelcastServicePodLabels" . | indent 8 }} annotations: {{- include "generatedHazelcastServicePodAnnotations" . | indent 8 }} diff --git a/terratest/src/test/pega/clustering-service-deployment_test.go b/terratest/src/test/pega/clustering-service-deployment_test.go index 06497602d..66bfcbdf3 100644 --- a/terratest/src/test/pega/clustering-service-deployment_test.go +++ b/terratest/src/test/pega/clustering-service-deployment_test.go @@ -30,6 +30,7 @@ func TestClusteringServiceDeployment(t *testing.T) { "global.provider": vendor, "global.actions.execute": operation, "hazelcast.clusteringServiceEnabled": "true", + "hazelcast.podLabels.key1": "value1", }, } @@ -74,6 +75,8 @@ func VerifyClusteringServiceDeployment(t *testing.T, yamlContent string, ssl boo for index, statefulInfo := range statefulSlice { if index >= 1 { UnmarshalK8SYaml(t, statefulInfo, &statefulsetObj) + require.Empty(t, statefulsetObj.Labels) + require.Equal(t, statefulsetObj.Spec.Template.Labels["key1"], "value1") require.Equal(t, *statefulsetObj.Spec.Replicas, int32(3)) require.Equal(t, statefulsetObj.Spec.ServiceName, "clusteringservice-service") statefulsetSpec := statefulsetObj.Spec.Template.Spec diff --git a/terratest/src/test/pega/clustering-service-migration_test.go b/terratest/src/test/pega/clustering-service-migration_test.go index 05bcf7b3a..08f2b8e82 100644 --- a/terratest/src/test/pega/clustering-service-migration_test.go +++ b/terratest/src/test/pega/clustering-service-migration_test.go @@ -1,45 +1,46 @@ package pega import ( + "fmt" + "path/filepath" + "strings" + "testing" + "github.com/gruntwork-io/terratest/modules/helm" "github.com/stretchr/testify/require" - "path/filepath" k8sbatch "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" k8srbac "k8s.io/api/rbac/v1" - "testing" - "strings" - "fmt" ) func TestClusteringServiceMigration(t *testing.T) { var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} - var supportedOperations = []string{"deploy","install-deploy"} + 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) + fmt.Println(vendor + "-" + operation) var options = &helm.Options{ SetValues: map[string]string{ - "global.provider": vendor, - "global.actions.execute": operation, - "hazelcast.migration.initiateMigration": "true", - "hazelcast.clusteringServiceEnabled": "true", + "global.provider": vendor, + "global.actions.execute": operation, + "hazelcast.migration.initiateMigration": "true", + "hazelcast.clusteringServiceEnabled": "true", }, } yamlContent := RenderTemplate(t, options, helmChartPath, []string{"charts/hazelcast/templates/clustering-service-migration.yaml"}) yamlSplit := strings.Split(yamlContent, "---") assertServiceAccount(t, yamlSplit[1], options) - assertRole(t, yamlSplit[2], options) - assertRoleBinding(t, yamlSplit[3], options) + assertRole(t, yamlSplit[2], options) + assertRoleBinding(t, yamlSplit[3], options) assertMigrationJob(t, yamlSplit[4], options) } @@ -57,27 +58,27 @@ func assertRole(t *testing.T, roleYaml string, options *helm.Options) { var roleObj k8srbac.Role UnmarshalK8SYaml(t, roleYaml, &roleObj) - require.Equal(t, roleObj.ObjectMeta.Name, "clusteringservice-migration-role") - require.Equal(t, roleObj.ObjectMeta.Namespace, "default") + require.Equal(t, roleObj.ObjectMeta.Name, "clusteringservice-migration-role") + require.Equal(t, roleObj.ObjectMeta.Namespace, "default") require.Equal(t, roleObj.Rules[0].APIGroups, []string{""}) require.Equal(t, roleObj.Rules[0].Resources, []string{"pods"}) require.Equal(t, roleObj.Rules[0].Verbs, []string{"get", "list"}) - require.Equal(t, roleObj.Rules[1].APIGroups, []string{""}) - require.Equal(t, roleObj.Rules[1].Resources, []string{"pods/exec"}) - require.Equal(t, roleObj.Rules[1].Verbs, []string{"create"}) + require.Equal(t, roleObj.Rules[1].APIGroups, []string{""}) + require.Equal(t, roleObj.Rules[1].Resources, []string{"pods/exec"}) + require.Equal(t, roleObj.Rules[1].Verbs, []string{"create"}) } func assertRoleBinding(t *testing.T, roleBinding string, options *helm.Options) { var roleBindingObj k8srbac.RoleBinding UnmarshalK8SYaml(t, roleBinding, &roleBindingObj) - require.Equal(t, roleBindingObj.ObjectMeta.Name, "clusteringservice-migration-role-binding") - require.Equal(t, roleBindingObj.ObjectMeta.Namespace, "default") + require.Equal(t, roleBindingObj.ObjectMeta.Name, "clusteringservice-migration-role-binding") + require.Equal(t, roleBindingObj.ObjectMeta.Namespace, "default") require.Equal(t, roleBindingObj.Subjects[0].Kind, "ServiceAccount") require.Equal(t, roleBindingObj.Subjects[0].Name, "clusteringservice-migration-sa") - require.Equal(t, roleBindingObj.RoleRef.APIGroup, "rbac.authorization.k8s.io") - require.Equal(t, roleBindingObj.RoleRef.Kind, "Role") - require.Equal(t, roleBindingObj.RoleRef.Name, "clusteringservice-migration-role") + require.Equal(t, roleBindingObj.RoleRef.APIGroup, "rbac.authorization.k8s.io") + require.Equal(t, roleBindingObj.RoleRef.Kind, "Role") + require.Equal(t, roleBindingObj.RoleRef.Name, "clusteringservice-migration-role") } func assertMigrationJob(t *testing.T, jobYaml string, options *helm.Options) { @@ -86,10 +87,8 @@ func assertMigrationJob(t *testing.T, jobYaml string, options *helm.Options) { jobSpec := jobObj.Spec.Template.Spec - require.Equal(t, jobObj.ObjectMeta.Name, "clusteringservice-migration-job") - require.Equal(t, jobObj.ObjectMeta.Namespace, "default") - require.Equal(t, jobObj.Spec.Template.ObjectMeta.Name, "clusteringservice-migration-job") + require.Equal(t, jobObj.ObjectMeta.Name, "clusteringservice-migration-job") + require.Equal(t, jobObj.ObjectMeta.Namespace, "default") + require.Equal(t, jobObj.Spec.Template.ObjectMeta.Name, "clusteringservice-migration-job") require.Equal(t, jobSpec.ServiceAccountName, "clusteringservice-migration-sa") } - - diff --git a/terratest/src/test/pega/pega-hz-deployment_test.go b/terratest/src/test/pega/pega-hz-deployment_test.go index 172b5dd4a..35a80264c 100644 --- a/terratest/src/test/pega/pega-hz-deployment_test.go +++ b/terratest/src/test/pega/pega-hz-deployment_test.go @@ -24,9 +24,10 @@ func TestHazelcastDeployment(t *testing.T) { var options = &helm.Options{ SetValues: map[string]string{ - "global.provider": vendor, - "global.actions.execute": operation, - "hazelcast.enabled": "true", + "global.provider": vendor, + "global.actions.execute": operation, + "hazelcast.enabled": "true", + "hazelcast.podLabels.key1": "value1", }, } @@ -43,6 +44,8 @@ func VerifyHazelcastDeployment(t *testing.T, yamlContent string) { for index, statefulInfo := range statefulSlice { if index >= 1 { UnmarshalK8SYaml(t, statefulInfo, &statefulsetObj) + require.Empty(t, statefulsetObj.Labels) + require.Equal(t, statefulsetObj.Spec.Template.Labels["key1"], "value1") require.Equal(t, *statefulsetObj.Spec.Replicas, int32(3)) require.Equal(t, statefulsetObj.Spec.ServiceName, "pega-hazelcast-service") statefulsetSpec := statefulsetObj.Spec.Template.Spec