Skip to content

Commit

Permalink
Enabled the multiple domains support on an inference service (kserve#…
Browse files Browse the repository at this point in the history
…3615)

* Added the field AdditionalIngressDomains into the struct IngressConfig

Signed-off-by: Vincent Hou <[email protected]>

* Added the additional ingress domains into the hosts

Signed-off-by: Vincent Hou <[email protected]>

* Fixed the indentation

Signed-off-by: Vincent Hou <[email protected]>

* Added isvc name and namespace into the domain name

* Added the validation for the URLs

Signed-off-by: Vincent Hou <[email protected]>

* Validate the domain in the additionalIngressDomains

Signed-off-by: Vincent Hou <[email protected]>

* Create the hosts from the list of additionalIngressDomains

Signed-off-by: Vincent Hou <[email protected]>

* Change the way to validate the host

Signed-off-by: Vincent Hou <[email protected]>

* Change the validation error message

Signed-off-by: Vincent Hou <[email protected]>

* Revert the name to url

Signed-off-by: Vincent Hou <[email protected]>

* Get all the available domain list

Signed-off-by: Vincent Hou <[email protected]>

* gofmt -s -w the file

Signed-off-by: Vincent Hou <[email protected]>

* Add additionalIngressDomains into the charts

Signed-off-by: Vincent Hou <[email protected]>

* Added the comments and refactor the tests

Signed-off-by: Vincent Hou <[email protected]>

* Regenerate the manifests

Signed-off-by: Vincent Hou <[email protected]>

* Modify createHTTPMatchRequest, the charts and the test cases

Signed-off-by: Vincent Hou <[email protected]>

* Run make generate

Signed-off-by: Vincent Hou <[email protected]>

---------

Signed-off-by: Vincent Hou <[email protected]>
  • Loading branch information
