Skip to content

Commit 82def1e

Browse files
kevin-shelagajenshushashankram
authored
[1.18 Backport] gateway params externaltrafficpolicy (#10552)
Signed-off-by: Shashank Ram <[email protected]> Co-authored-by: Jenny Shu <[email protected]> Co-authored-by: Shashank Ram <[email protected]>
1 parent 7b889c5 commit 82def1e

File tree

18 files changed

+163
-14
lines changed

18 files changed

+163
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
changelog:
2+
- type: FIX
3+
issueLink: https://github.com/k8sgateway/k8sgateway/issues/9879
4+
resolvesIssue: true
5+
description: >-
6+
Add ability to configure proxy service External Traffic Policy via Gateway Params

docs/content/reference/api/github.com/solo-io/gloo/projects/gateway2/api/v1alpha1/gateway_parameters.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7657,6 +7657,13 @@ Resource Types:
76577657
<br/>
76587658
</td>
76597659
<td>false</td>
7660+
</tr><tr>
7661+
<td><b>externalTrafficPolicy</b></td>
7662+
<td>string</td>
7663+
<td>
7664+
<br/>
7665+
</td>
7666+
<td>false</td>
76607667
</tr><tr>
76617668
<td><b>extraAnnotations</b></td>
76627669
<td>map[string]string</td>

docs/content/reference/values.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
|kubeGateway.gatewayParameters.glooGateway.service.type|string|LoadBalancer|K8s service type. If set to null, a default of LoadBalancer will be imposed.|
4343
|kubeGateway.gatewayParameters.glooGateway.service.extraLabels.NAME|string||Extra labels to add to the service.|
4444
|kubeGateway.gatewayParameters.glooGateway.service.extraAnnotations.NAME|string||Extra annotations to add to the service.|
45+
|kubeGateway.gatewayParameters.glooGateway.service.externalTrafficPolicy|string||Set the external traffic policy on the provisioned service.|
4546
|kubeGateway.gatewayParameters.glooGateway.serviceAccount.extraLabels.NAME|string||Extra labels to add to the service account.|
4647
|kubeGateway.gatewayParameters.glooGateway.serviceAccount.extraAnnotations.NAME|string||Extra annotations to add to the service account.|
4748
|kubeGateway.gatewayParameters.glooGateway.sdsContainer.image.tag|string|<release_version, ex: 1.2.3>|The image tag for the container.|
@@ -1002,7 +1003,7 @@
10021003
|gatewayProxies.NAME.service.httpsNodePort|int||HTTPS nodeport for the gateway service if using type NodePort|
10031004
|gatewayProxies.NAME.service.clusterIP|string||static clusterIP (or `None`) when `gatewayProxies[].gatewayProxy.service.type` is `ClusterIP`|
10041005
|gatewayProxies.NAME.service.extraAnnotations.NAME|string|||
1005-
|gatewayProxies.NAME.service.externalTrafficPolicy|string|||
1006+
|gatewayProxies.NAME.service.externalTrafficPolicy|string||Set the external traffic policy on the provisioned service.|
10061007
|gatewayProxies.NAME.service.name|string||Custom name override for the service resource of the proxy|
10071008
|gatewayProxies.NAME.service.httpsFirst|bool||List HTTPS port before HTTP|
10081009
|gatewayProxies.NAME.service.loadBalancerIP|string||IP address of the load balancer|
@@ -1255,7 +1256,7 @@
12551256
|gatewayProxies.gatewayProxy.service.httpsNodePort|int||HTTPS nodeport for the gateway service if using type NodePort|
12561257
|gatewayProxies.gatewayProxy.service.clusterIP|string||static clusterIP (or `None`) when `gatewayProxies[].gatewayProxy.service.type` is `ClusterIP`|
12571258
|gatewayProxies.gatewayProxy.service.extraAnnotations.NAME|string|||
1258-
|gatewayProxies.gatewayProxy.service.externalTrafficPolicy|string|||
1259+
|gatewayProxies.gatewayProxy.service.externalTrafficPolicy|string||Set the external traffic policy on the provisioned service.|
12591260
|gatewayProxies.gatewayProxy.service.name|string||Custom name override for the service resource of the proxy|
12601261
|gatewayProxies.gatewayProxy.service.httpsFirst|bool||List HTTPS port before HTTP|
12611262
|gatewayProxies.gatewayProxy.service.loadBalancerIP|string||IP address of the load balancer|

install/helm/gloo/crds/gateway.gloo.solo.io_gatewayparameters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,8 @@ spec:
20752075
properties:
20762076
clusterIP:
20772077
type: string
2078+
externalTrafficPolicy:
2079+
type: string
20782080
extraAnnotations:
20792081
additionalProperties:
20802082
type: string

install/helm/gloo/generate/values.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,10 @@ type ProvisionedDeployment struct {
369369
}
370370

371371
type ProvisionedService struct {
372-
Type *string `json:"type,omitempty" desc:"K8s service type. If set to null, a default of LoadBalancer will be imposed."`
373-
ExtraLabels map[string]string `json:"extraLabels,omitempty" desc:"Extra labels to add to the service."`
374-
ExtraAnnotations map[string]string `json:"extraAnnotations,omitempty" desc:"Extra annotations to add to the service."`
372+
Type *string `json:"type,omitempty" desc:"K8s service type. If set to null, a default of LoadBalancer will be imposed."`
373+
ExtraLabels map[string]string `json:"extraLabels,omitempty" desc:"Extra labels to add to the service."`
374+
ExtraAnnotations map[string]string `json:"extraAnnotations,omitempty" desc:"Extra annotations to add to the service."`
375+
ExternalTrafficPolicy *string `json:"externalTrafficPolicy,omitempty" desc:"Set the external traffic policy on the provisioned service."`
375376
}
376377

377378
type ProvisionedServiceAccount struct {
@@ -717,7 +718,7 @@ type GatewayProxyService struct {
717718
HttpsNodePort *int `json:"httpsNodePort,omitempty" desc:"HTTPS nodeport for the gateway service if using type NodePort"`
718719
ClusterIP *string "json:\"clusterIP,omitempty\" desc:\"static clusterIP (or `None`) when `gatewayProxies[].gatewayProxy.service.type` is `ClusterIP`\""
719720
ExtraAnnotations map[string]string `json:"extraAnnotations,omitempty"`
720-
ExternalTrafficPolicy *string `json:"externalTrafficPolicy,omitempty"`
721+
ExternalTrafficPolicy *string `json:"externalTrafficPolicy,omitempty" desc:"Set the external traffic policy on the provisioned service."`
721722
Name *string `json:"name,omitempty" desc:"Custom name override for the service resource of the proxy"`
722723
HttpsFirst *bool `json:"httpsFirst,omitempty" desc:"List HTTPS port before HTTP"`
723724
LoadBalancerIP *string `json:"loadBalancerIP,omitempty" desc:"IP address of the load balancer"`

install/helm/gloo/templates/43-gatewayparameters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ spec:
3131
{{- end }}{{/* if $gg.service */}}
3232
service:
3333
type: {{ $serviceType }}
34+
{{- with ($gg.service).externalTrafficPolicy }}
35+
externalTrafficPolicy: {{ . }}
36+
{{- end }}
3437
{{- with ($gg.service).extraLabels }}
3538
extraLabels:
3639
{{- toYaml . | nindent 8 }}

install/test/k8sgateway_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ var _ = Describe("Kubernetes Gateway API integration", func() {
153153
fmt.Sprintf("kubeGateway.gatewayParameters.glooGateway.envoyContainer.resources.limits.cpu=%s", envoyLimits["cpu"].ToUnstructured()),
154154
"kubeGateway.gatewayParameters.glooGateway.proxyDeployment.replicas=5",
155155
"kubeGateway.gatewayParameters.glooGateway.service.type=ClusterIP",
156+
"kubeGateway.gatewayParameters.glooGateway.service.externalTrafficPolicy=Local",
156157
"kubeGateway.gatewayParameters.glooGateway.service.extraLabels.svclabel1=x",
157158
"kubeGateway.gatewayParameters.glooGateway.service.extraAnnotations.svcanno1=y",
158159
"kubeGateway.gatewayParameters.glooGateway.serviceAccount.extraLabels.label1=a",
@@ -246,6 +247,7 @@ var _ = Describe("Kubernetes Gateway API integration", func() {
246247
Expect(gwpKube.GetSdsContainer().GetResources().Limits).To(matchers.ContainMapElements(sdsLimits))
247248

248249
Expect(*gwpKube.GetService().GetType()).To(Equal(corev1.ServiceTypeClusterIP))
250+
Expect(gwpKube.GetService().GetExternalTrafficPolicy()).To(HaveValue(Equal(corev1.ServiceExternalTrafficPolicyLocal)))
249251
Expect(gwpKube.GetService().GetExtraLabels()).To(matchers.ContainMapElements(map[string]string{"svclabel1": "x"}))
250252
Expect(gwpKube.GetService().GetExtraAnnotations()).To(matchers.ContainMapElements(map[string]string{"svcanno1": "y"}))
251253

@@ -282,6 +284,7 @@ var _ = Describe("Kubernetes Gateway API integration", func() {
282284
"kubeGateway.gatewayParameters.glooGateway.envoyContainer.image.pullPolicy=Always",
283285
"kubeGateway.gatewayParameters.glooGateway.proxyDeployment.replicas=5",
284286
"kubeGateway.gatewayParameters.glooGateway.service.type=ClusterIP",
287+
"kubeGateway.gatewayParameters.glooGateway.service.externalTrafficPolicy=Local",
285288
"kubeGateway.gatewayParameters.glooGateway.service.extraLabels.svclabel1=a",
286289
"kubeGateway.gatewayParameters.glooGateway.service.extraAnnotations.svcanno1=b",
287290
"kubeGateway.gatewayParameters.glooGateway.serviceAccount.extraLabels.label1=a",
@@ -324,6 +327,7 @@ var _ = Describe("Kubernetes Gateway API integration", func() {
324327
Expect(*gwpKube.GetSdsContainer().GetBootstrap().GetLogLevel()).To(Equal("debug"))
325328

326329
Expect(*gwpKube.GetService().GetType()).To(Equal(corev1.ServiceTypeClusterIP))
330+
Expect(gwpKube.GetService().GetExternalTrafficPolicy()).To(HaveValue(Equal(corev1.ServiceExternalTrafficPolicyLocal)))
327331
Expect(gwpKube.GetService().GetExtraLabels()).To(matchers.ContainMapElements(map[string]string{"svclabel1": "a"}))
328332
Expect(gwpKube.GetService().GetExtraAnnotations()).To(matchers.ContainMapElements(map[string]string{"svcanno1": "b"}))
329333

pkg/utils/kubeutils/service.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package kubeutils
2+
3+
import (
4+
"context"
5+
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
8+
corev1 "k8s.io/api/core/v1"
9+
"k8s.io/client-go/kubernetes"
10+
)
11+
12+
// GetService gets the service from the provided name/namespace
13+
func GetService(
14+
ctx context.Context,
15+
kubeClient *kubernetes.Clientset,
16+
serviceName string,
17+
serviceNamespace string,
18+
) (*corev1.Service, error) {
19+
20+
service, err := kubeClient.CoreV1().Services(serviceNamespace).Get(ctx, serviceName, metav1.GetOptions{})
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
return service, nil
26+
}

projects/gateway2/api/v1alpha1/kube_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ type Service struct {
9696
//
9797
// +kubebuilder:validation:Optional
9898
ExtraAnnotations map[string]string `json:"extraAnnotations,omitempty"`
99+
100+
// External Traffic Policy on the Service object.
101+
//
102+
// +kubebuilder:validation:Optional
103+
ExternalTrafficPolicy *corev1.ServiceExternalTrafficPolicy `json:"externalTrafficPolicy,omitempty"`
99104
}
100105

101106
func (in *Service) GetType() *corev1.ServiceType {
@@ -126,6 +131,13 @@ func (in *Service) GetExtraAnnotations() map[string]string {
126131
return in.ExtraAnnotations
127132
}
128133

134+
func (in *Service) GetExternalTrafficPolicy() *corev1.ServiceExternalTrafficPolicy {
135+
if in == nil {
136+
return nil
137+
}
138+
return in.ExternalTrafficPolicy
139+
}
140+
129141
type ServiceAccount struct {
130142
// Additional labels to add to the ServiceAccount object metadata.
131143
//

projects/gateway2/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)