Skip to content

feat(controller): added reconciliation of inferenceservice url#960

Merged
google-oss-prow[bot] merged 7 commits intokubeflow:mainfrom
Al-Pragliola:al-pragliola-inference-service-url
May 5, 2025
Merged

feat(controller): added reconciliation of inferenceservice url#960
google-oss-prow[bot] merged 7 commits intokubeflow:mainfrom
Al-Pragliola:al-pragliola-inference-service-url

Conversation

@Al-Pragliola
Copy link
Copy Markdown
Contributor

@Al-Pragliola Al-Pragliola commented Apr 10, 2025

needs #917

Description

In this PR, I have added a new field to the InferenceService customProperties, which is the 'url' field.
This field is used to reconcile the url from the status of the cluster InferenceService, and update the url in the customProperties.
Also, I have also added new unit tests to test the new functionality.

Why a customProperty and not a first class field?

Because the url is part of the InferenceService status, and not the spec so it is ephemeral and should be treated as such in my opinion.

How Has This Been Tested?

make test

And also, I have created a mock controller that periodically updates the URL in the InferenceService status, and the URL in the customProperties is updated accordingly.

package controllers

import (
	"context"
	"fmt"
	"time"

	kservev1beta1 "github.com/kserve/kserve/pkg/apis/serving/v1beta1"
	"k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/runtime"
	"knative.dev/pkg/apis"
	ctrl "sigs.k8s.io/controller-runtime"
	"sigs.k8s.io/controller-runtime/pkg/client"
	"sigs.k8s.io/controller-runtime/pkg/log"
)

type InferenceServiceMockReconciler struct {
	client.Client
	Scheme *runtime.Scheme
}

// +kubebuilder:rbac:groups=serving.kserve.io,resources=inferenceservices,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=serving.kserve.io,resources=inferenceservices/status,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=serving.kserve.io,resources=inferenceservices/finalizers,verbs=get;list;watch;update;create;patch;delete
// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch

func (r *InferenceServiceMockReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	_ = log.FromContext(ctx)

	isvc := &kservev1beta1.InferenceService{}
	err := r.Get(ctx, req.NamespacedName, isvc)
	if err != nil {
		if errors.IsNotFound(err) {
			// Resource not found, nothing to do
			return ctrl.Result{}, nil
		}
		// Error fetching resource
		return ctrl.Result{}, err
	}

	// Update the status.url field
	newUrl, err := apis.ParseURL(fmt.Sprintf("https://example.com/%d", time.Now().Unix()))
	if err != nil {
		return ctrl.Result{}, err
	}

	isvc.Status.URL = newUrl
	err = r.Status().Update(ctx, isvc)
	if err != nil {
		return ctrl.Result{}, err
	}

	// Requeue the reconcile loop after 30 seconds
	return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
}

func (r *InferenceServiceMockReconciler) SetupWithManager(mgr ctrl.Manager) error {
	return ctrl.NewControllerManagedBy(mgr).
		For(&kservev1beta1.InferenceService{}).
		Named("mockinferenceservice").
		Complete(r)
}

Merge criteria:

  • All the commits have been signed-off (To pass the DCO check)
  • The commits have meaningful messages; the author will squash them after approval or in case of manual merges will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work.
  • Code changes follow the kubeflow contribution guidelines.
  • For first time contributors: Please reach out to the Reviewers to ensure all tests are being run, ensuring the label ok-to-test has been added to the PR.

Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>
Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>
@Al-Pragliola Al-Pragliola force-pushed the al-pragliola-inference-service-url branch from 99e8b4b to 636d409 Compare April 18, 2025 15:13
Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>
@Al-Pragliola Al-Pragliola marked this pull request as ready for review April 18, 2025 15:43
@google-oss-prow google-oss-prow Bot requested review from ckadner and zijianjoy April 18, 2025 15:43
@Al-Pragliola
Copy link
Copy Markdown
Contributor Author

/cc @pboyd

@google-oss-prow google-oss-prow Bot requested a review from pboyd April 18, 2025 15:44
Comment thread pkg/inferenceservice-controller/controller.go Outdated
}

if isvc.Status.URL != nil {
(*isCreate.CustomProperties)["url"].MetadataStringValue.StringValue = isvc.Status.URL.String()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to initialize CustomProperties before this, right? (I think you have the same situation as this, which panics).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need test cases for all combinations of url and customProperties set/unset, etc. in controller_test.go to verify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pboyd Good catch, it didn't happen in my tests because the .Status.URL always gets populated after the basic creation, so CustomProperties was empty but not nil

@dhirajsb thanks, I'll add more tests

}

if isvc.Status.URL != nil {
(*isCreate.CustomProperties)["url"].MetadataStringValue.StringValue = isvc.Status.URL.String()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need test cases for all combinations of url and customProperties set/unset, etc. in controller_test.go to verify.

handler := http.NewServeMux()

servingEnvironments := new(sync.Map)
inferenceServices := new(sync.Map)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I missed it, but it doesn't look like these sync maps are needed, does it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying them while debugging a weird bug in tests and I forgot to switch back to regular maps, good catch reverted in 5847b3c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, there is only one hardcoded id 1 being used. If so, does it even need a map?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for the time being, I'm going to keep it in case of more complex scenarios

@google-oss-prow
Copy link
Copy Markdown
Contributor

@dhirajsb: changing LGTM is restricted to collaborators

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Al-Pragliola and others added 3 commits April 28, 2025 14:59
Co-authored-by: Paul Boyd <paul@camelot.email>
Signed-off-by: Alessio Pragliola <83355398+Al-Pragliola@users.noreply.github.com>
Co-authored-by: Paul Boyd <paul@camelot.email>
Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>
Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>
Copy link
Copy Markdown
Member

@pboyd pboyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@google-oss-prow google-oss-prow Bot added the lgtm label Apr 28, 2025
Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>
@Al-Pragliola
Copy link
Copy Markdown
Contributor Author

added more tests @dhirajsb

Copy link
Copy Markdown
Contributor

@dhirajsb dhirajsb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@google-oss-prow
Copy link
Copy Markdown
Contributor

@dhirajsb: changing LGTM is restricted to collaborators

Details

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Al-Pragliola Al-Pragliola requested a review from pboyd May 5, 2025 15:04
Copy link
Copy Markdown
Member

@tarilabs tarilabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot @Al-Pragliola and all

/approve

@google-oss-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tarilabs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pboyd
Copy link
Copy Markdown
Member

pboyd commented May 5, 2025

/lgtm

@google-oss-prow google-oss-prow Bot added the lgtm label May 5, 2025
@google-oss-prow google-oss-prow Bot merged commit 8258979 into kubeflow:main May 5, 2025
15 checks passed
@Al-Pragliola Al-Pragliola deleted the al-pragliola-inference-service-url branch May 5, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants