@@ -50,20 +50,34 @@ type Destination struct {
5050 ServiceName string
5151 Weight int32
5252 Port uint32
53+ Shadow bool
5354}
5455
5556func VirtualService (spec * VirtualServiceSpec ) * istioclientnetworking.VirtualService {
5657 destinations := []* istionetworking.HTTPRouteDestination {}
58+ var mirror * istionetworking.Destination
59+ var mirrorWeight * istionetworking.Percent
60+
5761 for _ , destination := range spec .Destinations {
58- destinations = append ( destinations , & istionetworking. HTTPRouteDestination {
59- Destination : & istionetworking.Destination {
62+ if destination . Shadow {
63+ mirror = & istionetworking.Destination {
6064 Host : destination .ServiceName ,
6165 Port : & istionetworking.PortSelector {
6266 Number : destination .Port ,
6367 },
64- },
65- Weight : destination .Weight ,
66- })
68+ }
69+ mirrorWeight = & istionetworking.Percent {Value : float64 (destination .Weight )}
70+ } else {
71+ destinations = append (destinations , & istionetworking.HTTPRouteDestination {
72+ Destination : & istionetworking.Destination {
73+ Host : destination .ServiceName ,
74+ Port : & istionetworking.PortSelector {
75+ Number : destination .Port ,
76+ },
77+ },
78+ Weight : destination .Weight ,
79+ })
80+ }
6781 }
6882
6983 var httpRoutes []* istionetworking.HTTPRoute
@@ -79,7 +93,9 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ
7993 },
8094 },
8195 },
82- Route : destinations ,
96+ Route : destinations ,
97+ Mirror : mirror ,
98+ MirrorPercentage : mirrorWeight ,
8399 })
84100
85101 if spec .Rewrite != nil {
@@ -98,7 +114,9 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ
98114 },
99115 },
100116 },
101- Route : destinations ,
117+ Route : destinations ,
118+ Mirror : mirror ,
119+ MirrorPercentage : mirrorWeight ,
102120 }
103121
104122 prefixMatch := & istionetworking.HTTPRoute {
@@ -111,7 +129,9 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ
111129 },
112130 },
113131 },
114- Route : destinations ,
132+ Route : destinations ,
133+ Mirror : mirror ,
134+ MirrorPercentage : mirrorWeight ,
115135 }
116136
117137 if spec .Rewrite != nil {
0 commit comments