houshengbo authored Apr 30, 2024
1 parent f717e12 commit 36a3e6d
Show file tree
Hide file tree
Showing 15 changed files with 601 additions and 80 deletions.
1 change: 1 addition & 0 deletions charts/kserve-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $ helm install kserve oci://ghcr.io/kserve/charts/kserve --version v0.12.1
| kserve.agent.tag | string | `"v0.12.1"` | |
| kserve.controller.affinity | object | `{}` | |
| kserve.controller.deploymentMode | string | `"Serverless"` | |
| kserve.controller.gateway.additionalIngressDomains | list | `[]` | |
| kserve.controller.gateway.disableIngressCreation | bool | `false` | |
| kserve.controller.gateway.disableIstioVirtualHost | bool | `false` | |
| kserve.controller.gateway.domain | string | `"example.com"` | |
Expand Down
9 changes: 9 additions & 0 deletions charts/kserve-resources/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ data:
"localGateway" : "knative-serving/knative-local-gateway",
"localGatewayService" : "knative-local-gateway.istio-system.svc.cluster.local",
"ingressDomain" : "example.com",
"additionalIngressDomains": ["additional-example.com", "additional-example-1.com"],
"ingressClassName" : "istio",
"domainTemplate": "{{ .Name }}-{{ .Namespace }}.{{ .IngressDomain }}",
"urlScheme": "http",
Expand Down Expand Up @@ -215,6 +216,9 @@ data:
# NOTE: This configuration only applicable for raw deployment.
"ingressDomain" : "example.com",
# additionalIngressDomains specifies the additional domain names which are used for creating the url.
"additionalIngressDomains": ["additional-example.com", "additional-example-1.com"]
# ingressClassName specifies the ingress controller to use for ingress traffic.
# This is optional and if omitted the default ingress in the cluster is used.
# https://kubernetes.io/docs/concepts/services-networking/ingress/#default-ingress-class
Expand Down Expand Up @@ -496,6 +500,11 @@ data:
"localGatewayService" : "{{ .Values.kserve.controller.gateway.localGateway.gatewayService }}",
"ingressClassName" : "{{ .Values.kserve.controller.gateway.ingressGateway.className }}",
"ingressDomain" : "{{ .Values.kserve.controller.gateway.domain }}",
"additionalIngressDomains": [
{{- range $index, $flag := .Values.kserve.controller.gateway.additionalIngressDomains }}
{{ $flag | quote }} {{ if ne $index (sub (len $.Values.kserve.controller.gateway.additionalIngressDomains) 1)}}, {{ end }}
{{- end}}
],
"domainTemplate": "{{ .Values.kserve.controller.gateway.domainTemplate }}",
"urlScheme": "{{ .Values.kserve.controller.gateway.urlScheme }}",
"disableIstioVirtualHost": {{ .Values.kserve.controller.gateway.disableIstioVirtualHost }},
Expand Down
1 change: 1 addition & 0 deletions charts/kserve-resources/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ kserve:
rbacProxyImage: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.1
gateway:
domain: example.com
additionalIngressDomains: []
domainTemplate: "{{ .Name }}-{{ .Namespace }}.{{ .IngressDomain }}"
urlScheme: http
disableIstioVirtualHost: false
Expand Down
6 changes: 5 additions & 1 deletion config/configmap/inferenceservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ data:
"localGateway" : "knative-serving/knative-local-gateway",
"localGatewayService" : "knative-local-gateway.istio-system.svc.cluster.local",
"ingressDomain" : "example.com",
"additionalIngressDomains": ["additional-example.com", "additional-example-1.com"],
"ingressClassName" : "istio",
"domainTemplate": "{{ .Name }}-{{ .Namespace }}.{{ .IngressDomain }}",
"urlScheme": "http",
Expand Down Expand Up @@ -225,7 +226,10 @@ data:
# If ingressDomain is empty then example.com is used as default domain.
# NOTE: This configuration only applicable for raw deployment.
"ingressDomain" : "example.com",
# additionalIngressDomains specifies the additional domain names which are used for creating the url.
"additionalIngressDomains": ["additional-example.com", "additional-example-1.com"]
# ingressClassName specifies the ingress controller to use for ingress traffic.
# This is optional and if omitted the default ingress in the cluster is used.
# https://kubernetes.io/docs/concepts/services-networking/ingress/#default-ingress-class
Expand Down
240 changes: 240 additions & 0 deletions go.sum

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions pkg/apis/serving/v1beta1/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ type InferenceServicesConfig struct {

// +kubebuilder:object:generate=false
type IngressConfig struct {
IngressGateway string `json:"ingressGateway,omitempty"`
IngressServiceName string `json:"ingressService,omitempty"`
LocalGateway string `json:"localGateway,omitempty"`
LocalGatewayServiceName string `json:"localGatewayService,omitempty"`
IngressDomain string `json:"ingressDomain,omitempty"`
IngressClassName *string `json:"ingressClassName,omitempty"`
DomainTemplate string `json:"domainTemplate,omitempty"`
UrlScheme string `json:"urlScheme,omitempty"`
DisableIstioVirtualHost bool `json:"disableIstioVirtualHost,omitempty"`
PathTemplate string `json:"pathTemplate,omitempty"`
DisableIngressCreation bool `json:"disableIngressCreation,omitempty"`
IngressGateway string `json:"ingressGateway,omitempty"`
IngressServiceName string `json:"ingressService,omitempty"`
LocalGateway string `json:"localGateway,omitempty"`
LocalGatewayServiceName string `json:"localGatewayService,omitempty"`
IngressDomain string `json:"ingressDomain,omitempty"`
IngressClassName *string `json:"ingressClassName,omitempty"`
AdditionalIngressDomains *[]string `json:"additionalIngressDomains,omitempty"`
DomainTemplate string `json:"domainTemplate,omitempty"`
UrlScheme string `json:"urlScheme,omitempty"`
DisableIstioVirtualHost bool `json:"disableIstioVirtualHost,omitempty"`
PathTemplate string `json:"pathTemplate,omitempty"`
DisableIngressCreation bool `json:"disableIngressCreation,omitempty"`
}

// +kubebuilder:object:generate=false
Expand Down
78 changes: 32 additions & 46 deletions pkg/apis/serving/v1beta1/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,36 @@ limitations under the License.
package v1beta1

import (
ctx "context"
logger "log"
"fmt"
"testing"

"github.com/kserve/kserve/pkg/constants"
"github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fakeclientset "k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/controller-runtime/pkg/client"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func createFakeClient() client.WithWatch {
clientBuilder := fakeclient.NewClientBuilder()
fakeClient := clientBuilder.Build()
configMap := &v1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "",
},
ObjectMeta: metav1.ObjectMeta{
Name: constants.InferenceServiceConfigMapName,
Namespace: constants.KServeNamespace,
},
Immutable: nil,
Data: map[string]string{},
BinaryData: map[string][]byte{
ExplainerConfigKeyName: []byte(`{ │
"art": { │
"image" : "kserve/art-explainer", │
"defaultImageVersion": "latest" │
} │
}`),
IngressConfigKeyName: []byte(`{ │
"ingressGateway" : "knative-serving/knative-ingress-gateway", │
"ingressService" : "istio-ingressgateway.istio-system.svc.cluster.local", │
"localGateway" : "knative-serving/knative-local-gateway", │
"localGatewayService" : "knative-local-gateway.istio-system.svc.cluster.local", │
"ingressDomain" : "example.com", │
"ingressClassName" : "istio", │
"domainTemplate": "{{ .Name }}-{{ .Namespace }}.{{ .IngressDomain }}", │
"urlScheme": "http" │
}`),
DeployConfigName: []byte(`{ │
"defaultDeploymentMode": "Serverless" │
}`),
},
}
err := fakeClient.Create(ctx.TODO(), configMap)
if err != nil {
logger.Fatalf("Unable to create configmap: %v", err)
}
return fakeClient
}
var (
KnativeIngressGateway = "knative-serving/knative-ingress-gateway"
IngressService = "test-destination"
KnativeLocalGateway = "knative-serving/knative-local-gateway"
LocalGatewayService = "knative-local-gateway.istio-system.svc.cluster.local"
UrlScheme = "https"
IngressDomain = "example.com"
AdditionalDomain = "additional-example.com"
AdditionalDomainExtra = "additional-example-extra.com"
IngressConfigData = fmt.Sprintf(`{
"ingressGateway" : "%s",
"ingressService" : "%s",
"localGateway" : "%s",
"localGatewayService" : "%s",
"ingressDomain": "%s",
"urlScheme": "https",
"additionalIngressDomains": ["%s","%s"]
}`, KnativeIngressGateway, IngressService, KnativeLocalGateway, LocalGatewayService, IngressDomain,
AdditionalDomain, AdditionalDomainExtra)
)

