diff --git a/charts/pega/templates/_pega-service.tpl b/charts/pega/templates/_pega-service.tpl index cf659886f..5c7dc31e0 100644 --- a/charts/pega/templates/_pega-service.tpl +++ b/charts/pega/templates/_pega-service.tpl @@ -36,10 +36,18 @@ metadata: {{- end }} spec: type: - {{- if or (eq .root.Values.global.provider "gke") (eq .root.Values.global.provider "eks") -}} + {{- if (.node.service.serviceType) -}} + {{ indent 1 (.node.service.serviceType) }} + {{- else if or (eq .root.Values.global.provider "gke") (eq .root.Values.global.provider "eks") -}} {{ indent 1 "NodePort" }} {{- else -}} - {{ indent 1 (.node.service.serviceType | default "LoadBalancer") }} + {{ indent 1 "LoadBalancer" }} + {{- end }} + {{- if and ( and (.node.service.serviceType) (eq (toString .node.service.serviceType) "LoadBalancer")) (.node.service.loadBalancerSourceRanges) }} + loadBalancerSourceRanges: + {{- range .node.service.loadBalancerSourceRanges }} + - "{{ . }}" + {{- end }} {{- end }} # Specification of on which port the service is enabled ports: diff --git a/charts/pega/values.yaml b/charts/pega/values.yaml index 071b3ef45..63d5921c7 100644 --- a/charts/pega/values.yaml +++ b/charts/pega/values.yaml @@ -138,6 +138,18 @@ global: httpEnabled: true port: 80 targetPort: 8080 + # Use this parameter to deploy a specific type of service using the serviceType parameter and specify the type of service in double quotes. + # This is an optional value and should be used based on the use case. + # This should be set only in case of eks, gke and other cloud providers. This option should not be used for k8s and minikube. + # For example if you want to deploy a service of type LoadBalancer, uncomment the following line and specify serviceType: "LoadBalancer" + # serviceType: "" + # Specify the CIDR ranges to restrict the service access to the given CIDR range. + # Each new CIDR block should be added in a separate line. + # Should be used only when serviceType is set to LoadBalancer. + # Uncomment the following lines and replace the CIDR blocks with your configuration requirements. + # loadBalancerSourceRanges: + # - "123.123.123.0/24" + # - "128.128.128.64/32" # To configure TLS between the ingress/load balancer and the backend, set the following: tls: enabled: false diff --git a/terratest/src/test/pega/data/values_with_servicetype.yaml b/terratest/src/test/pega/data/values_with_servicetype.yaml new file mode 100644 index 000000000..1057c2745 --- /dev/null +++ b/terratest/src/test/pega/data/values_with_servicetype.yaml @@ -0,0 +1,49 @@ +--- +global: + tier: + - name: "web" + nodeType: "WebUser" + requestor: + passivationTimeSec: 900 + service: + httpEnabled: true + port: 80 + targetPort: 8080 + tls: + enabled: false + external_secret_name: "" + keystore: + keystorepassword: + port: 443 + targetPort: 8443 + cacertificate: + certificateFile: + certificateKeyFile: + traefik: + enabled: false + serverName: "" + insecureSkipVerify: false + serviceType: "LoadBalancer" + ingress: + domain: + tls: + enabled: true + certificate: + key: + cacertificate: + replicas: 1 + javaOpts: "" + pegaDiagnosticUser: "" + pegaDiagnosticPassword: "" + deploymentStrategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + type: RollingUpdate + livenessProbe: + port: 8081 + hpa: + enabled: true + pdb: + enabled: false + minAvailable: 1 diff --git a/terratest/src/test/pega/pega-tier-service-with-servicetype_test.go b/terratest/src/test/pega/pega-tier-service-with-servicetype_test.go new file mode 100644 index 000000000..3574698c3 --- /dev/null +++ b/terratest/src/test/pega/pega-tier-service-with-servicetype_test.go @@ -0,0 +1,45 @@ +package pega + +import ( + "fmt" + "github.com/gruntwork-io/terratest/modules/helm" + "github.com/stretchr/testify/require" + k8score "k8s.io/api/core/v1" + "path/filepath" + "strings" + "testing" +) + +func TestPegaServiceWithServiceType(t *testing.T) { + + var supportedVendors = []string{"openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"install-deploy"} + var deploymentNames = []string{"pega", "myapp-dev"} + + helmChartPath, err := filepath.Abs(PegaHelmChartPath) + require.NoError(t, err) + + for _, vendor := range supportedVendors { + for _, operation := range supportedOperations { + for _, depName := range deploymentNames { + fmt.Println(vendor + "-" + operation) + var options = &helm.Options{ + ValuesFiles: []string{"data/values_with_servicetype.yaml"}, + SetValues: map[string]string{ + "global.deployment.name": depName, + "global.provider": vendor, + "global.actions.execute": operation, + }, + } + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-service.yaml"}) + serviceyamlContent := strings.Split(yamlContent, "---") + var pegaServiceObj k8score.Service + UnmarshalK8SYaml(t, serviceyamlContent[1], &pegaServiceObj) + serviceType := pegaServiceObj.Spec.Type + require.Equal(t, k8score.ServiceType("LoadBalancer"), serviceType ) + } + } + } +} + +