Skip to content

Commit

Permalink
Review feedback: add additional server-side values missing
Browse files Browse the repository at this point in the history
  • Loading branch information
pebrc committed Apr 11, 2024
1 parent 749e878 commit 33da273
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
7 changes: 7 additions & 0 deletions pkg/controller/common/service_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ func applyServerSideValues(expected, reconciled *corev1.Service) {
if expected.Spec.Type == corev1.ServiceTypeLoadBalancer && expected.Spec.LoadBalancerClass == nil {
expected.Spec.LoadBalancerClass = reconciled.Spec.LoadBalancerClass
}

if expected.Spec.AllocateLoadBalancerNodePorts == nil {
expected.Spec.AllocateLoadBalancerNodePorts = reconciled.Spec.AllocateLoadBalancerNodePorts
}
if expected.Spec.ExternalTrafficPolicy == "" {
expected.Spec.ExternalTrafficPolicy = reconciled.Spec.ExternalTrafficPolicy
}
}

// hasNodePort returns for a given service type, if the service ports have a NodePort or not.
Expand Down
24 changes: 17 additions & 7 deletions pkg/controller/common/service_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,29 +564,39 @@ func Test_applyServerSideValues(t *testing.T) {
}},
},
{
name: "Reconciled InternalTrafficPolicy is used if the expected one is empty",
name: "Reconciled InternalTrafficPolicy/ExternalTrafficPolicy/AllocateLoadBalancerPorts are used if the expected one is empty",
args: args{
expected: corev1.Service{Spec: corev1.ServiceSpec{}},
reconciled: corev1.Service{Spec: corev1.ServiceSpec{
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyCluster),
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyCluster),
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyCluster,
AllocateLoadBalancerNodePorts: ptr.To(true),
}},
},
want: corev1.Service{Spec: corev1.ServiceSpec{
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyCluster),
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyCluster),
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyCluster,
AllocateLoadBalancerNodePorts: ptr.To(true),
}},
},
{
name: "Expected InternalTrafficPolicy is used if not empty",
name: "Expected InternalTrafficPolicy/ExternalTrafficPolicy/AllocateLoadBalancerPorts are used if not empty",
args: args{
expected: corev1.Service{Spec: corev1.ServiceSpec{
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyLocal),
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyLocal),
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
AllocateLoadBalancerNodePorts: ptr.To(false),
}},
reconciled: corev1.Service{Spec: corev1.ServiceSpec{
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyCluster),
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyCluster),
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyCluster,
AllocateLoadBalancerNodePorts: ptr.To(true),
}},
},
want: corev1.Service{Spec: corev1.ServiceSpec{
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyLocal),
InternalTrafficPolicy: pointer(corev1.ServiceInternalTrafficPolicyLocal),
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
AllocateLoadBalancerNodePorts: ptr.To(false),
}},
},
{
Expand Down

0 comments on commit 33da273

Please sign in to comment.