From 56cb888cbf63696e9dab052793f8cb9d6624fe92 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Mon, 25 Feb 2019 00:08:06 +0200 Subject: [PATCH] Add HTTP match and rewrite to virtual service --- pkg/controller/router.go | 45 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/pkg/controller/router.go b/pkg/controller/router.go index 4097ab42..dd99873a 100644 --- a/pkg/controller/router.go +++ b/pkg/controller/router.go @@ -168,36 +168,39 @@ func (c *CanaryRouter) syncVirtualService(cd *flaggerv1.Canary) error { primaryName := fmt.Sprintf("%s-primary", targetName) hosts := append(cd.Spec.Service.Hosts, targetName) gateways := append(cd.Spec.Service.Gateways, "mesh") - virtualService, err := c.istioClient.NetworkingV1alpha3().VirtualServices(cd.Namespace).Get(targetName, metav1.GetOptions{}) + route := []istiov1alpha3.DestinationWeight{ + { + Destination: istiov1alpha3.Destination{ + Host: primaryName, + Port: istiov1alpha3.PortSelector{ + Number: uint32(cd.Spec.Service.Port), + }, + }, + Weight: 100, + }, + { + Destination: istiov1alpha3.Destination{ + Host: targetName, + Port: istiov1alpha3.PortSelector{ + Number: uint32(cd.Spec.Service.Port), + }, + }, + Weight: 0, + }, + } newSpec := istiov1alpha3.VirtualServiceSpec{ Hosts: hosts, Gateways: gateways, Http: []istiov1alpha3.HTTPRoute{ { - Route: []istiov1alpha3.DestinationWeight{ - { - Destination: istiov1alpha3.Destination{ - Host: primaryName, - Port: istiov1alpha3.PortSelector{ - Number: uint32(cd.Spec.Service.Port), - }, - }, - Weight: 100, - }, - { - Destination: istiov1alpha3.Destination{ - Host: targetName, - Port: istiov1alpha3.PortSelector{ - Number: uint32(cd.Spec.Service.Port), - }, - }, - Weight: 0, - }, - }, + Match: cd.Spec.Service.Match, + Rewrite: cd.Spec.Service.Rewrite, + Route: route, }, }, } + virtualService, err := c.istioClient.NetworkingV1alpha3().VirtualServices(cd.Namespace).Get(targetName, metav1.GetOptions{}) // insert if errors.IsNotFound(err) { virtualService = &istiov1alpha3.VirtualService{