func TestNewInferenceServiceConfig(t *testing.T) {
g := gomega.NewGomegaWithT(t)
Expand All @@ -87,10 +62,21 @@ func TestNewIngressConfig(t *testing.T) {
g := gomega.NewGomegaWithT(t)
clientset := fakeclientset.NewSimpleClientset(&v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: constants.InferenceServiceConfigMapName, Namespace: constants.KServeNamespace},
Data: map[string]string{
IngressConfigKeyName: IngressConfigData,
},
})
ingressCfg, err := NewIngressConfig(clientset)
g.Expect(err).Should(gomega.BeNil())
g.Expect(ingressCfg).ShouldNot(gomega.BeNil())

g.Expect(ingressCfg.IngressGateway).To(gomega.Equal(KnativeIngressGateway))
g.Expect(ingressCfg.IngressServiceName).To(gomega.Equal(IngressService))
g.Expect(ingressCfg.LocalGateway).To(gomega.Equal(KnativeLocalGateway))
g.Expect(ingressCfg.LocalGatewayServiceName).To(gomega.Equal(LocalGatewayService))
g.Expect(ingressCfg.UrlScheme).To(gomega.Equal(UrlScheme))
g.Expect(ingressCfg.IngressDomain).To(gomega.Equal(IngressDomain))
g.Expect(*ingressCfg.AdditionalIngressDomains).To(gomega.Equal([]string{AdditionalDomain, AdditionalDomainExtra}))
}

func TestNewDeployConfig(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/serving/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/apis/serving/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2699,6 +2699,13 @@
"v1beta1.IngressConfig": {
"type": "object",
"properties": {
"additionalIngressDomains": {
"type": "array",
"items": {
"type": "string",
"default": ""
}
},
"disableIngressCreation": {
"type": "boolean"
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ const (
ModelMeshDeployment DeploymentModeType = "ModelMesh"
)

const (
DefaultNSKnativeServing = "knative-serving"
)

// built-in runtime servers
const (
SKLearnServer = "kserve-sklearnserver"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/v1beta1/inferenceservice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (r *InferenceServiceReconciler) Reconcile(ctx context.Context, req ctrl.Req
return reconcile.Result{}, errors.Wrapf(err, "fails to reconcile ingress")
}
} else {
reconciler := ingress.NewIngressReconciler(r.Client, r.Scheme, ingressConfig)
reconciler := ingress.NewIngressReconciler(r.Client, r.Clientset, r.Scheme, ingressConfig)
r.Log.Info("Reconciling ingress for inference service", "isvc", isvc.Name)
if err := reconciler.Reconcile(isvc); err != nil {
return reconcile.Result{}, errors.Wrapf(err, "fails to reconcile ingress")
Expand Down
Loading

0 comments on commit 36a3e6d

Please sign in to comment.