Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix virtual service destination routes when match is set #1668

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
default all traffic to canary deployment
Signed-off-by: luisr-escobar <luis.scobr@gmail.com>
  • Loading branch information
luisr-escobar authored Oct 1, 2024
commit 36a91bd1fd683797d02f4141c143be227c17be60
22 changes: 6 additions & 16 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"math/rand"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -246,7 +247,8 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Route: []istiov1beta1.HTTPRouteDestination{
makeDestination(canary, canaryName, 0),
makeDestination(canary, primaryName, 0),
makeDestination(canary, canaryName, 100),
},
},
{
Expand Down Expand Up @@ -454,19 +456,6 @@ func (ir *IstioRouter) GetRoutes(canary *flaggerv1.Canary) (
}
}

if !isTcp(canary) && len(canary.GetAnalysis().Match) > 0 {
for _, http := range vs.Spec.Http {
for _, routeDest := range http.Route {
if routeDest.Destination.Host == primaryName {
primaryWeight = routeDest.Weight
}
if routeDest.Destination.Host == canaryName {
canaryWeight = routeDest.Weight
}
}
}
}

if primaryWeight == 0 && canaryWeight == 0 {
err = fmt.Errorf("VirtualService %s.%s does not contain routes for %s-primary and %s-canary",
apexName, canary.Namespace, apexName, apexName)
Expand Down Expand Up @@ -635,6 +624,7 @@ func (ir *IstioRouter) SetRoutes(
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Route: []istiov1beta1.HTTPRouteDestination{
makeDestination(canary, primaryName, primaryWeight),
makeDestination(canary, canaryName, canaryWeight),
},
},
Expand Down Expand Up @@ -720,7 +710,7 @@ func mergeMatchConditions(canary, defaults []istiov1beta1.HTTPMatchRequest) []is
return merged
}

// makeDestination returns a an destination weight for the specified host
// makeDestination returns a destination weight for the specified host
func makeDestination(canary *flaggerv1.Canary, host string, weight int) istiov1beta1.HTTPRouteDestination {
dest := istiov1beta1.HTTPRouteDestination{
Destination: istiov1beta1.Destination{
Expand All @@ -732,7 +722,7 @@ func makeDestination(canary *flaggerv1.Canary, host string, weight int) istiov1b
// set destination port when an ingress gateway is specified
if canary.Spec.Service.PortDiscovery &&
(len(canary.Spec.Service.Gateways) > 0 &&
canary.Spec.Service.Gateways[0] != "mesh" || canary.Spec.Service.Delegation) {
!slices.Contains(canary.Spec.Service.Gateways, "mesh") || canary.Spec.Service.Delegation) {
dest = istiov1beta1.HTTPRouteDestination{
Destination: istiov1beta1.Destination{
Host: host,
Expand Down