@@ -50,22 +50,6 @@ type Destination struct {
5050}
5151
5252func VirtualService (spec * VirtualServiceSpec ) * istioclientnetworking.VirtualService {
53- var stringMatch * istionetworking.StringMatch
54-
55- if spec .ExactPath != nil {
56- stringMatch = & istionetworking.StringMatch {
57- MatchType : & istionetworking.StringMatch_Exact {
58- Exact : urls .CanonicalizeEndpoint (* spec .ExactPath ),
59- },
60- }
61- } else {
62- stringMatch = & istionetworking.StringMatch {
63- MatchType : & istionetworking.StringMatch_Prefix {
64- Prefix : urls .CanonicalizeEndpoint (* spec .PrefixPath ),
65- },
66- }
67- }
68-
6953 destinations := []* istionetworking.HTTPRouteDestination {}
7054 for _ , destination := range spec .Destinations {
7155 destinations = append (destinations , & istionetworking.HTTPRouteDestination {
@@ -79,6 +63,56 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ
7963 })
8064 }
8165
66+ httpRoutes := []* istionetworking.HTTPRoute {}
67+
68+ if spec .ExactPath != nil {
69+ httpRoutes = append (httpRoutes , & istionetworking.HTTPRoute {
70+ Match : []* istionetworking.HTTPMatchRequest {
71+ {
72+ Uri : & istionetworking.StringMatch {
73+ MatchType : & istionetworking.StringMatch_Exact {
74+ Exact : urls .CanonicalizeEndpoint (* spec .ExactPath ),
75+ },
76+ },
77+ },
78+ },
79+ Route : destinations ,
80+ Rewrite : & istionetworking.HTTPRewrite {
81+ Uri : urls .CanonicalizeEndpoint (* spec .Rewrite ),
82+ },
83+ })
84+ } else {
85+ httpRoutes = append (httpRoutes , & istionetworking.HTTPRoute {
86+ Match : []* istionetworking.HTTPMatchRequest {
87+ {
88+ Uri : & istionetworking.StringMatch {
89+ MatchType : & istionetworking.StringMatch_Exact {
90+ Exact : urls .CanonicalizeEndpoint (* spec .PrefixPath ),
91+ },
92+ },
93+ },
94+ },
95+ Route : destinations ,
96+ Rewrite : & istionetworking.HTTPRewrite {
97+ Uri : urls .CanonicalizeEndpoint (* spec .Rewrite ),
98+ },
99+ }, & istionetworking.HTTPRoute {
100+ Match : []* istionetworking.HTTPMatchRequest {
101+ {
102+ Uri : & istionetworking.StringMatch {
103+ MatchType : & istionetworking.StringMatch_Prefix {
104+ Prefix : urls .CanonicalizeEndpoint (* spec .PrefixPath ) + "/" ,
105+ },
106+ },
107+ },
108+ },
109+ Route : destinations ,
110+ Rewrite : & istionetworking.HTTPRewrite {
111+ Uri : urls .CanonicalizeEndpoint (* spec .Rewrite ) + "/" ,
112+ },
113+ })
114+ }
115+
82116 virtualService := & istioclientnetworking.VirtualService {
83117 TypeMeta : _virtualServiceTypeMeta ,
84118 ObjectMeta : kmeta.ObjectMeta {
@@ -89,33 +123,10 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ
89123 Spec : istionetworking.VirtualService {
90124 Hosts : []string {"*" },
91125 Gateways : spec .Gateways ,
92- Http : []* istionetworking.HTTPRoute {
93- {
94- Match : []* istionetworking.HTTPMatchRequest {
95- {
96- Uri : stringMatch ,
97- },
98- },
99- Route : destinations ,
100- },
101- },
126+ Http : httpRoutes ,
102127 },
103128 }
104129
105- var path string
106-
107- if spec .ExactPath != nil {
108- path = * spec .ExactPath
109- } else {
110- path = * spec .PrefixPath
111- }
112-
113- if spec .Rewrite != nil && urls .CanonicalizeEndpoint (* spec .Rewrite ) != urls .CanonicalizeEndpoint (path ) {
114- virtualService .Spec .Http [0 ].Rewrite = & istionetworking.HTTPRewrite {
115- Uri : urls .CanonicalizeEndpoint (* spec .Rewrite ),
116- }
117- }
118-
119130 return virtualService
120131}
121132
0 commit comments