Commit b8793127 authored by Han Wang's avatar Han Wang Committed by Hordur Freyr Yngvason
Browse files

feat: support NodePort deployments

parent 1442a247
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
apiVersion: v1
description: GitLab's Auto-deploy Helm Chart
name: auto-deploy-app
version: 2.18.0
version: 2.19.0
icon: https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
| service.annotations           | Service annotations | `{}`                       |
| service.name                  |             | `web`                              |
| service.type                  |             | `ClusterIP`                        |
| service.nodePort              | Used to set NodePort number if service.type == 'NodePort' | `30001`                        |
| service.url                   |             | `http://my.host.com/`              |
| service.additionalHosts       | If present, this list will add additional hostnames to the server configuration. | `nil` |
| service.commonName            | If present, this will define the ssl certificate common name to be used by CertManager. `service.url` and `service.additionalHosts` will be added as Subject Alternative Names (SANs) | `nil` |
+3 −0
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ spec:
    targetPort: {{ .Values.service.internalPort }}
    protocol: TCP
    name: {{ .Values.service.name }}
{{- if eq .Values.service.type "NodePort" }}
    nodePort: {{ .Values.service.nodePort }}
{{- end }}
  selector:
    app: {{ template "appname" . }}
    tier: "{{ .Values.application.tier }}"
+44 −0
Original line number Diff line number Diff line
@@ -7,8 +7,52 @@ import (
	"github.com/gruntwork-io/terratest/modules/helm"
	"github.com/stretchr/testify/require"
	coreV1 "k8s.io/api/core/v1"
	v1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/util/intstr"
)

func TestServiceTemplate_ServiceType(t *testing.T) {
	templates := []string{"templates/service.yaml"}
	releaseName := "test"
	tcs := []struct {
		name   string
		values map[string]string

		expectedName        string
		expectedType        string
		expectedPort        coreV1.ServicePort
		expectedErrorRegexp *regexp.Regexp
	}{
		{
			name:         "defaults",
			expectedType: "ClusterIP",
			expectedPort: coreV1.ServicePort{Port: 5000, TargetPort: intstr.FromInt(5000), Protocol: "TCP", Name: "web"},

		},
		{
			name:         "with NodePort",
			values: map[string]string{ "service.type": "NodePort" },
			expectedType: "NodePort",
			expectedPort: coreV1.ServicePort{Port: 5000, TargetPort: intstr.FromInt(5000), NodePort: 30001, Protocol: "TCP", Name: "web"},
		},
	}

	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
			output, ret := renderTemplate(t, tc.values, releaseName, templates, tc.expectedErrorRegexp)

			if ret == false {
				return
			}

			service := new(coreV1.Service)
			helm.UnmarshalK8SYaml(t, output, service)
			require.Equal(t, service.Spec.Type, v1.ServiceType(tc.expectedType))
			require.Equal(t, service.Spec.Ports, []coreV1.ServicePort{tc.expectedPort})
		})
	}
}

func TestServiceTemplate_DifferentTracks(t *testing.T) {
	templates := []string{"templates/service.yaml"}
	tcs := []struct {
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ service:
  commonName:
  externalPort: 5000
  internalPort: 5000
  nodePort: 30001
ingress:
  enabled: true
  path: "/"