Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added podLabels and deploymentLabels attributes to the clusteringservice/hazelcast charts #833

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions charts/pega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,8 @@ Parameter | Description | Default value
`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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestClusteringServiceDeployment(t *testing.T) {
"global.provider": vendor,
"global.actions.execute": operation,
"hazelcast.clusteringServiceEnabled": "true",
"hazelcast.podLabels.key1": "value1",
},
}

Expand All @@ -46,6 +47,8 @@ func VerifyClusteringServiceDeployment(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, "clusteringservice-service")
statefulsetSpec := statefulsetObj.Spec.Template.Spec
Expand Down
57 changes: 28 additions & 29 deletions terratest/src/test/pega/clustering-service-migration_test.go
Original file line number Diff line number Diff line change
@@ -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)

}
Expand All @@ -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) {
Expand All @@ -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")
}


9 changes: 6 additions & 3 deletions terratest/src/test/pega/pega-hz-deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand All @@ -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
Expand Down
Loading