Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

chore: Fix nginx rewrite path error when create deployment via BYOC #188

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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: 5 additions & 3 deletions agent/pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package consts
import "time"

const (
LabelBuildName = "ai.tensorchord.build"
LabelName = "ai.tensorchord.name"
LabelServerResource = "ai.tensorchord.server-resource"
LabelBuildName = "ai.tensorchord.build"
LabelName = "ai.tensorchord.name"
LabelServerResource = "ai.tensorchord.server-resource"
AnnotationControlPlaneKey = "ai.tensorchord.control-plane"
ModelzAnnotationValue = "modelz"

Domain = "modelz.live"
DefaultPrefix = "modelz-"
Expand Down
6 changes: 6 additions & 0 deletions agent/pkg/runtime/inference_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,11 @@ func makeIngress(request types.InferenceDeployment, cfg config.IngressConfig) (*
},
}

annotation := map[string]string{}
if value, exist := request.Spec.Annotations[localconsts.AnnotationControlPlaneKey]; exist {
annotation[localconsts.AnnotationControlPlaneKey] = value
}
ingress.Annotations = annotation

return ingress, nil
}
6 changes: 4 additions & 2 deletions ingress-operator/pkg/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package consts

const (
KeyCert = "cert"
EnvironmentPrefix = "MODELZ"
KeyCert = "cert"
EnvironmentPrefix = "MODELZ"
AnnotationControlPlaneKey = "ai.tensorchord.control-plane"
ModelzAnnotationValue = "modelz"
)
21 changes: 15 additions & 6 deletions ingress-operator/pkg/controller/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
faasscheme "github.com/tensorchord/openmodelz/ingress-operator/pkg/client/clientset/versioned/scheme"
v1 "github.com/tensorchord/openmodelz/ingress-operator/pkg/client/informers/externalversions/modelzetes/v1"
listers "github.com/tensorchord/openmodelz/ingress-operator/pkg/client/listers/modelzetes/v1"
"github.com/tensorchord/openmodelz/modelzetes/pkg/consts"
"github.com/tensorchord/openmodelz/ingress-operator/pkg/consts"
mdzconsts "github.com/tensorchord/openmodelz/modelzetes/pkg/consts"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -250,12 +251,13 @@ func GetIssuerKind(issuerType string) string {
}

func MakeAnnotations(fni *faasv1.InferenceIngress, host string) map[string]string {
controlPlane, exist := fni.Annotations[consts.AnnotationControlPlaneKey]
class := GetClass(fni.Spec.IngressType)
specJSON, _ := json.Marshal(fni)
annotations := make(map[string]string)

annotations["ai.tensorchord.spec"] = string(specJSON)
inferenceNamespace := fni.Labels[consts.LabelInferenceNamespace]
inferenceNamespace := fni.Labels[mdzconsts.LabelInferenceNamespace]

if !fni.Spec.BypassGateway {
switch class {
Expand All @@ -267,11 +269,18 @@ func MakeAnnotations(fni *faasv1.InferenceIngress, host string) map[string]strin
"/" + fni.Spec.Function + "/$1"
annotations["nginx.ingress.kubernetes.io/use-regex"] = "true"
default:
annotations["nginx.ingress.kubernetes.io/rewrite-target"] = "/inference/" + fni.Name + "." + inferenceNamespace + "/$1"
annotations["nginx.ingress.kubernetes.io/ssl-redirect"] = "false"
annotations["nginx.ingress.kubernetes.io/use-regex"] = "true"
// for inference created by modelz apiserver
Copy link
Member

@cutecutecat cutecutecat Oct 10, 2023

Choose a reason for hiding this comment

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

Is this designed for BYOC created inference when INGRESS_OPERATOR_SERVICE_HOST might be not be apiserver?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you set INGRESS_OPERATOR_SERVICE_HOST be apiserver, you can not use mdz create inference in local environment.

if exist && controlPlane == consts.ModelzAnnotationValue {
annotations["nginx.ingress.kubernetes.io/rewrite-target"] = "/api/v1/" + fni.Spec.Framework +
"/" + fni.Spec.Function + "/$1"
annotations["nginx.ingress.kubernetes.io/use-regex"] = "true"
annotations["nginx.ingress.kubernetes.io/ssl-redirect"] = "false"
} else {
annotations["nginx.ingress.kubernetes.io/rewrite-target"] = "/inference/" + fni.Name + "." + inferenceNamespace + "/$1"
annotations["nginx.ingress.kubernetes.io/ssl-redirect"] = "false"
annotations["nginx.ingress.kubernetes.io/use-regex"] = "true"
}
}

}
}

Expand Down
Loading