Skip to content

Commit

Permalink
Add well-known label to InferenceGraphs (#463)
Browse files Browse the repository at this point in the history
Implementation of authentication for InferenceGraphs using Serverless mode will use ServiceMesh with Authorino (like InferenceServices case). For this, an Istio AuthorizationPolicy is applied mesh-wide. The AuthorizationPolicy uses a static label selector that is expected to be present on all Pods that require to be protected.

Currently, the InferenceGraph does not have a static label that can be used.

This PR is adding the `serving.kserve.io/kind: InferenceGraph` to pods that belong to InferenceGraph to properly protect them per user request.

Signed-off-by: Edgar Hernández <[email protected]>
  • Loading branch information
israel-hdez authored Jan 9, 2025
1 parent 7010e26 commit e2c9247
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ import (
)

// KServe Constants
var (
const (
KServeName = "kserve"
KServeAPIGroupName = "serving.kserve.io"
KnativeAutoscalingAPIGroupName = "autoscaling.knative.dev"
KnativeServingAPIGroupNamePrefix = "serving.knative"
KnativeServingAPIGroupName = KnativeServingAPIGroupNamePrefix + ".dev"
KServeNamespace = getEnvOrDefault("POD_NAMESPACE", "kserve")
KServeDefaultVersion = "v0.5.0"
)

var KServeNamespace = getEnvOrDefault("POD_NAMESPACE", "kserve")

// InferenceService Constants
var (
InferenceServiceName = "inferenceservice"
Expand Down Expand Up @@ -300,6 +300,7 @@ const (
KServiceComponentLabel = "component"
KServiceModelLabel = "model"
KServiceEndpointLabel = "endpoint"
KServeWorkloadKind = KServeAPIGroupName + "/kind"
)

// Labels for TrainedModel
Expand Down
10 changes: 7 additions & 3 deletions pkg/controller/v1alpha1/inferencegraph/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
"fmt"
"time"

"github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
"github.com/kserve/kserve/pkg/constants"
"github.com/kserve/kserve/pkg/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"google.golang.org/protobuf/proto"
Expand All @@ -36,6 +33,10 @@ import (
knservingv1 "knative.dev/serving/pkg/apis/serving/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
"github.com/kserve/kserve/pkg/constants"
"github.com/kserve/kserve/pkg/utils"
)

var _ = Describe("Inference Graph controller test", func() {
Expand Down Expand Up @@ -132,6 +133,7 @@ var _ = Describe("Inference Graph controller test", func() {
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"serving.kserve.io/inferencegraph": graphName,
constants.KServeWorkloadKind: "InferenceGraph",
},
Annotations: map[string]string{
"autoscaling.knative.dev/min-scale": "1",
Expand Down Expand Up @@ -290,6 +292,7 @@ var _ = Describe("Inference Graph controller test", func() {
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"serving.kserve.io/inferencegraph": graphName,
constants.KServeWorkloadKind: "InferenceGraph",
},
Annotations: map[string]string{
"autoscaling.knative.dev/min-scale": "1",
Expand Down Expand Up @@ -462,6 +465,7 @@ var _ = Describe("Inference Graph controller test", func() {
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"serving.kserve.io/inferencegraph": graphName,
constants.KServeWorkloadKind: "InferenceGraph",
},
Annotations: map[string]string{
"autoscaling.knative.dev/min-scale": "1",
Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/v1alpha1/inferencegraph/knative_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import (
"reflect"
"strings"

v1alpha1api "github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
"github.com/kserve/kserve/pkg/constants"
"github.com/kserve/kserve/pkg/utils"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
v1 "k8s.io/api/core/v1"
Expand All @@ -42,6 +39,10 @@ import (
knservingv1 "knative.dev/serving/pkg/apis/serving/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"

v1alpha1api "github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
"github.com/kserve/kserve/pkg/constants"
"github.com/kserve/kserve/pkg/utils"
)

var log = logf.Log.WithName("GraphKsvcReconciler")
Expand Down Expand Up @@ -169,6 +170,7 @@ func createKnativeService(componentMeta metav1.ObjectMeta, graph *v1alpha1api.In
return !utils.Includes(constants.RevisionTemplateLabelDisallowedList, key)
})
labels[constants.InferenceGraphLabel] = componentMeta.Name
labels[constants.KServeWorkloadKind] = "InferenceGraph"
service := &knservingv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: componentMeta.Name,
Expand Down

0 comments on commit e2c9247

Please sign in to comment.