Skip to content

Commit

Permalink
add ability to choose ingress creation for Kserve RawDeployment and s…
Browse files Browse the repository at this point in the history
…et cluster domain

Signed-off-by: Vedant Mahabaleshwarkar <vmahabal@redhat.com>
  • Loading branch information
VedantMahabaleshwarkar committed Oct 9, 2024
1 parent 294cc1e commit 0f1a36c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
2 changes: 2 additions & 0 deletions components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ 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"`
// +kubebuilder:validation:Type:bool
DisableIngressCreation bool `json:"disableIngressCreation,omitempty"`
}

func (k *Kserve) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
Expand Down
51 changes: 29 additions & 22 deletions components/kserve/kserve_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ 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 defaultDeploymentMode DefaultDeploymentMode
var disableIngressCreation bool
if k.DefaultDeploymentMode == "" {
defaultDeploymentMode = Serverless
} else {
defaultDeploymentMode = k.DefaultDeploymentMode
}
if !k.DisableIngressCreation {
disableIngressCreation = true
} else {
disableIngressCreation = k.DisableIngressCreation
}
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 {
Expand All @@ -45,14 +49,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,
Expand All @@ -67,24 +73,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)
Expand Down

0 comments on commit 0f1a36c

Please sign in to comment.