From 73d4eef0607f0ea09336866fa16495c40e7e67b1 Mon Sep 17 00:00:00 2001 From: Sivanantham Chinnaiyan Date: Mon, 4 Mar 2024 15:00:10 +0530 Subject: [PATCH] Add Ingress probe Signed-off-by: Sivanantham Chinnaiyan --- .../reconcilers/ingress/ingress_reconciler.go | 56 +++++++++++++++---- test/e2e/common/utils.py | 5 -- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go b/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go index 9224894ae48..36a3e80165d 100644 --- a/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go +++ b/pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/ingress_reconciler.go @@ -18,11 +18,13 @@ package ingress import ( "context" + "crypto/tls" "fmt" + "net/http" + "strings" + "time" + "github.com/google/go-cmp/cmp" - "github.com/kserve/kserve/pkg/apis/serving/v1beta1" - "github.com/kserve/kserve/pkg/constants" - utils "github.com/kserve/kserve/pkg/utils" "github.com/pkg/errors" "google.golang.org/protobuf/testing/protocmp" istiov1beta1 "istio.io/api/networking/v1beta1" @@ -40,7 +42,9 @@ import ( knservingv1 "knative.dev/serving/pkg/apis/serving/v1" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "strings" + "github.com/kserve/kserve/pkg/apis/serving/v1beta1" + "github.com/kserve/kserve/pkg/constants" + utils "github.com/kserve/kserve/pkg/utils" "sigs.k8s.io/controller-runtime/pkg/client" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -48,6 +52,8 @@ import ( var ( log = logf.Log.WithName("IngressReconciler") + // probeTimeout defines the maximum amount of time a request will wait + probeTimeout = 1 * time.Second ) type IngressReconciler struct { @@ -522,17 +528,45 @@ func (ir *IngressReconciler) Reconcile(isvc *v1beta1.InferenceService) error { } else { hostPrefix = getHostPrefix(isvc, disableIstioVirtualHost, false) } - + host := network.GetServiceHostname(hostPrefix, isvc.Namespace) + scheme := "http" isvc.Status.Address = &duckv1.Addressable{ URL: &apis.URL{ - Host: network.GetServiceHostname(hostPrefix, isvc.Namespace), - Scheme: "http", + Host: host, + Scheme: scheme, }, } - isvc.Status.SetCondition(v1beta1.IngressReady, &apis.Condition{ - Type: v1beta1.IngressReady, - Status: corev1.ConditionTrue, - }) + target := isvc.Status.Address.URL.String() + transport := http.DefaultTransport.(*http.Transport).Clone() + transport.TLSClientConfig = &tls.Config{ + //nolint:gosec + // We only want to know that the Gateway is configured, not that the configuration is valid. + // Therefore, we can safely ignore any TLS certificate validation. + InsecureSkipVerify: true, + } + transport.DisableKeepAlives = true + ctx, cancel := context.WithTimeout(context.TODO(), probeTimeout) + defer cancel() + req, err := http.NewRequest(http.MethodGet, target, nil) + if err != nil { + return errors.Wrapf(err, "failed to probe ingress %s", target) + } + req = req.WithContext(ctx) + resp, err := transport.RoundTrip(req) + if err != nil { + return errors.Wrapf(err, "failed to probe ingress %s", target) + } + if resp.StatusCode == http.StatusOK { + isvc.Status.SetCondition(v1beta1.IngressReady, &apis.Condition{ + Type: v1beta1.IngressReady, + Status: corev1.ConditionTrue, + }) + } else { + isvc.Status.SetCondition(v1beta1.IngressReady, &apis.Condition{ + Type: v1beta1.IngressReady, + Status: corev1.ConditionFalse, + }) + } return nil } else { return errors.Wrapf(err, "fails to parse service url") diff --git a/test/e2e/common/utils.py b/test/e2e/common/utils.py index 326e6e31586..2870de3f46c 100644 --- a/test/e2e/common/utils.py +++ b/test/e2e/common/utils.py @@ -13,7 +13,6 @@ import json import logging import os -import time from urllib.parse import urlparse import grpc @@ -94,8 +93,6 @@ def predict_str(service_name, input_json, protocol_version="v1", logging.info("Sending Header = %s", headers) logging.info("Sending url = %s", url) logging.info("Sending request data: %s", input_json) - # temporary sleep until this is fixed https://github.com/kserve/kserve/issues/604 - time.sleep(10) response = requests.post(url, input_json, headers=headers) logging.info("Got response code %s, content %s", response.status_code, response.content) if response.status_code == 200: @@ -158,8 +155,6 @@ def explain_response(service_name, input_json): data = json.load(json_file) logging.info("Sending request data: %s", json.dumps(data)) try: - # temporary sleep until this is fixed https://github.com/kserve/kserve/issues/604 - time.sleep(10) response = requests.post(url, json.dumps(data), headers=headers) logging.info( "Got response code %s, content %s",