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
Next Next commit
fix virtual service destination routes when match is set in the analy…
…sis config

primary destination is duplicated on both virtual service routes when setting match rules as per the [istio a/b testing](https://docs.flagger.app/tutorials/istio-ab-testing) tutorial:
```yaml
  http:
  - match:
    - headers:
        x-header-1:
          exact: Test_from_DEVs
    route:
    - destination:
        host: podinfo-primary
      weight: 50
    - destination:
        host: podinfo-canary
      weight: 50
  - route:
     - destination:
         host: podinfo-primary
        weight: 50
```
this PR removes the primary destination from canary route to generate and update the virtual service without the duplicate destination:
```yaml
  http:
  - match:
    - headers:
        x-header-1:
          exact: Test_from_DEVs
    route:
    - destination:
        host: podinfo-canary
      weight: 50
  - route:
    - destination:
        host: podinfo-primary
       weight: 50
```

Signed-off-by: luisr-escobar <luis.scobr@gmail.com>
  • Loading branch information
luisr-escobar authored Jun 27, 2024
commit 208d1cd3397d957c029624b261a72dc9eb1d85cb
18 changes: 16 additions & 2 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
Retries: canary.Spec.Service.Retries,
CorsPolicy: canary.Spec.Service.CorsPolicy,
Headers: canary.Spec.Service.Headers,
Route: canaryRoute,
Route: []istiov1beta1.HTTPRouteDestination{
makeDestination(canary, canaryName, 0),
},
},
{
Match: canary.Spec.Service.Match,
Expand Down Expand Up @@ -452,6 +454,19 @@ 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 @@ -620,7 +635,6 @@ 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