generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 125
Feature/timeouts #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
k8s-ci-robot
merged 24 commits into
kubernetes-sigs:main
from
Stevenjin8:feature/timeouts
Feb 6, 2026
+431
−2
Merged
Feature/timeouts #289
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e4bc299
implement header manipulation for nginxingress
eladmotola aa0232e
pr comments
eladmotola e507ae5
fmt
eladmotola 7855e52
fmt
eladmotola a981915
fmt
eladmotola 2607469
fmt
eladmotola 925d85f
add TODOs
eladmotola 0e7ad52
Merge branch 'main' into feature/nginxingress-implement-header-manipu…
eladmotola 409a726
fix mege from master
eladmotola 2679f65
fmt
eladmotola 6b089ba
Update pkg/i2gw/providers/ingressnginx/headers.go
eladmotola 17988c1
timeouts
Stevenjin8 8f4ab04
timeouts
Stevenjin8 4a502a7
add warning for timeouts
Stevenjin8 33459e3
lint
Stevenjin8 41d140a
Merge remote-tracking branch 'up/main' into feature/timeouts
Stevenjin8 ac4c865
Lint
Stevenjin8 94b94a3
Merge remote-tracking branch 'up/main' into feature/timeouts
Stevenjin8 5187159
refactor timeout IR
Stevenjin8 73dbc71
update tests
Stevenjin8 482967e
lint
Stevenjin8 5d438b1
Merge remote-tracking branch 'up/main' into feature/timeouts
Stevenjin8 ecc9ab8
Merge remote-tracking branch 'up/main' into feature/timeouts
Stevenjin8 44b60f2
Merge remote-tracking branch 'up/main' into feature/timeouts
Stevenjin8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| Copyright 2026 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package common_emitter | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| emitterir "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/emitter_intermediate" | ||
| gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
| ) | ||
|
|
||
| func TestApplyHTTPRouteRequestTimeouts(t *testing.T) { | ||
| d := gatewayv1.Duration("10s") | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| ctx emitterir.HTTPRouteContext | ||
| wantSet bool | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "sets request timeout", | ||
| ctx: emitterir.HTTPRouteContext{ | ||
| HTTPRoute: gatewayv1.HTTPRoute{Spec: gatewayv1.HTTPRouteSpec{Rules: []gatewayv1.HTTPRouteRule{{}}}}, | ||
| RequestTimeouts: map[int]*gatewayv1.Duration{0: &d}, | ||
| }, | ||
| wantSet: true, | ||
| }, | ||
| { | ||
| name: "nil duration ignored", | ||
| ctx: emitterir.HTTPRouteContext{ | ||
| HTTPRoute: gatewayv1.HTTPRoute{Spec: gatewayv1.HTTPRouteSpec{Rules: []gatewayv1.HTTPRouteRule{{}}}}, | ||
| RequestTimeouts: map[int]*gatewayv1.Duration{0: nil}, | ||
| }, | ||
| wantSet: false, | ||
| }, | ||
| { | ||
| name: "out of range rule index", | ||
| ctx: emitterir.HTTPRouteContext{ | ||
| HTTPRoute: gatewayv1.HTTPRoute{Spec: gatewayv1.HTTPRouteSpec{Rules: []gatewayv1.HTTPRouteRule{{}}}}, | ||
| RequestTimeouts: map[int]*gatewayv1.Duration{1: &d}, | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| errList := applyHTTPRouteRequestTimeouts(&tc.ctx) | ||
| if tc.ctx.RequestTimeouts != nil { | ||
| t.Fatalf("expected RequestTimeouts to be nil after apply") | ||
| } | ||
| if tc.wantErr { | ||
| if len(errList) == 0 { | ||
| t.Fatalf("expected error") | ||
| } | ||
| return | ||
| } | ||
| if len(errList) > 0 { | ||
| t.Fatalf("expected no errors, got %v", errList) | ||
| } | ||
|
|
||
| got := tc.ctx.Spec.Rules[0].Timeouts | ||
| if tc.wantSet { | ||
| if got == nil || got.Request == nil { | ||
| t.Fatalf("expected request timeout to be set") | ||
| } | ||
| if *got.Request != d { | ||
| t.Fatalf("expected %v, got %v", d, *got.Request) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| if got != nil { | ||
| t.Fatalf("expected timeouts to be nil, got %v", got) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| Copyright 2023 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package ingressnginx | ||
|
|
||
| const ( | ||
| // Canary annotations | ||
| CanaryAnnotation = "nginx.ingress.kubernetes.io/canary" | ||
| CanaryWeightAnnotation = "nginx.ingress.kubernetes.io/canary-weight" | ||
| CanaryWeightTotalAnnotation = "nginx.ingress.kubernetes.io/canary-weight-total" | ||
|
|
||
| // Rewrite annotations | ||
| RewriteTargetAnnotation = "nginx.ingress.kubernetes.io/rewrite-target" | ||
|
|
||
| // Header annotations | ||
| XForwardedPrefixAnnotation = "nginx.ingress.kubernetes.io/x-forwarded-prefix" | ||
| UpstreamVhostAnnotation = "nginx.ingress.kubernetes.io/upstream-vhost" | ||
| ConnectionProxyHeaderAnnotation = "nginx.ingress.kubernetes.io/connection-proxy-header" | ||
| CustomHeadersAnnotation = "nginx.ingress.kubernetes.io/custom-headers" | ||
|
|
||
| // Timeout annotations | ||
| ProxyConnectTimeoutAnnotation = "nginx.ingress.kubernetes.io/proxy-connect-timeout" | ||
| ProxySendTimeoutAnnotation = "nginx.ingress.kubernetes.io/proxy-send-timeout" | ||
| ProxyReadTimeoutAnnotation = "nginx.ingress.kubernetes.io/proxy-read-timeout" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| Copyright 2023 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package ingressnginx | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications" | ||
| providerir "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/provider_intermediate" | ||
| networkingv1 "k8s.io/api/networking/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/apimachinery/pkg/util/validation/field" | ||
| gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
| ) | ||
|
|
||
| func headerModifierFeature(_ []networkingv1.Ingress, _ map[types.NamespacedName]map[string]int32, ir *providerir.ProviderIR) field.ErrorList { | ||
| for _, httpRouteContext := range ir.HTTPRoutes { | ||
| for i := range httpRouteContext.HTTPRoute.Spec.Rules { | ||
| if i >= len(httpRouteContext.RuleBackendSources) { | ||
| continue | ||
| } | ||
| sources := httpRouteContext.RuleBackendSources[i] | ||
|
|
||
| ingress := getNonCanaryIngress(sources) | ||
| if ingress == nil { | ||
| panic("No non-canary ingress found") | ||
| } | ||
|
|
||
| headersToSet := make(map[string]string) | ||
|
|
||
| _, hasRewriteTarget := ingress.Annotations[RewriteTargetAnnotation] | ||
|
|
||
| // 1. x-forwarded-prefix | ||
| // This annotation only works if rewrite-target is also present. | ||
| // TODO: X-Forwarded-Prefix is complex because it depends on rewrite-target. | ||
| // Deferring this to a future PR. | ||
| if val, ok := ingress.Annotations[XForwardedPrefixAnnotation]; ok && val != "" && hasRewriteTarget { | ||
| headersToSet["X-Forwarded-Prefix"] = val | ||
| } | ||
|
|
||
| // 2. upstream-vhost -> Host header | ||
| if val, ok := ingress.Annotations[UpstreamVhostAnnotation]; ok && val != "" { | ||
| headersToSet["Host"] = val | ||
| } | ||
|
|
||
| // 3. connection-proxy-header -> Connection header | ||
| if val, ok := ingress.Annotations[ConnectionProxyHeaderAnnotation]; ok && val != "" { | ||
| headersToSet["Connection"] = val | ||
| } | ||
|
|
||
| // 4. custom-headers -> Warn unsupported | ||
| // TODO: implement custom-headers annotation. | ||
| if _, ok := ingress.Annotations[CustomHeadersAnnotation]; ok { | ||
| notify(notifications.WarningNotification, fmt.Sprintf("Ingress %s/%s uses '%s' which is not supported.", ingress.Namespace, ingress.Name, CustomHeadersAnnotation), &httpRouteContext.HTTPRoute) | ||
| } | ||
|
|
||
| if len(headersToSet) > 0 { | ||
| applyHeaderModifiers(&httpRouteContext.HTTPRoute, i, headersToSet) | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func applyHeaderModifiers(httpRoute *gatewayv1.HTTPRoute, ruleIndex int, headersToSet map[string]string) { | ||
| // Find existing RequestHeaderModifier filter or create new one | ||
| var filter *gatewayv1.HTTPRouteFilter | ||
| for j, f := range httpRoute.Spec.Rules[ruleIndex].Filters { | ||
| if f.Type == gatewayv1.HTTPRouteFilterRequestHeaderModifier && f.RequestHeaderModifier != nil { | ||
| filter = &httpRoute.Spec.Rules[ruleIndex].Filters[j] | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if filter == nil { | ||
| f := gatewayv1.HTTPRouteFilter{ | ||
| Type: gatewayv1.HTTPRouteFilterRequestHeaderModifier, | ||
| RequestHeaderModifier: &gatewayv1.HTTPHeaderFilter{ | ||
| Set: []gatewayv1.HTTPHeader{}, | ||
| }, | ||
| } | ||
| httpRoute.Spec.Rules[ruleIndex].Filters = append(httpRoute.Spec.Rules[ruleIndex].Filters, f) | ||
| filter = &httpRoute.Spec.Rules[ruleIndex].Filters[len(httpRoute.Spec.Rules[ruleIndex].Filters)-1] | ||
| } | ||
|
|
||
| for name, value := range headersToSet { | ||
| // Used standard append as suggested in PR review | ||
| filter.RequestHeaderModifier.Set = append(filter.RequestHeaderModifier.Set, gatewayv1.HTTPHeader{ | ||
| Name: gatewayv1.HTTPHeaderName(name), | ||
| Value: value, | ||
| }) | ||
| notify(notifications.InfoNotification, fmt.Sprintf("Applied header modifier %s: %s to rule %d of route %s/%s", name, value, ruleIndex, httpRoute.Namespace, httpRoute.Name), httpRoute) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.