Skip to content

Commit

Permalink
feat: ConfigMap key to disable KServe Serverless configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ruivieira committed Jul 31, 2024
1 parent ec4462e commit 7fe87c3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
7 changes: 7 additions & 0 deletions config/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ vars:
apiVersion: v1
fieldref:
fieldpath: data.oauthProxyImage
- name: kServeServerless
objref:
kind: ConfigMap
name: config
apiVersion: v1
fieldref:
fieldpath: data.kServeServerless
1 change: 1 addition & 0 deletions config/base/params.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
trustyaiServiceImage=quay.io/trustyai/trustyai-service:latest
trustyaiOperatorImage=quay.io/trustyai/trustyai-service-operator:latest
oauthProxyImage=quay.io/openshift/origin-oauth-proxy:4.14.0
kServeServerless=disabled
38 changes: 38 additions & 0 deletions controllers/config_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,44 @@ func (r *TrustyAIServiceReconciler) getImageFromConfigMap(ctx context.Context, k
}
}

// getKServeServerlessConfig checks the kServeServerless value in a ConfigMap in the operator's namespace
func (r *TrustyAIServiceReconciler) getKServeServerlessConfig(ctx context.Context) (bool, error) {

if r.Namespace != "" {
// Define the key for the ConfigMap
configMapKey := types.NamespacedName{
Namespace: r.Namespace,
Name: imageConfigMap,
}

// Create an empty ConfigMap object
var cm corev1.ConfigMap

// Try to get the ConfigMap
if err := r.Get(ctx, configMapKey, &cm); err != nil {
if errors.IsNotFound(err) {
// ConfigMap not found, return false as the default behavior
return false, nil
}
// Other error occurred when trying to fetch the ConfigMap
return false, fmt.Errorf("error reading configmap %s", configMapKey)
}

// ConfigMap is found, extract the kServeServerless value
kServeServerless, ok := cm.Data[configMapkServeServerlessKey]

if !ok || kServeServerless != "enabled" {
// Key is missing or its value is not "enabled", return false
return false, nil
}

// kServeServerless is "enabled"
return true, nil
} else {
return false, nil
}
}

// getConfigMapNamesWithLabel retrieves the names of ConfigMaps that have the specified label
func (r *TrustyAIServiceReconciler) getConfigMapNamesWithLabel(ctx context.Context, namespace string, labelSelector client.MatchingLabels) ([]string, error) {
configMapList := &corev1.ConfigMapList{}
Expand Down
7 changes: 4 additions & 3 deletions controllers/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ const (

// Configuration constants
const (
imageConfigMap = "trustyai-service-operator-config"
configMapOAuthProxyImageKey = "oauthProxyImage"
configMapServiceImageKey = "trustyaiServiceImage"
imageConfigMap = "trustyai-service-operator-config"
configMapOAuthProxyImageKey = "oauthProxyImage"
configMapServiceImageKey = "trustyaiServiceImage"
configMapkServeServerlessKey = "kServeServerless"
)

// OAuth constants
Expand Down
16 changes: 12 additions & 4 deletions controllers/inference_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ func (r *TrustyAIServiceReconciler) handleInferenceServices(ctx context.Context,
return false, err
}

kServeServerlessEnabled, err := r.getKServeServerlessConfig(ctx)
if err != nil {
log.FromContext(ctx).Error(err, "Could not read KServeServerless configuration. Defaulting to disabled")
kServeServerlessEnabled = false
}

if len(inferenceServices.Items) == 0 {
return true, nil
}
Expand All @@ -220,10 +226,12 @@ func (r *TrustyAIServiceReconciler) handleInferenceServices(ctx context.Context,
continue
}
}
err := r.patchKServe(ctx, instance, infService, namespace, crName, remove)
if err != nil {
log.FromContext(ctx).Error(err, "could not patch InferenceLogger for KServe deployment")
return false, err
if kServeServerlessEnabled {
err := r.patchKServe(ctx, instance, infService, namespace, crName, remove)
if err != nil {
log.FromContext(ctx).Error(err, "could not patch InferenceLogger for KServe deployment")
return false, err
}
}
}
return true, nil
Expand Down

0 comments on commit 7fe87c3

Please sign in to comment.