Skip to content
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

feat(tas): Re-enable KServe Raw support #361

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/tas/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func setupAndTestDeploymentInferenceService(instance *trustyaiopendatahubiov1alp
return k8sClient.Create(ctx, inferenceService)
}, "failed to create deployment")

Expect(reconciler.patchKServe(ctx, instance, *inferenceService, namespace, instance.Name, false)).ToNot(HaveOccurred())
Expect(reconciler.patchKServe(ctx, instance, *inferenceService, namespace, instance.Name, false, false)).ToNot(HaveOccurred())

deployment := &appsv1.Deployment{}
WaitFor(func() error {
Expand Down
58 changes: 39 additions & 19 deletions controllers/tas/inference_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func generateEnvVarValue(currentValue, newValue string, remove bool) string {
return currentValue
}

func (r *TrustyAIServiceReconciler) handleInferenceServices(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService, namespace string, labelKey string, labelValue string, envVarName string, crName string, remove bool) (bool, error) {
func (r *TrustyAIServiceReconciler) handleInferenceServices(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService, namespace string, labelKey, labelValue, envVarName, crName string, remove bool) (bool, error) {
var inferenceServices kservev1beta1.InferenceServiceList

if err := r.List(ctx, &inferenceServices, client.InNamespace(namespace)); err != nil {
Expand All @@ -231,36 +231,56 @@ func (r *TrustyAIServiceReconciler) handleInferenceServices(ctx context.Context,

for _, infService := range inferenceServices.Items {
annotations := infService.GetAnnotations()
deploymentMode, ok := annotations["serving.kserve.io/deploymentMode"]

// Check the annotation "serving.kserve.io/deploymentMode"
if val, ok := annotations["serving.kserve.io/deploymentMode"]; ok {
if val == DEPLOYMENT_MODE_RAW {
log.FromContext(ctx).Info("RawDeployment mode not supported by TrustyAI")
continue
} else if val == DEPLOYMENT_MODE_MODELMESH {
shouldContinue, err := r.patchEnvVarsByLabelForDeployments(ctx, instance, namespace, labelKey, labelValue, envVarName, crName, remove)
if err != nil {
log.FromContext(ctx).Error(err, "could not patch environment variables for ModelMesh deployments")
return shouldContinue, err
}
continue
}
if !ok {
// Model is not annotated as either KServe serverless, KServe Raw or ModelMesh
continue
}
if kServeServerlessEnabled {
err := r.patchKServe(ctx, instance, infService, namespace, crName, remove)

switch deploymentMode {
case DEPLOYMENT_MODE_MODELMESH:
// Handle ModelMesh deployments
shouldContinue, err := r.patchEnvVarsByLabelForDeployments(ctx, instance, namespace, labelKey, labelValue, envVarName, crName, remove)
if err != nil {
log.FromContext(ctx).Error(err, "Could not patch environment variables for ModelMesh deployments")
return shouldContinue, err
}
continue

case DEPLOYMENT_MODE_RAW:
// Handle KServe Raw deployments
err := r.patchKServe(ctx, instance, infService, namespace, crName, remove, true)
if err != nil {
log.FromContext(ctx).Error(err, "could not patch InferenceLogger for KServe deployment")
log.FromContext(ctx).Error(err, "Could not patch InferenceLogger for KServe Raw deployment")
return false, err
}
continue

default:
// Handle KServe Serverless deployments
if kServeServerlessEnabled {
err := r.patchKServe(ctx, instance, infService, namespace, crName, remove, false)
if err != nil {
log.FromContext(ctx).Error(err, "Could not patch InferenceLogger for KServe Serverless deployment")
return false, err
}
}
continue
}
}
return true, nil
}

// patchKServe adds a TrustyAI service as an InferenceLogger to a KServe InferenceService
func (r *TrustyAIServiceReconciler) patchKServe(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService, infService kservev1beta1.InferenceService, namespace string, crName string, remove bool) error {
func (r *TrustyAIServiceReconciler) patchKServe(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService, infService kservev1beta1.InferenceService, namespace string, crName string, remove bool, useHTTPS bool) error {

url := utils.GenerateKServeLoggerURL(crName, namespace)
var url string
if useHTTPS {
url = utils.GenerateHTTPSKServeLoggerURL(crName, namespace)
} else {
url = utils.GenerateKServeLoggerURL(crName, namespace)
}

if remove {
if infService.Spec.Predictor.Logger == nil || *infService.Spec.Predictor.Logger.URL != url {
Expand Down
2 changes: 1 addition & 1 deletion controllers/tas/statuses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ var _ = Describe("Status and condition tests", func() {
return k8sClient.Create(ctx, inferenceService)
}, "failed to create InferenceService")

Expect(reconciler.patchKServe(ctx, instance, *inferenceService, namespace, instance.Name, false)).ToNot(HaveOccurred())
Expect(reconciler.patchKServe(ctx, instance, *inferenceService, namespace, instance.Name, false, false)).ToNot(HaveOccurred())

WaitFor(func() error {
return k8sClient.Create(ctx, instance)
Expand Down
5 changes: 5 additions & 0 deletions controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ func GenerateNonTLSServiceURL(crName string, namespace string) string {
func GenerateKServeLoggerURL(crName string, namespace string) string {
return "http://" + crName + "." + namespace + ".svc.cluster.local"
}

// generateHTTPSKServeLoggerURL generates an HTTPS logger url for KServe Inference Loggers
func GenerateHTTPSKServeLoggerURL(crName string, namespace string) string {
return "https://" + crName + "." + namespace + ".svc.cluster.local"
}
Loading
Loading