Skip to content

Commit

Permalink
feat: Add TLS ConfigMap parameter
Browse files Browse the repository at this point in the history
Update ODH and RHOAI overlays
  • Loading branch information
ruivieira committed Aug 2, 2024
1 parent 91ba2c5 commit e0e0c7f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 5 deletions.
9 changes: 8 additions & 1 deletion config/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ vars:
name: config
apiVersion: v1
fieldref:
fieldpath: data.kServeServerless
fieldpath: data.kServeServerless
- name: tls
objref:
kind: ConfigMap
name: config
apiVersion: v1
fieldref:
fieldpath: data.tls
3 changes: 2 additions & 1 deletion config/base/params.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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
kServeServerless=disabled
tls=enabled
6 changes: 4 additions & 2 deletions config/overlays/odh/params.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
trustyaiServiceImage=quay.io/trustyai/trustyai-service:v0.13.0
trustyaiOperatorImage=quay.io/trustyai/trustyai-service-operator:v1.19.0
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=enabled
tls=disabled
4 changes: 4 additions & 0 deletions config/overlays/rhoai/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
configMapGenerator:
- env: params.env
behavior: merge
name: config
5 changes: 5 additions & 0 deletions config/overlays/rhoai/params.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trustyaiServiceImage=quay.io/trustyai/trustyai-service:latest
trustyaiOperatorImage=quay.io/trustyai/trustyai-service-operator:latest
oauthProxyImage=registry.redhat.io/openshift4/ose-oauth-proxy@sha256:ab112105ac37352a2a4916a39d6736f5db6ab4c29bad4467de8d613e80e9bb33
kServeServerless=disabled
tls=enabled
38 changes: 38 additions & 0 deletions controllers/config_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,44 @@ func (r *TrustyAIServiceReconciler) getKServeServerlessConfig(ctx context.Contex
}
}

// getTLSConfig checks the tls value in a ConfigMap in the operator's namespace
func (r *TrustyAIServiceReconciler) getTLSConfig(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 tls value
tls, ok := cm.Data[configMapTLSKey]

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

// tls 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
1 change: 1 addition & 0 deletions controllers/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
configMapOAuthProxyImageKey = "oauthProxyImage"
configMapServiceImageKey = "trustyaiServiceImage"
configMapkServeServerlessKey = "kServeServerless"
configMapTLSKey = "tls"
)

// OAuth constants
Expand Down
13 changes: 12 additions & 1 deletion controllers/inference_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,19 @@ func (r *TrustyAIServiceReconciler) patchEnvVarsByLabelForDeployments(ctx contex
return false, err
}

tlsEnabled, err := r.getTLSConfig(ctx)
if err != nil {
log.FromContext(ctx).Error(err, "Could not read TLS configuration. Defaulting to enabled")
tlsEnabled = true
}

// Build the payload processor endpoint
url := generateTLSServiceURL(crName, namespace) + "/consumer/kserve/v2"
var url string
if tlsEnabled {
url = generateTLSServiceURL(crName, namespace) + "/consumer/kserve/v2"
} else {
url = generateNonTLSServiceURL(crName, namespace) + "/consumer/kserve/v2"
}

// Patch environment variables for the Deployments
if shouldContinue, err := r.patchEnvVarsForDeployments(ctx, instance, deployments, envVarName, url, remove); err != nil {
Expand Down

0 comments on commit e0e0c7f

Please sign in to comment.