Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Nov 6, 2024
1 parent d00f780 commit 49383cf
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
istioGateway:
- apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: httpbin-gateway
namespace: default
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- httpbin.example.com
port:
name: http
number: 80
protocol: HTTP
virtualService:
httpbin-gateway:
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: httpbin
namespace: default
annotations:
htnn.mosn.io/filterpolicy: |
{"apiVersion":"htnn.mosn.io/v1","kind":"FilterPolicy","metadata":{"name":"policy","namespace":"default"},"spec":{"filters":{"animal":{"config":{"hostName":"fish"}},"localReply":{"config":{"code":404}}}}}
spec:
gateways:
- httpbin-gateway
hosts:
- httpbin.example.com
http:
- match:
- uri:
prefix: /status
name: policy
route:
- destination:
host: httpbin
port:
number: 8000
filterPolicy:
httpbin:
- apiVersion: htnn.mosn.io/v1
kind: FilterPolicy
metadata:
name: policy
namespace: default
spec:
targetRef:
group: networking.istio.io
kind: VirtualService
name: httpbin
filters:
animal:
config:
hostName: goldfish
demo:
config:
hostName: micky
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
- metadata:
annotations:
htnn.mosn.io/info: '{"filterpolicies":["default/embedded-virtualservice-httpbin","default/policy"]}'
creationTimestamp: null
labels:
htnn.mosn.io/created-by: FilterPolicy
name: htnn-h-httpbin.example.com
namespace: default
spec:
configPatches:
- applyTo: HTTP_ROUTE
match:
routeConfiguration:
vhost:
name: httpbin.example.com:80
route:
name: policy
patch:
operation: MERGE
value:
typed_per_filter_config:
htnn.filters.http.golang:
'@type': type.googleapis.com/envoy.extensions.filters.http.golang.v3alpha.ConfigsPerRoute
plugins_config:
fm:
config:
'@type': type.googleapis.com/xds.type.v3.TypedStruct
value:
plugins:
- config:
hostName: fish
name: animal
- config:
hostName: micky
name: demo
- config:
code: 404
name: localReply
status: {}
24 changes: 24 additions & 0 deletions controller/internal/translation/translation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package translation

import (
"context"
"encoding/json"
"maps"
"os"
"path/filepath"
Expand All @@ -32,6 +33,7 @@ import (
"mosn.io/htnn/controller/internal/config"
"mosn.io/htnn/controller/internal/istio"
"mosn.io/htnn/controller/internal/log"
"mosn.io/htnn/controller/pkg/constant"
_ "mosn.io/htnn/controller/plugins" // register plugins
_ "mosn.io/htnn/controller/registries" // register registries
mosniov1 "mosn.io/htnn/types/apis/v1"
Expand Down Expand Up @@ -213,6 +215,17 @@ func TestTranslate(t *testing.T) {
}
s.AddPolicyForVirtualService(fp, wrapper.vs, wrapper.gws)
}

ann := wrapper.vs.Annotations
if ann[constant.AnnotationFilterPolicy] != "" {
var policy mosniov1.FilterPolicy
err := json.Unmarshal([]byte(ann[constant.AnnotationFilterPolicy]), &policy)
require.NoError(t, err)
policy.Namespace = wrapper.vs.Namespace
// Name convention is "embedded-$kind-$name"
policy.Name = "embedded-virtualservice-" + wrapper.vs.Name
s.AddPolicyForVirtualService(&policy, wrapper.vs, wrapper.gws)
}
}

// For gateway-only cases
Expand All @@ -225,6 +238,17 @@ func TestTranslate(t *testing.T) {
}
s.AddPolicyForIstioGateway(fp, gw)
}

ann := gw.Annotations
if ann[constant.AnnotationFilterPolicy] != "" {
var policy mosniov1.FilterPolicy
err := json.Unmarshal([]byte(ann[constant.AnnotationFilterPolicy]), &policy)
require.NoError(t, err)
policy.Namespace = gw.Namespace
// Name convention is "embedded-$kind-$name"
policy.Name = "embedded-gateway-" + gw.Name
s.AddPolicyForIstioGateway(&policy, gw)
}
}
if config.EnableLDSPluginViaECDS() {
for _, gw := range input.IstioGateway {
Expand Down

0 comments on commit 49383cf

Please sign in to comment.