-
Notifications
You must be signed in to change notification settings - Fork 26
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
Implement OpenShift Route creation for InferenceGraphs #480
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package inferencegraph | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"reflect" | ||
|
||
v1 "github.com/openshift/api/route/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
ctrlLog "sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
"github.com/kserve/kserve/pkg/apis/serving/v1alpha1" | ||
) | ||
|
||
type OpenShiftRouteReconciler struct { | ||
Scheme *runtime.Scheme | ||
Client client.Client | ||
} | ||
|
||
func (r *OpenShiftRouteReconciler) Reconcile(ctx context.Context, inferenceGraph *v1alpha1.InferenceGraph) (string, error) { | ||
logger := ctrlLog.FromContext(ctx, "subreconciler", "OpenShiftRoute") | ||
|
||
desiredRoute, err := r.buildOpenShiftRoute(inferenceGraph) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
nsName := types.NamespacedName{ | ||
Namespace: desiredRoute.Namespace, | ||
Name: desiredRoute.Name, | ||
} | ||
|
||
actualRoute := v1.Route{} | ||
err = client.IgnoreNotFound(r.Client.Get(ctx, nsName, &actualRoute)) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if len(actualRoute.Name) == 0 { | ||
logger.Info("Creating a new OpenShift Route for InferenceGraph", "namespace", desiredRoute.Namespace, "name", desiredRoute.Name) | ||
err = r.Client.Create(ctx, &desiredRoute) | ||
return getRouteHostname(&desiredRoute), err | ||
} | ||
|
||
if !reflect.DeepEqual(actualRoute.Spec, desiredRoute.Spec) { | ||
logger.Info("Updating OpenShift Route for InferenceGraph", "namespace", desiredRoute.Namespace, "name", desiredRoute.Name) | ||
actualRoute.Spec = desiredRoute.Spec | ||
err = r.Client.Update(ctx, &actualRoute) | ||
} | ||
|
||
return getRouteHostname(&actualRoute), err | ||
} | ||
|
||
func (r *OpenShiftRouteReconciler) buildOpenShiftRoute(inferenceGraph *v1alpha1.InferenceGraph) (v1.Route, error) { | ||
route := v1.Route{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: fmt.Sprintf("%s-route", inferenceGraph.Name), | ||
Namespace: inferenceGraph.Namespace, | ||
}, | ||
Spec: v1.RouteSpec{ | ||
To: v1.RouteTargetReference{ | ||
Kind: "Service", | ||
Name: inferenceGraph.GetName(), | ||
}, | ||
Port: &v1.RoutePort{ | ||
TargetPort: intstr.FromString(inferenceGraph.GetName()), | ||
}, | ||
}, | ||
} | ||
|
||
err := controllerutil.SetControllerReference(inferenceGraph, &route, r.Scheme) | ||
return route, err | ||
} | ||
|
||
func getRouteHostname(route *v1.Route) string { | ||
for _, entry := range route.Status.Ingress { | ||
return entry.Host | ||
} | ||
return "" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ package inferenceservice | |
import ( | ||
"context" | ||
"fmt" | ||
|
||
"time" | ||
|
||
"github.com/kserve/kserve/pkg/apis/serving/v1alpha1" | ||
|
@@ -29,9 +28,10 @@ import ( | |
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
. "github.com/onsi/ginkgo/v2" | ||
|
||
"github.com/kserve/kserve/pkg/apis/serving/v1beta1" | ||
"github.com/kserve/kserve/pkg/constants" | ||
. "github.com/onsi/ginkgo/v2" | ||
|
||
"github.com/onsi/gomega" | ||
. "github.com/onsi/gomega" | ||
|
@@ -41,7 +41,6 @@ import ( | |
autoscalingv2 "k8s.io/api/autoscaling/v2" | ||
v1 "k8s.io/api/core/v1" | ||
|
||
v1beta1utils "github.com/kserve/kserve/pkg/controller/v1beta1/inferenceservice/utils" | ||
routev1 "github.com/openshift/api/route/v1" | ||
netv1 "k8s.io/api/networking/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
@@ -51,6 +50,8 @@ import ( | |
"knative.dev/pkg/apis" | ||
duckv1 "knative.dev/pkg/apis/duck/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
v1beta1utils "github.com/kserve/kserve/pkg/controller/v1beta1/inferenceservice/utils" | ||
) | ||
|
||
var _ = Describe("v1beta1 inference service controller", func() { | ||
|
@@ -2605,21 +2606,22 @@ var _ = Describe("v1beta1 inference service controller", func() { | |
}, | ||
WildcardPolicy: routev1.WildcardPolicyNone, | ||
}, | ||
Status: routev1.RouteStatus{ | ||
Ingress: []routev1.RouteIngress{ | ||
{ | ||
Host: "raw-auth-default.example.com", | ||
Conditions: []routev1.RouteIngressCondition{ | ||
{ | ||
Type: routev1.RouteAdmitted, | ||
Status: v1.ConditionTrue, | ||
}, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this for inferencegraph test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. I updated the CRD test file Something was wrong with the old CRD definition. The kube client typically doesn't save the |
||
Expect(k8sClient.Create(context.TODO(), route)).Should(Succeed()) | ||
route.Status = routev1.RouteStatus{ | ||
Ingress: []routev1.RouteIngress{ | ||
{ | ||
Host: "raw-auth-default.example.com", | ||
Conditions: []routev1.RouteIngressCondition{ | ||
{ | ||
Type: routev1.RouteAdmitted, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
Expect(k8sClient.Create(context.TODO(), route)).Should(Succeed()) | ||
Expect(k8sClient.Status().Update(ctx, route)).Should(Succeed()) | ||
|
||
//check isvc status | ||
updatedDeployment := actualDeployment.DeepCopy() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks it uses http protocol. do we need to use https?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be the goal of this Jira: https://issues.redhat.com/browse/RHOAIENG-18978