Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RHOAIENG-4191] - odh-model-controller should tolerate missing Authorino #177

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ rules:
- patch
- update
- watch
- apiGroups:
- datasciencecluster.opendatahub.io
resources:
- datascienceclusters
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
Expand Down
19 changes: 16 additions & 3 deletions controllers/inferenceservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package controllers

import (
"context"

"github.com/go-logr/logr"
kservev1alpha1 "github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
kservev1beta1 "github.com/kserve/kserve/pkg/apis/serving/v1beta1"
Expand Down Expand Up @@ -122,7 +121,6 @@ func (r *OpenshiftInferenceServiceReconciler) SetupWithManager(mgr ctrl.Manager)
Owns(&networkingv1.NetworkPolicy{}).
Owns(&monitoringv1.ServiceMonitor{}).
Owns(&monitoringv1.PodMonitor{}).
Owns(&authorinov1beta2.AuthConfig{}).
Watches(&source.Kind{Type: &kservev1alpha1.ServingRuntime{}},
handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {
r.log.Info("Reconcile event triggered by serving runtime: " + o.GetName())
Expand Down Expand Up @@ -152,7 +150,22 @@ func (r *OpenshiftInferenceServiceReconciler) SetupWithManager(mgr ctrl.Manager)
}
return reconcileRequests
}))
err := builder.Complete(r)

// check if kserve is enabled, otherwise don't require Authorino.
spolti marked this conversation as resolved.
Show resolved Hide resolved
enabled, err := utils.VerifyIfComponentIsEnabled(context.TODO(), r.client, "kserve")
if err != nil {
r.log.V(1).Error(err, "could not determine if kserve is enabled, default is enabled")
enabled = true
}

if enabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

Almost! More feedback:
The DSC can be:

apiVersion: datasciencecluster.opendatahub.io/v1
kind: DataScienceCluster
metadata:
  name: default-dsc
spec:
  components:
    kserve: 
      managementState: "Removed",
      serving: 
        ingressGateway: 
          certificate: 
            type: SelfSigned
        name: "knative-serving",
        managementState: "Managed"

Notice kserve.managementState is Removed while serving.managementState is Managed. If KServe is removed, I think odh-model-controller don't need to care about authorino.

So, turns out we would need to check kserve.managementState == Managed && serving.managementState != Removed, to require authorino here.

I think I'm bad at explaining stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

both enabled, right.

okay.

builder.Owns(&authorinov1beta2.AuthConfig{})
r.log.Info("kserve component is enabled, Authorino is required")
} else {
r.log.Info("kserve component is disabled, ignoring Authorino requirement")
}

err = builder.Complete(r)
if err != nil {
return err
}
Expand Down
28 changes: 28 additions & 0 deletions controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"os"
"reflect"

Expand All @@ -23,6 +24,8 @@ var (
const (
inferenceServiceDeploymentModeAnnotation = "serving.kserve.io/deploymentMode"
KserveConfigMapName = "inferenceservice-config"
dataScienceClusterKind = "DataScienceCluster"
dataScienceClusterApiVersion = "datasciencecluster.opendatahub.io/v1"
)

func GetDeploymentModeForIsvc(ctx context.Context, cli client.Client, isvc *kservev1beta1.InferenceService) (IsvcDeploymentMode, error) {
Expand Down Expand Up @@ -69,6 +72,31 @@ func GetDeploymentModeForIsvc(ctx context.Context, cli client.Client, isvc *kser
}
}

// VerifyIfComponentIsEnabled will query the DCS in the cluster and see if the desired componentName is enabled
func VerifyIfComponentIsEnabled(ctx context.Context, cli client.Client, componentName string) (bool, error) {
// Query the custom object
objectList := &unstructured.UnstructuredList{}
objectList.SetAPIVersion(dataScienceClusterApiVersion)
objectList.SetKind(dataScienceClusterKind)

if err := cli.List(ctx, objectList); err != nil {
return false, fmt.Errorf("not able to read %s: %w", objectList, err)
}

// there must be only one dsc
if len(objectList.Items) == 1 {
fields := []string{"spec", "components", componentName, "managementState"}
val, _, err := unstructured.NestedString(objectList.Items[0].Object, fields...)
if err != nil {
return false, fmt.Errorf("failed to retrieve the component [%s] status from %+v",
componentName, objectList.Items[0])
}
return val == "Managed", nil
} else {
return false, fmt.Errorf("there is no %s available in the cluster", dataScienceClusterKind)
}
}

func IsNil(i any) bool {
return reflect.ValueOf(i).IsNil()
}
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func init() { //nolint:gochecknoinits //reason this way we ensure schemes are al
// +kubebuilder:rbac:groups="",resources=namespaces;pods;services;endpoints,verbs=get;list;watch;create;update;patch
// +kubebuilder:rbac:groups="",resources=secrets;configmaps;serviceaccounts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=authorino.kuadrant.io,resources=authconfigs,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=datasciencecluster.opendatahub.io,resources=datascienceclusters,verbs=get;list;watch

func getEnvAsBool(name string, defaultValue bool) bool {
valStr := os.Getenv(name)
Expand Down