Skip to content

Commit 9e0af9d

Browse files
author
Jonathan Yu
authored
fix: unset service externalTrafficPolicy in examples (#188)
When using ClusterIP services, such as for Ingress objects, the LoadBalancer-specific externalTrafficPolicy setting must not be set, so explicitly unset it for those examples.
1 parent aa346d3 commit 9e0af9d

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

examples/ingress/ingress.values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ coderd:
33
serviceSpec:
44
# The Ingress will route traffic to the internal ClusterIP.
55
type: ClusterIP
6+
externalTrafficPolicy: ""
67

78
ingress:
89
enable: true

examples/kind/kind.values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ coderd:
33
serviceSpec:
44
# Avoid provisioning a LoadBalancer
55
type: ClusterIP
6+
externalTrafficPolicy: ""
67

78
# Reduce resource requirements for deployments using kind, which
89
# we typically use for development and test purposes only.

examples/openshift/openshift.values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ coderd:
33

44
serviceSpec:
55
type: ClusterIP
6+
externalTrafficPolicy: ""
67

78
# OpenShift's default "restricted" Security Context Constraint
89
# requires that these be unset. OpenShift manages the runAsUser

tests/examples_test.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func TestExamples(t *testing.T) {
1818

1919
chart := LoadChart(t)
2020

21+
exampleIngress, err := ReadValuesFileAsMap("../examples/ingress/ingress.values.yaml")
22+
require.NoError(t, err, "failed to load ingress example values")
23+
2124
exampleOpenShift, err := ReadValuesFileAsMap("../examples/openshift/openshift.values.yaml")
2225
require.NoError(t, err, "failed to load OpenShift example values")
2326

@@ -29,11 +32,16 @@ func TestExamples(t *testing.T) {
2932
Values map[string]interface{}
3033
PodSecurityContext *corev1.PodSecurityContext
3134
ContainerSecurityContext *corev1.SecurityContext
32-
Postgres *PostgresValues
35+
ServiceType corev1.ServiceType
3336
}{
3437
{
35-
Name: "default",
36-
Values: nil,
38+
Name: "default",
39+
Values: nil,
40+
ServiceType: corev1.ServiceTypeLoadBalancer,
41+
}, {
42+
Name: "ingress",
43+
Values: exampleIngress,
44+
ServiceType: corev1.ServiceTypeClusterIP,
3745
}, {
3846
Name: "openshift",
3947
Values: exampleOpenShift,
@@ -56,6 +64,7 @@ func TestExamples(t *testing.T) {
5664
ProcMount: nil,
5765
SeccompProfile: nil,
5866
},
67+
ServiceType: corev1.ServiceTypeClusterIP,
5968
},
6069
{
6170
Name: "kind",
@@ -84,6 +93,7 @@ func TestExamples(t *testing.T) {
8493
LocalhostProfile: nil,
8594
},
8695
},
96+
ServiceType: corev1.ServiceTypeClusterIP,
8797
},
8898
}
8999

@@ -143,6 +153,18 @@ func TestExamples(t *testing.T) {
143153
assert.Equal(t, test.ContainerSecurityContext, coderd.Spec.Template.Spec.Containers[0].SecurityContext,
144154
"expected matching container securityContext",
145155
)
156+
157+
service := MustFindService(t, objs, "coderd")
158+
assert.Equal(t, test.ServiceType, service.Spec.Type, "service type should match")
159+
switch test.ServiceType {
160+
case corev1.ServiceTypeLoadBalancer:
161+
assert.Empty(t, service.Spec.ExternalName, "external name should not be set")
162+
case corev1.ServiceTypeClusterIP:
163+
assert.Empty(t, service.Spec.ExternalName, "external name should not be set")
164+
assert.Nil(t, service.Spec.LoadBalancerClass, "loadBalancerClass should not be set")
165+
assert.Empty(t, service.Spec.LoadBalancerSourceRanges, "loadBalancerSourceRanges should not be set")
166+
assert.Empty(t, service.Spec.ExternalTrafficPolicy, "externalTrafficPolicy should not be set")
167+
}
146168
})
147169
}
148170
}

tests/utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ import (
88
"k8s.io/apimachinery/pkg/runtime"
99
)
1010

11+
// MustFindService finds a service in the given slice of objects with the
12+
// given name, or fails the test.
13+
func MustFindService(t testing.TB, objs []runtime.Object, name string) *corev1.Service {
14+
names := []string{}
15+
for _, obj := range objs {
16+
if service, ok := obj.(*corev1.Service); ok {
17+
if service.Name == name {
18+
return service
19+
}
20+
names = append(names, service.Name)
21+
}
22+
}
23+
24+
t.Fatalf("failed to find service %q, found %v", name, names)
25+
return nil
26+
}
27+
1128
// MustFindDeployment finds a deployment in the given slice of objects with the
1229
// given name, or fails the test.
1330
func MustFindDeployment(t testing.TB, objs []runtime.Object, name string) *appsv1.Deployment {

0 commit comments

Comments
 (0)