Skip to content

Commit d97baa6

Browse files
Fix ingress configuration for path based routing and update go mod (kserve#3944)
Fix broken ingress test and update go mod Signed-off-by: Sivanantham Chinnaiyan <[email protected]>
1 parent 536fc9b commit d97baa6

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535
k8s.io/code-generator v0.30.4
3636
k8s.io/klog v1.0.0
3737
k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2
38+
k8s.io/utils v0.0.0-20240821151609-f90d01438635
3839
knative.dev/networking v0.0.0-20240815142417-37fdbdd0854b
3940
knative.dev/pkg v0.0.0-20240815051656-89743d9bbf7c
4041
knative.dev/serving v0.42.2
@@ -129,7 +130,6 @@ require (
129130
k8s.io/apiextensions-apiserver v0.30.4 // indirect
130131
k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7 // indirect
131132
k8s.io/klog/v2 v2.130.1 // indirect
132-
k8s.io/utils v0.0.0-20240821151609-f90d01438635 // indirect
133133
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
134134
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
135135
)

pkg/constants/constants.go

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ const (
130130
NetworkVisibility = "networking.kserve.io/visibility"
131131
ClusterLocalVisibility = "cluster-local"
132132
ClusterLocalDomain = "svc.cluster.local"
133+
IsvcNameHeader = "KServe-Isvc-Name"
134+
IsvcNamespaceHeader = "KServe-Isvc-Namespace"
133135
)
134136

135137
// StorageSpec Constants

pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ func createIngress(isvc *v1beta1.InferenceService, useDefault bool, config *v1be
440440
Headers: &istiov1beta1.Headers{
441441
Request: &istiov1beta1.Headers_HeaderOperations{
442442
Set: map[string]string{
443-
"Host": network.GetServiceHostname(expBackend, isvc.Namespace),
444-
"KServe-Isvc-Name": isvc.Name,
445-
"KServe-Isvc-Namespace": isvc.Namespace,
443+
"Host": network.GetServiceHostname(expBackend, isvc.Namespace),
444+
constants.IsvcNameHeader: isvc.Name,
445+
constants.IsvcNamespaceHeader: isvc.Namespace,
446446
},
447447
},
448448
},
@@ -459,9 +459,9 @@ func createIngress(isvc *v1beta1.InferenceService, useDefault bool, config *v1be
459459
Headers: &istiov1beta1.Headers{
460460
Request: &istiov1beta1.Headers_HeaderOperations{
461461
Set: map[string]string{
462-
"Host": network.GetServiceHostname(backend, isvc.Namespace),
463-
"KServe-Isvc-Name": isvc.Name,
464-
"KServe-Isvc-Namespace": isvc.Namespace,
462+
"Host": network.GetServiceHostname(backend, isvc.Namespace),
463+
constants.IsvcNameHeader: isvc.Name,
464+
constants.IsvcNamespaceHeader: isvc.Namespace,
465465
},
466466
},
467467
},
@@ -510,12 +510,14 @@ func createIngress(isvc *v1beta1.InferenceService, useDefault bool, config *v1be
510510
},
511511
},
512512
Route: []*istiov1beta1.HTTPRouteDestination{
513-
createHTTPRouteDestination(config.LocalGatewayServiceName),
513+
createHTTPRouteDestination(config.KnativeLocalGatewayService),
514514
},
515515
Headers: &istiov1beta1.Headers{
516516
Request: &istiov1beta1.Headers_HeaderOperations{
517517
Set: map[string]string{
518-
"Host": network.GetServiceHostname(expBackend, isvc.Namespace),
518+
"Host": network.GetServiceHostname(expBackend, isvc.Namespace),
519+
constants.IsvcNameHeader: isvc.Name,
520+
constants.IsvcNamespaceHeader: isvc.Namespace,
519521
},
520522
},
521523
},
@@ -559,9 +561,9 @@ func createIngress(isvc *v1beta1.InferenceService, useDefault bool, config *v1be
559561
Headers: &istiov1beta1.Headers{
560562
Request: &istiov1beta1.Headers_HeaderOperations{
561563
Set: map[string]string{
562-
"Host": network.GetServiceHostname(backend, isvc.Namespace),
563-
"KServe-Isvc-Name": isvc.Name,
564-
"KServe-Isvc-Namespace": isvc.Namespace,
564+
"Host": network.GetServiceHostname(backend, isvc.Namespace),
565+
constants.IsvcNameHeader: isvc.Name,
566+
constants.IsvcNamespaceHeader: isvc.Namespace,
565567
},
566568
},
567569
},

pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler_test.go

+27-20
Original file line numberDiff line numberDiff line change
@@ -952,14 +952,14 @@ func TestCreateVirtualService(t *testing.T) {
952952
}, {
953953
name: "found predictor and explainer status with path template",
954954
ingressConfig: &v1beta1.IngressConfig{
955-
IngressGateway: constants.KnativeIngressGateway,
956-
IngressServiceName: "someIngressServiceName",
957-
LocalGateway: constants.KnativeLocalGateway,
958-
LocalGatewayServiceName: "knative-local-gateway.istio-system.svc.cluster.local",
959-
UrlScheme: "http",
960-
IngressDomain: "my-domain.com",
961-
PathTemplate: "/serving/{{ .Namespace }}/{{ .Name }}",
962-
DisableIstioVirtualHost: false,
955+
IngressGateway: constants.KnativeIngressGateway,
956+
KnativeLocalGatewayService: knativeLocalGatewayService,
957+
LocalGateway: constants.KnativeLocalGateway,
958+
LocalGatewayServiceName: knativeLocalGatewayService,
959+
UrlScheme: "http",
960+
IngressDomain: "my-domain.com",
961+
PathTemplate: "/serving/{{ .Namespace }}/{{ .Name }}",
962+
DisableIstioVirtualHost: false,
963963
},
964964
useDefault: false,
965965
componentStatus: &v1beta1.InferenceServiceStatus{
@@ -1038,14 +1038,16 @@ func TestCreateVirtualService(t *testing.T) {
10381038
},
10391039
},
10401040
Route: []*istiov1beta1.HTTPRouteDestination{
1041-
{
1042-
Destination: &istiov1beta1.Destination{Host: constants.LocalGatewayHost, Port: &istiov1beta1.PortSelector{Number: constants.CommonDefaultHttpPort}},
1043-
Weight: 100,
1041+
{Destination: &istiov1beta1.Destination{Host: knativeLocalGatewayService, Port: &istiov1beta1.PortSelector{Number: constants.CommonDefaultHttpPort}},
1042+
Weight: 100,
10441043
},
10451044
},
10461045
Headers: &istiov1beta1.Headers{
10471046
Request: &istiov1beta1.Headers_HeaderOperations{Set: map[string]string{
1048-
"Host": network.GetServiceHostname(constants.ExplainerServiceName(serviceName), namespace)},
1047+
"Host": network.GetServiceHostname(constants.ExplainerServiceName(serviceName), namespace),
1048+
constants.IsvcNameHeader: serviceName,
1049+
constants.IsvcNamespaceHeader: namespace,
1050+
},
10491051
},
10501052
},
10511053
},
@@ -1069,14 +1071,15 @@ func TestCreateVirtualService(t *testing.T) {
10691071
},
10701072
},
10711073
Route: []*istiov1beta1.HTTPRouteDestination{
1072-
{
1073-
Destination: &istiov1beta1.Destination{Host: constants.LocalGatewayHost, Port: &istiov1beta1.PortSelector{Number: constants.CommonDefaultHttpPort}},
1074-
Weight: 100,
1074+
{Destination: &istiov1beta1.Destination{Host: knativeLocalGatewayService, Port: &istiov1beta1.PortSelector{Number: constants.CommonDefaultHttpPort}},
1075+
Weight: 100,
10751076
},
10761077
},
10771078
Headers: &istiov1beta1.Headers{
10781079
Request: &istiov1beta1.Headers_HeaderOperations{Set: map[string]string{
1079-
"Host": network.GetServiceHostname(constants.PredictorServiceName(serviceName), namespace)}},
1080+
"Host": network.GetServiceHostname(constants.PredictorServiceName(serviceName), namespace),
1081+
constants.IsvcNameHeader: serviceName,
1082+
constants.IsvcNamespaceHeader: namespace}},
10801083
},
10811084
},
10821085
{
@@ -1102,12 +1105,14 @@ func TestCreateVirtualService(t *testing.T) {
11021105
},
11031106
},
11041107
Route: []*istiov1beta1.HTTPRouteDestination{
1105-
createHTTPRouteDestination("knative-local-gateway.istio-system.svc.cluster.local"),
1108+
createHTTPRouteDestination(knativeLocalGatewayService),
11061109
},
11071110
Headers: &istiov1beta1.Headers{
11081111
Request: &istiov1beta1.Headers_HeaderOperations{
11091112
Set: map[string]string{
1110-
"Host": network.GetServiceHostname(constants.ExplainerServiceName(serviceName), namespace),
1113+
"Host": network.GetServiceHostname(constants.ExplainerServiceName(serviceName), namespace),
1114+
constants.IsvcNameHeader: serviceName,
1115+
constants.IsvcNamespaceHeader: namespace,
11111116
},
11121117
},
11131118
},
@@ -1145,12 +1150,14 @@ func TestCreateVirtualService(t *testing.T) {
11451150
Uri: "/",
11461151
},
11471152
Route: []*istiov1beta1.HTTPRouteDestination{
1148-
createHTTPRouteDestination("knative-local-gateway.istio-system.svc.cluster.local"),
1153+
createHTTPRouteDestination(knativeLocalGatewayService),
11491154
},
11501155
Headers: &istiov1beta1.Headers{
11511156
Request: &istiov1beta1.Headers_HeaderOperations{
11521157
Set: map[string]string{
1153-
"Host": network.GetServiceHostname(constants.PredictorServiceName(serviceName), namespace),
1158+
"Host": network.GetServiceHostname(constants.PredictorServiceName(serviceName), namespace),
1159+
constants.IsvcNameHeader: serviceName,
1160+
constants.IsvcNamespaceHeader: namespace,
11541161
},
11551162
},
11561163
},

0 commit comments

Comments
 (0)