diff --git a/go.mod b/go.mod index ee0cc4d0c47..363687ef7c8 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,7 @@ require ( k8s.io/code-generator v0.30.4 k8s.io/klog v1.0.0 k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2 + k8s.io/utils v0.0.0-20240821151609-f90d01438635 knative.dev/networking v0.0.0-20240815142417-37fdbdd0854b knative.dev/pkg v0.0.0-20240815051656-89743d9bbf7c knative.dev/serving v0.42.2 @@ -129,7 +130,6 @@ require ( k8s.io/apiextensions-apiserver v0.30.4 // indirect k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7 // indirect k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/utils v0.0.0-20240821151609-f90d01438635 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect ) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 14d09a733c7..48fd74615ba 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -130,6 +130,8 @@ const ( NetworkVisibility = "networking.kserve.io/visibility" ClusterLocalVisibility = "cluster-local" ClusterLocalDomain = "svc.cluster.local" + IsvcNameHeader = "KServe-Isvc-Name" + IsvcNamespaceHeader = "KServe-Isvc-Namespace" ) // StorageSpec Constants diff --git a/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go b/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go index 18e80025fa3..2f6222b355b 100644 --- a/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go +++ b/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go @@ -440,9 +440,9 @@ func createIngress(isvc *v1beta1.InferenceService, useDefault bool, config *v1be Headers: &istiov1beta1.Headers{ Request: &istiov1beta1.Headers_HeaderOperations{ Set: map[string]string{ - "Host": network.GetServiceHostname(expBackend, isvc.Namespace), - "KServe-Isvc-Name": isvc.Name, - "KServe-Isvc-Namespace": isvc.Namespace, + "Host": network.GetServiceHostname(expBackend, isvc.Namespace), + constants.IsvcNameHeader: isvc.Name, + constants.IsvcNamespaceHeader: isvc.Namespace, }, }, }, @@ -459,9 +459,9 @@ func createIngress(isvc *v1beta1.InferenceService, useDefault bool, config *v1be Headers: &istiov1beta1.Headers{ Request: &istiov1beta1.Headers_HeaderOperations{ Set: map[string]string{ - "Host": network.GetServiceHostname(backend, isvc.Namespace), - "KServe-Isvc-Name": isvc.Name, - "KServe-Isvc-Namespace": isvc.Namespace, + "Host": network.GetServiceHostname(backend, isvc.Namespace), + constants.IsvcNameHeader: isvc.Name, + constants.IsvcNamespaceHeader: isvc.Namespace, }, }, }, @@ -510,12 +510,14 @@ func createIngress(isvc *v1beta1.InferenceService, useDefault bool, config *v1be }, }, Route: []*istiov1beta1.HTTPRouteDestination{ - createHTTPRouteDestination(config.LocalGatewayServiceName), + createHTTPRouteDestination(config.KnativeLocalGatewayService), }, Headers: &istiov1beta1.Headers{ Request: &istiov1beta1.Headers_HeaderOperations{ Set: map[string]string{ - "Host": network.GetServiceHostname(expBackend, isvc.Namespace), + "Host": network.GetServiceHostname(expBackend, isvc.Namespace), + constants.IsvcNameHeader: isvc.Name, + constants.IsvcNamespaceHeader: isvc.Namespace, }, }, }, @@ -559,9 +561,9 @@ func createIngress(isvc *v1beta1.InferenceService, useDefault bool, config *v1be Headers: &istiov1beta1.Headers{ Request: &istiov1beta1.Headers_HeaderOperations{ Set: map[string]string{ - "Host": network.GetServiceHostname(backend, isvc.Namespace), - "KServe-Isvc-Name": isvc.Name, - "KServe-Isvc-Namespace": isvc.Namespace, + "Host": network.GetServiceHostname(backend, isvc.Namespace), + constants.IsvcNameHeader: isvc.Name, + constants.IsvcNamespaceHeader: isvc.Namespace, }, }, }, diff --git a/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler_test.go b/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler_test.go index c53e7589030..afe5fa25955 100644 --- a/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler_test.go +++ b/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler_test.go @@ -952,14 +952,14 @@ func TestCreateVirtualService(t *testing.T) { }, { name: "found predictor and explainer status with path template", ingressConfig: &v1beta1.IngressConfig{ - IngressGateway: constants.KnativeIngressGateway, - IngressServiceName: "someIngressServiceName", - LocalGateway: constants.KnativeLocalGateway, - LocalGatewayServiceName: "knative-local-gateway.istio-system.svc.cluster.local", - UrlScheme: "http", - IngressDomain: "my-domain.com", - PathTemplate: "/serving/{{ .Namespace }}/{{ .Name }}", - DisableIstioVirtualHost: false, + IngressGateway: constants.KnativeIngressGateway, + KnativeLocalGatewayService: knativeLocalGatewayService, + LocalGateway: constants.KnativeLocalGateway, + LocalGatewayServiceName: knativeLocalGatewayService, + UrlScheme: "http", + IngressDomain: "my-domain.com", + PathTemplate: "/serving/{{ .Namespace }}/{{ .Name }}", + DisableIstioVirtualHost: false, }, useDefault: false, componentStatus: &v1beta1.InferenceServiceStatus{ @@ -1038,14 +1038,16 @@ func TestCreateVirtualService(t *testing.T) { }, }, Route: []*istiov1beta1.HTTPRouteDestination{ - { - Destination: &istiov1beta1.Destination{Host: constants.LocalGatewayHost, Port: &istiov1beta1.PortSelector{Number: constants.CommonDefaultHttpPort}}, - Weight: 100, + {Destination: &istiov1beta1.Destination{Host: knativeLocalGatewayService, Port: &istiov1beta1.PortSelector{Number: constants.CommonDefaultHttpPort}}, + Weight: 100, }, }, Headers: &istiov1beta1.Headers{ Request: &istiov1beta1.Headers_HeaderOperations{Set: map[string]string{ - "Host": network.GetServiceHostname(constants.ExplainerServiceName(serviceName), namespace)}, + "Host": network.GetServiceHostname(constants.ExplainerServiceName(serviceName), namespace), + constants.IsvcNameHeader: serviceName, + constants.IsvcNamespaceHeader: namespace, + }, }, }, }, @@ -1069,14 +1071,15 @@ func TestCreateVirtualService(t *testing.T) { }, }, Route: []*istiov1beta1.HTTPRouteDestination{ - { - Destination: &istiov1beta1.Destination{Host: constants.LocalGatewayHost, Port: &istiov1beta1.PortSelector{Number: constants.CommonDefaultHttpPort}}, - Weight: 100, + {Destination: &istiov1beta1.Destination{Host: knativeLocalGatewayService, Port: &istiov1beta1.PortSelector{Number: constants.CommonDefaultHttpPort}}, + Weight: 100, }, }, Headers: &istiov1beta1.Headers{ Request: &istiov1beta1.Headers_HeaderOperations{Set: map[string]string{ - "Host": network.GetServiceHostname(constants.PredictorServiceName(serviceName), namespace)}}, + "Host": network.GetServiceHostname(constants.PredictorServiceName(serviceName), namespace), + constants.IsvcNameHeader: serviceName, + constants.IsvcNamespaceHeader: namespace}}, }, }, { @@ -1102,12 +1105,14 @@ func TestCreateVirtualService(t *testing.T) { }, }, Route: []*istiov1beta1.HTTPRouteDestination{ - createHTTPRouteDestination("knative-local-gateway.istio-system.svc.cluster.local"), + createHTTPRouteDestination(knativeLocalGatewayService), }, Headers: &istiov1beta1.Headers{ Request: &istiov1beta1.Headers_HeaderOperations{ Set: map[string]string{ - "Host": network.GetServiceHostname(constants.ExplainerServiceName(serviceName), namespace), + "Host": network.GetServiceHostname(constants.ExplainerServiceName(serviceName), namespace), + constants.IsvcNameHeader: serviceName, + constants.IsvcNamespaceHeader: namespace, }, }, }, @@ -1145,12 +1150,14 @@ func TestCreateVirtualService(t *testing.T) { Uri: "/", }, Route: []*istiov1beta1.HTTPRouteDestination{ - createHTTPRouteDestination("knative-local-gateway.istio-system.svc.cluster.local"), + createHTTPRouteDestination(knativeLocalGatewayService), }, Headers: &istiov1beta1.Headers{ Request: &istiov1beta1.Headers_HeaderOperations{ Set: map[string]string{ - "Host": network.GetServiceHostname(constants.PredictorServiceName(serviceName), namespace), + "Host": network.GetServiceHostname(constants.PredictorServiceName(serviceName), namespace), + constants.IsvcNameHeader: serviceName, + constants.IsvcNamespaceHeader: namespace, }, }, },