From 9ed325bcefb4ae780d833773a92dbc3d795b248a Mon Sep 17 00:00:00 2001 From: Vedant Mahabaleshwarkar Date: Thu, 12 Sep 2024 15:12:15 -0400 Subject: [PATCH 1/2] add ability to choose ingress creation for Kserve RawDeployment and set cluster domain Signed-off-by: Vedant Mahabaleshwarkar --- ...er.opendatahub.io_datascienceclusters.yaml | 11 ++++ components/kserve/kserve.go | 6 +++ components/kserve/kserve_config_handler.go | 52 +++++++++++-------- ...er.opendatahub.io_datascienceclusters.yaml | 11 ++++ docs/api-overview.md | 1 + 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/bundle/manifests/datasciencecluster.opendatahub.io_datascienceclusters.yaml b/bundle/manifests/datasciencecluster.opendatahub.io_datascienceclusters.yaml index 761d550a5dc..58f13c26a34 100644 --- a/bundle/manifests/datasciencecluster.opendatahub.io_datascienceclusters.yaml +++ b/bundle/manifests/datasciencecluster.opendatahub.io_datascienceclusters.yaml @@ -245,6 +245,17 @@ spec: - Removed pattern: ^(Managed|Unmanaged|Force|Removed)$ type: string + rawRouteCreation: + description: |- + Configures the global setting for route creation for Kserve Raw InferenceServices. + Managed: Route creation is enabled by default, InferenceServices will have to choose to opt out. + Removed: Route creation is disabled globally. In this configuration it is not possible for an individual + InferenceService to opt in to having a Route created automatically. + enum: + - Managed + - Removed + pattern: ^(Managed|Unmanaged|Force|Removed)$ + type: string serving: description: |- Serving configures the KNative-Serving stack used for model serving. A Service diff --git a/components/kserve/kserve.go b/components/kserve/kserve.go index fe2eb2a994d..04888f7a750 100644 --- a/components/kserve/kserve.go +++ b/components/kserve/kserve.go @@ -54,6 +54,12 @@ type Kserve struct { // This field is optional. If no default deployment mode is specified, Kserve will use Serverless mode. // +kubebuilder:validation:Enum=Serverless;RawDeployment DefaultDeploymentMode DefaultDeploymentMode `json:"defaultDeploymentMode,omitempty"` + // Configures the global setting for route creation for Kserve Raw InferenceServices. + // Managed: Route creation is enabled by default, InferenceServices will have to choose to opt out. + // Removed: Route creation is disabled globally. In this configuration it is not possible for an individual + // InferenceService to opt in to having a Route created automatically. + // +kubebuilder:validation:Enum=Managed;Removed + RawRouteCreation operatorv1.ManagementState `json:"rawRouteCreation,omitempty"` } func (k *Kserve) OverrideManifests(ctx context.Context, _ cluster.Platform) error { diff --git a/components/kserve/kserve_config_handler.go b/components/kserve/kserve_config_handler.go index 46df279e753..5ce85ab0eb8 100644 --- a/components/kserve/kserve_config_handler.go +++ b/components/kserve/kserve_config_handler.go @@ -25,18 +25,23 @@ const ( func (k *Kserve) setupKserveConfig(ctx context.Context, cli client.Client, logger logr.Logger, dscispec *dsciv1.DSCInitializationSpec) error { // as long as Kserve.Serving is not 'Removed', we will setup the dependencies + var disableIngressCreation bool + defaultDeploymentMode := k.DefaultDeploymentMode + if defaultDeploymentMode == "" { + defaultDeploymentMode = Serverless + } + switch k.RawRouteCreation { + case operatorv1.Removed, "": + disableIngressCreation = true + case operatorv1.Managed: + disableIngressCreation = false + default: + disableIngressCreation = true + } switch k.Serving.ManagementState { case operatorv1.Managed, operatorv1.Unmanaged: - if k.DefaultDeploymentMode == "" { - // if the default mode is empty in the DSC, assume mode is "Serverless" since k.Serving is Managed - if err := k.setDefaultDeploymentMode(ctx, cli, dscispec, Serverless); err != nil { - return err - } - } else { - // if the default mode is explicitly specified, respect that - if err := k.setDefaultDeploymentMode(ctx, cli, dscispec, k.DefaultDeploymentMode); err != nil { - return err - } + if err := k.setKserveRawConfig(ctx, cli, dscispec, defaultDeploymentMode, disableIngressCreation); err != nil { + return err } case operatorv1.Removed: if k.DefaultDeploymentMode == Serverless { @@ -45,14 +50,16 @@ func (k *Kserve) setupKserveConfig(ctx context.Context, cli client.Client, logge if k.DefaultDeploymentMode == "" { logger.Info("Serving is removed, Kserve will default to rawdeployment") } - if err := k.setDefaultDeploymentMode(ctx, cli, dscispec, RawDeployment); err != nil { + if err := k.setKserveRawConfig(ctx, cli, dscispec, RawDeployment, disableIngressCreation); err != nil { return err } } return nil } -func (k *Kserve) setDefaultDeploymentMode(ctx context.Context, cli client.Client, dscispec *dsciv1.DSCInitializationSpec, defaultmode DefaultDeploymentMode) error { +func (k *Kserve) setKserveRawConfig( + ctx context.Context, cli client.Client, dscispec *dsciv1.DSCInitializationSpec, + defaultmode DefaultDeploymentMode, disableIngressCreation bool) error { inferenceServiceConfigMap := &corev1.ConfigMap{} err := cli.Get(ctx, client.ObjectKey{ Namespace: dscispec.ApplicationsNamespace, @@ -67,24 +74,25 @@ func (k *Kserve) setDefaultDeploymentMode(ctx context.Context, cli client.Client if err = json.Unmarshal([]byte(inferenceServiceConfigMap.Data["deploy"]), &deployData); err != nil { return fmt.Errorf("error retrieving value for key 'deploy' from configmap %s. %w", KserveConfigMapName, err) } + var ingressData map[string]interface{} + if err = json.Unmarshal([]byte(inferenceServiceConfigMap.Data["ingress"]), &ingressData); err != nil { + return fmt.Errorf("error retrieving value for key 'ingress' from configmap %s. %w", KserveConfigMapName, err) + } modeFound := deployData["defaultDeploymentMode"] - if modeFound != string(defaultmode) { + ingressCreationValueFound := ingressData["disableIngressCreation"] + if (modeFound != string(defaultmode)) || ingressCreationValueFound != disableIngressCreation { deployData["defaultDeploymentMode"] = defaultmode deployDataBytes, err := json.MarshalIndent(deployData, "", " ") if err != nil { return fmt.Errorf("could not set values in configmap %s. %w", KserveConfigMapName, err) } inferenceServiceConfigMap.Data["deploy"] = string(deployDataBytes) - - var ingressData map[string]interface{} - if err = json.Unmarshal([]byte(inferenceServiceConfigMap.Data["ingress"]), &ingressData); err != nil { - return fmt.Errorf("error retrieving value for key 'ingress' from configmap %s. %w", KserveConfigMapName, err) - } - if defaultmode == RawDeployment { - ingressData["disableIngressCreation"] = true - } else { - ingressData["disableIngressCreation"] = false + clusterDomain, err := cluster.GetDomain(ctx, cli) + if err != nil { + return fmt.Errorf("error retrieving cluster domain %s. %w", KserveConfigMapName, err) } + ingressData["ingressDomain"] = clusterDomain + ingressData["disableIngressCreation"] = disableIngressCreation ingressDataBytes, err := json.MarshalIndent(ingressData, "", " ") if err != nil { return fmt.Errorf("could not set values in configmap %s. %w", KserveConfigMapName, err) diff --git a/config/crd/bases/datasciencecluster.opendatahub.io_datascienceclusters.yaml b/config/crd/bases/datasciencecluster.opendatahub.io_datascienceclusters.yaml index 327c95af25a..8afce6a175f 100644 --- a/config/crd/bases/datasciencecluster.opendatahub.io_datascienceclusters.yaml +++ b/config/crd/bases/datasciencecluster.opendatahub.io_datascienceclusters.yaml @@ -245,6 +245,17 @@ spec: - Removed pattern: ^(Managed|Unmanaged|Force|Removed)$ type: string + rawRouteCreation: + description: |- + Configures the global setting for route creation for Kserve Raw InferenceServices. + Managed: Route creation is enabled by default, InferenceServices will have to choose to opt out. + Removed: Route creation is disabled globally. In this configuration it is not possible for an individual + InferenceService to opt in to having a Route created automatically. + enum: + - Managed + - Removed + pattern: ^(Managed|Unmanaged|Force|Removed)$ + type: string serving: description: |- Serving configures the KNative-Serving stack used for model serving. A Service diff --git a/docs/api-overview.md b/docs/api-overview.md index c909cee2b11..b94a5ced163 100644 --- a/docs/api-overview.md +++ b/docs/api-overview.md @@ -183,6 +183,7 @@ _Appears in:_ | `Component` _[Component](#component)_ | | | | | `serving` _[ServingSpec](#servingspec)_ | Serving configures the KNative-Serving stack used for model serving. A Service
Mesh (Istio) is prerequisite, since it is used as networking layer. | | | | `defaultDeploymentMode` _[DefaultDeploymentMode](#defaultdeploymentmode)_ | Configures the default deployment mode for Kserve. This can be set to 'Serverless' or 'RawDeployment'.
The value specified in this field will be used to set the default deployment mode in the 'inferenceservice-config' configmap for Kserve.
This field is optional. If no default deployment mode is specified, Kserve will use Serverless mode. | | Enum: [Serverless RawDeployment]
Pattern: `^(Serverless\|RawDeployment)$`
| +| `rawRouteCreation` _[ManagementState](#managementstate)_ | Configures the global setting for route creation for Kserve Raw InferenceServices.
Managed: Route creation is enabled by default, InferenceServices will have to choose to opt out.
Removed: Route creation is disabled globally. In this configuration it is not possible for an individual
InferenceService to opt in to having a Route created automatically. | | Enum: [Managed Removed]
| From 79a01054d946f4e7af66912525cc456f8b38a348 Mon Sep 17 00:00:00 2001 From: Vedant Mahabaleshwarkar Date: Fri, 11 Oct 2024 16:00:28 -0400 Subject: [PATCH 2/2] pr feedback Signed-off-by: Vedant Mahabaleshwarkar --- components/kserve/kserve_config_handler.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/components/kserve/kserve_config_handler.go b/components/kserve/kserve_config_handler.go index 5ce85ab0eb8..30fb14bc631 100644 --- a/components/kserve/kserve_config_handler.go +++ b/components/kserve/kserve_config_handler.go @@ -25,18 +25,13 @@ const ( func (k *Kserve) setupKserveConfig(ctx context.Context, cli client.Client, logger logr.Logger, dscispec *dsciv1.DSCInitializationSpec) error { // as long as Kserve.Serving is not 'Removed', we will setup the dependencies - var disableIngressCreation bool defaultDeploymentMode := k.DefaultDeploymentMode if defaultDeploymentMode == "" { defaultDeploymentMode = Serverless } - switch k.RawRouteCreation { - case operatorv1.Removed, "": - disableIngressCreation = true - case operatorv1.Managed: + disableIngressCreation := true + if k.RawRouteCreation == operatorv1.Managed { disableIngressCreation = false - default: - disableIngressCreation = true } switch k.Serving.ManagementState { case operatorv1.Managed, operatorv1.Unmanaged: