Skip to content

Commit a82e344

Browse files
team-k8s-botrandmonkeyvictordrnd
authored
[Cherry-pick] fix: Do not add request-termination on TLSRoute / TCPRoute (#7700) (#7720) (#7729)
* fix: Do not add request-termination on TLSRoute / TCPRoute * fix: add import of strings and check nil * fix unit tests and golden test cases * add changelog --------- (cherry picked from commit cc67509) Co-authored-by: Tao Yi <tao.yi@konghq.com> Co-authored-by: Victor Durand <contact@victordurand.fr>
1 parent 9f0d81f commit a82e344

File tree

9 files changed

+17
-45
lines changed

9 files changed

+17
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ Adding a new version? You'll need three changes:
113113

114114
### Fixed
115115

116+
- Add `request-termination` plugin to return `500` if there are no available
117+
`backendRef` only when the service is translated from `HTTPRoute` or
118+
`GRPCRoute`.
119+
[#7720](https://github.com/Kong/kubernetes-ingress-controller/pull/7720)
116120
- Do not skip the gateway listeners without `Programmed` condition set to `True`
117121
when the gateway class does not contain `konghq.com/gateway-unmanaged`
118122
annotation in extracting certificates from listeners. This fixes the issue

internal/dataplane/testdata/golden/tcproute-example/default_golden.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ services:
44
host: tcproute.tcp-namespace.echo-plaintext.0
55
id: e2302e1e-0a75-5174-82f3-c0bc379a108a
66
name: tcproute.tcp-namespace.echo-plaintext.0
7-
plugins:
8-
- config:
9-
message: no existing backendRef provided
10-
status_code: 500
11-
name: request-termination
127
protocol: tcp
138
read_timeout: 60000
149
retries: 5

internal/dataplane/testdata/golden/tcproute-example/expression-routes-on_golden.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ services:
44
host: tcproute.tcp-namespace.echo-plaintext.0
55
id: e2302e1e-0a75-5174-82f3-c0bc379a108a
66
name: tcproute.tcp-namespace.echo-plaintext.0
7-
plugins:
8-
- config:
9-
message: no existing backendRef provided
10-
status_code: 500
11-
name: request-termination
127
protocol: tcp
138
read_timeout: 60000
149
retries: 5

internal/dataplane/testdata/golden/tlsroute-example/default_golden.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ services:
44
host: tlsroute.tls-namespace.echo-tls.0
55
id: 2a2aad7c-6331-5bcf-bd7c-d9516639f65d
66
name: tlsroute.tls-namespace.echo-tls.0
7-
plugins:
8-
- config:
9-
message: no existing backendRef provided
10-
status_code: 500
11-
name: request-termination
127
protocol: tcp
138
read_timeout: 60000
149
retries: 5

internal/dataplane/testdata/golden/tlsroute-example/expression-routes-on_golden.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ services:
44
host: tlsroute.tls-namespace.echo-tls.0
55
id: 2a2aad7c-6331-5bcf-bd7c-d9516639f65d
66
name: tlsroute.tls-namespace.echo-tls.0
7-
plugins:
8-
- config:
9-
message: no existing backendRef provided
10-
status_code: 500
11-
name: request-termination
127
protocol: tcp
138
read_timeout: 60000
149
retries: 5

internal/dataplane/testdata/golden/udproute-example/default_golden.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ services:
44
host: udproute.udp-example.tftp.0
55
id: 439fc57a-baff-51a3-9e1f-4e6af6b9dcae
66
name: udproute.udp-example.tftp.0
7-
plugins:
8-
- config:
9-
message: no existing backendRef provided
10-
status_code: 500
11-
name: request-termination
127
protocol: udp
138
read_timeout: 60000
149
retries: 5

internal/dataplane/testdata/golden/udproute-example/expression-routes-on_golden.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ services:
44
host: udproute.udp-example.tftp.0
55
id: 439fc57a-baff-51a3-9e1f-4e6af6b9dcae
66
name: udproute.udp-example.tftp.0
7-
plugins:
8-
- config:
9-
message: no existing backendRef provided
10-
status_code: 500
11-
name: request-termination
127
protocol: udp
138
read_timeout: 60000
149
retries: 5

internal/dataplane/translator/translate_utils.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package translator
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/go-logr/logr"
78
"github.com/kong/go-kong/kong"
@@ -79,13 +80,16 @@ func generateKongServiceFromBackendRefWithName(
7980
if service.Plugins == nil {
8081
service.Plugins = make([]kong.Plugin, 0)
8182
}
82-
service.Plugins = append(service.Plugins, kong.Plugin{
83-
Name: kong.String("request-termination"),
84-
Config: kong.Configuration{
85-
"status_code": 500,
86-
"message": "no existing backendRef provided",
87-
},
88-
})
83+
if service.Protocol != nil &&
84+
(strings.Contains(*service.Protocol, "http") || strings.Contains(*service.Protocol, "grpc")) {
85+
service.Plugins = append(service.Plugins, kong.Plugin{
86+
Name: kong.String("request-termination"),
87+
Config: kong.Configuration{
88+
"status_code": 500,
89+
"message": "no existing backendRef provided",
90+
},
91+
})
92+
}
8993
}
9094

9195
return service, nil

internal/dataplane/translator/translate_utils_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,8 @@ func TestGenerateKongServiceFromBackendRef(t *testing.T) {
290290
},
291291
Namespace: "behbudiy",
292292
Backends: []kongstate.ServiceBackend{},
293-
Plugins: []kong.Plugin{
294-
{
295-
Name: kong.String("request-termination"),
296-
Config: kong.Configuration{
297-
"status_code": 500,
298-
"message": "no existing backendRef provided",
299-
},
300-
},
293+
Plugins: []kong.Plugin{
294+
// No request-termination plugin is added for services with protocol not containing `http` or `grpc`.
301295
},
302296
Parent: &gatewayapi.TCPRoute{
303297
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)