Skip to content

Commit 95f3bf4

Browse files
authored
Added support for configuring cluster ip on service (#141)
* Added support for configuring cluster ip on service * Handle updated mount output
1 parent fbc1f8a commit 95f3bf4

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

charts/k8s-service/templates/service.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ spec:
2727
- name: {{ $key }}
2828
{{ toYaml $value | indent 6 }}
2929
{{- end }}
30+
{{- if .Values.service.clusterIP }}
31+
clusterIP: {{ .Values.service.clusterIP }}
32+
{{- end }}
3033
selector:
3134
app.kubernetes.io/name: {{ include "k8s-service.name" . }}
3235
app.kubernetes.io/instance: {{ .Release.Name }}

charts/k8s-service/values.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ minPodsAvailable: 0
297297
# Deployment. This has the same structure as containerPorts, with the additional
298298
# key of `targetPort` to indicate which port of the container the service port
299299
# should route to. The `targetPort` can be a name defined in `containerPorts`.
300+
# - clusterIP (string) : The IP to use as the ClusterIP.
300301
# - sessionAffinity (string) : Used to maintain session affinity, as defined in Kubernetes - supports 'ClientIP' and 'None'
301302
# (https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies)
302303
# Kubernetes defaults to None.
@@ -306,7 +307,7 @@ minPodsAvailable: 0
306307
# The following example uses the default config and enables client IP based session affinity with a maximum session
307308
# sticky time of 3 hours.
308309
# EXAMPLE:
309-
#
310+
#
310311
# service:
311312
# enabled: true
312313
# ports:
@@ -318,7 +319,7 @@ minPodsAvailable: 0
318319
# sessionAffinityConfig:
319320
# clientIP:
320321
# timeoutSeconds: 10800
321-
#
322+
#
322323
# The default config configures a Service of type ClusterIP with no annotation, and binds port 80 of the pod to the
323324
# port 80 of the service, and names the binding as `app`:
324325
service:

test/k8s_service_template_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,3 +962,30 @@ func TestK8SServiceSessionAffinityOnlySetIfDefined(t *testing.T) {
962962
assert.Equal(t, corev1.ServiceAffinity(""), service.Spec.SessionAffinity)
963963
assert.Nil(t, service.Spec.SessionAffinityConfig)
964964
}
965+
966+
// Test that clusterIP is rendered correctly when it is set.
967+
func TestK8SServiceClusterIP(t *testing.T) {
968+
t.Parallel()
969+
970+
testCases := []string{
971+
// Unset
972+
"",
973+
// headless service:
974+
// https://kubernetes.io/docs/concepts/services-networking/service/#headless-services
975+
"None",
976+
// Some random IP
977+
"192.168.0.42",
978+
}
979+
980+
for _, tc := range testCases {
981+
t.Run(tc, func(t *testing.T) {
982+
values := make(map[string]string)
983+
if tc != "" {
984+
values["service.clusterIP"] = tc
985+
}
986+
987+
service := renderK8SServiceWithSetValues(t, values)
988+
assert.Equal(t, tc, service.Spec.ClusterIP)
989+
})
990+
}
991+
}

test/k8s_service_volume_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build all || integration
12
// +build all integration
23

34
// NOTE: We use build flags to differentiate between template tests and integration tests so that you can conveniently
@@ -60,5 +61,5 @@ func TestK8SServiceScratchSpaceIsTmpfs(t *testing.T) {
6061
pod := pods[0]
6162
logs, err := k8s.RunKubectlAndGetOutputE(t, kubectlOptions, "logs", pod.Name)
6263
require.NoError(t, err)
63-
require.Contains(t, logs, "tmpfs on /mnt/scratch type tmpfs (rw,relatime)")
64+
require.Contains(t, logs, "tmpfs on /mnt/scratch type tmpfs (rw,relatime,inode64)")
6465
}

0 commit comments

Comments
 (0)