forked from opendatahub-io/odh-model-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of ODH defaulters for InferenceGraph and InferenceService
On creation of InferenceGraph or InferenceService resources, the following default annotations will be added: * `serving.knative.openshift.io/enablePassthrough: true` * `sidecar.istio.io/inject: true` * `sidecar.istio.io/rewriteAppHTTPProbers: true` The annotations are added only for Serverless mode, and only if they are missing. Signed-off-by: Edgar Hernández <[email protected]>
- Loading branch information
1 parent
3a45bac
commit 2412463
Showing
17 changed files
with
601 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Containerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package serving | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/go-logr/logr" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/opendatahub-io/odh-model-controller/internal/controller/constants" | ||
"github.com/opendatahub-io/odh-model-controller/internal/controller/utils" | ||
) | ||
|
||
func ApplyDefaultServerlessAnnotations(ctx context.Context, client client.Client, resourceName string, resourceMetadata *v1.ObjectMeta, logger logr.Logger) error { | ||
deploymentMode, err := utils.GetDeploymentModeForKServeResource(ctx, client, resourceMetadata.GetAnnotations()) | ||
if err != nil { | ||
return fmt.Errorf("error resolving deployment mode for resource %s: %w", resourceName, err) | ||
} | ||
|
||
if deploymentMode == constants.Serverless { | ||
logAnnotationsAdded := make([]string, 0, 3) | ||
resourceAnnotations := resourceMetadata.GetAnnotations() | ||
if resourceAnnotations == nil { | ||
resourceAnnotations = make(map[string]string) | ||
} | ||
|
||
if _, exists := resourceAnnotations["serving.knative.openshift.io/enablePassthrough"]; !exists { | ||
resourceAnnotations["serving.knative.openshift.io/enablePassthrough"] = "true" | ||
logAnnotationsAdded = append(logAnnotationsAdded, "serving.knative.openshift.io/enablePassthrough") | ||
} | ||
|
||
if _, exists := resourceAnnotations["sidecar.istio.io/inject"]; !exists { | ||
resourceAnnotations["sidecar.istio.io/inject"] = "true" | ||
logAnnotationsAdded = append(logAnnotationsAdded, "sidecar.istio.io/inject") | ||
} | ||
|
||
if _, exists := resourceAnnotations["sidecar.istio.io/rewriteAppHTTPProbers"]; !exists { | ||
resourceAnnotations["sidecar.istio.io/rewriteAppHTTPProbers"] = "true" | ||
logAnnotationsAdded = append(logAnnotationsAdded, "sidecar.istio.io/rewriteAppHTTPProbers") | ||
} | ||
|
||
if len(logAnnotationsAdded) > 0 { | ||
logger.V(1).Info("Annotations added", "annotations", strings.Join(logAnnotationsAdded, ",")) | ||
} | ||
|
||
resourceMetadata.SetAnnotations(resourceAnnotations) | ||
} | ||
return nil | ||
} |
73 changes: 73 additions & 0 deletions
73
internal/webhook/serving/v1alpha1/inferencegraph_webhook.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright 2024. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
servingv1alpha1 "github.com/kserve/kserve/pkg/apis/serving/v1alpha1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
|
||
"github.com/opendatahub-io/odh-model-controller/internal/webhook/serving" | ||
) | ||
|
||
// nolint:unused | ||
// log is for logging in this package. | ||
var inferencegraphlog = logf.Log.WithName("inferencegraph-resource") | ||
|
||
// SetupInferenceGraphWebhookWithManager registers the webhook for InferenceGraph in the manager. | ||
func SetupInferenceGraphWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr).For(&servingv1alpha1.InferenceGraph{}). | ||
WithDefaulter(&InferenceGraphCustomDefaulter{client: mgr.GetClient()}). | ||
Complete() | ||
} | ||
|
||
// +kubebuilder:webhook:path=/mutate-serving-kserve-io-v1alpha1-inferencegraph,mutating=true,failurePolicy=fail,sideEffects=None,groups=serving.kserve.io,resources=inferencegraphs,verbs=create,versions=v1alpha1,name=minferencegraph-v1alpha1.kb.io,admissionReviewVersions=v1 | ||
|
||
// InferenceGraphCustomDefaulter struct is responsible for setting default values on the custom resource of the | ||
// Kind InferenceGraph when those are created or updated. | ||
// | ||
// NOTE: The +kubebuilder:object:generate=false marker prevents controller-gen from generating DeepCopy methods, | ||
// as it is used only for temporary operations and does not need to be deeply copied. | ||
type InferenceGraphCustomDefaulter struct { | ||
client client.Client | ||
} | ||
|
||
var _ webhook.CustomDefaulter = &InferenceGraphCustomDefaulter{} | ||
|
||
// Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind InferenceGraph. | ||
func (d *InferenceGraphCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { | ||
inferencegraph, ok := obj.(*servingv1alpha1.InferenceGraph) | ||
|
||
if !ok { | ||
return fmt.Errorf("expected an InferenceGraph object but got %T", obj) | ||
} | ||
logger := inferencegraphlog.WithValues("name", inferencegraph.GetName()) | ||
logger.Info("Defaulting for InferenceGraph") | ||
|
||
err := serving.ApplyDefaultServerlessAnnotations(ctx, d.client, inferencegraph.GetName(), &inferencegraph.ObjectMeta, logger) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.