-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add KServe destination rule for Inference Services in the ServiceMesh (…
…trustyai-explainability#315) * Add DestinationRule creation for KServe serverless * Add permissions for destination rules * Add role for destination rules * Add missing role for creating destination rules * Fix spacing in DestinationRule template
- Loading branch information
Showing
6 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
trustyaiServiceImage=quay.io/trustyai/trustyai-service:v0.19.0 | ||
trustyaiOperatorImage=quay.io/trustyai/trustyai-service-operator:v1.25.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"reflect" | ||
|
||
trustyaiopendatahubiov1alpha1 "github.com/trustyai-explainability/trustyai-service-operator/api/v1alpha1" | ||
templateParser "github.com/trustyai-explainability/trustyai-service-operator/controllers/templates" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/types" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
const ( | ||
destinationRuleTemplatePath = "service/destination-rule.tmpl.yaml" | ||
) | ||
|
||
// DestinationRuleConfig has the variables for the DestinationRule template | ||
type DestinationRuleConfig struct { | ||
Name string | ||
Namespace string | ||
DestinationRuleName string | ||
} | ||
|
||
func (r *TrustyAIServiceReconciler) ensureDestinationRule(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService) error { | ||
destinationRuleName := instance.Name + "-internal" | ||
|
||
existingDestinationRule := &unstructured.Unstructured{} | ||
existingDestinationRule.SetKind("DestinationRule") | ||
existingDestinationRule.SetAPIVersion("networking.istio.io/v1beta1") | ||
|
||
// Check if the DestinationRule already exists | ||
err := r.Get(ctx, types.NamespacedName{Name: destinationRuleName, Namespace: instance.Namespace}, existingDestinationRule) | ||
if err == nil { | ||
// DestinationRule exists | ||
return nil | ||
} | ||
|
||
if !errors.IsNotFound(err) { | ||
return fmt.Errorf("failed to check for existing DestinationRule: %v", err) | ||
} | ||
|
||
destinationRuleConfig := DestinationRuleConfig{ | ||
Name: instance.Name, | ||
Namespace: instance.Namespace, | ||
DestinationRuleName: destinationRuleName, | ||
} | ||
|
||
var destinationRule *unstructured.Unstructured | ||
destinationRule, err = templateParser.ParseResource[unstructured.Unstructured](destinationRuleTemplatePath, destinationRuleConfig, reflect.TypeOf(&unstructured.Unstructured{})) | ||
if err != nil { | ||
log.FromContext(ctx).Error(err, "could not parse the DestinationRule template") | ||
return err | ||
} | ||
|
||
if err := ctrl.SetControllerReference(instance, destinationRule, r.Scheme); err != nil { | ||
return err | ||
} | ||
|
||
err = r.Create(ctx, destinationRule) | ||
if err != nil { | ||
return fmt.Errorf("failed to create DestinationRule: %v", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: networking.istio.io/v1beta1 | ||
kind: DestinationRule | ||
metadata: | ||
name: {{ .DestinationRuleName }} | ||
namespace: {{ .Namespace }} | ||
spec: | ||
host: {{ .Name }}.{{ .Namespace }}.svc.cluster.local | ||
trafficPolicy: | ||
portLevelSettings: | ||
- port: | ||
number: 443 | ||
tls: | ||
mode: SIMPLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters