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: get new httpRoutesI after removeRoute() to avoid duplicates. Fixes #2769 #2887

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 6 additions & 5 deletions rollout/trafficrouting/istio/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,6 @@ func (r *Reconciler) getVirtualService(namespace string, vsvcName string, client
}

func (r *Reconciler) reconcileVirtualServiceHeaderRoutes(virtualService v1alpha1.IstioVirtualService, obj *unstructured.Unstructured, headerRouting *v1alpha1.SetHeaderRoute) error {
// HTTP Routes
httpRoutesI, err := GetHttpRoutesI(obj)
if err != nil {
return err
}
destRuleHost, err := r.getDestinationRuleHost()
if err != nil {
return err
Expand Down Expand Up @@ -746,6 +741,12 @@ func (r *Reconciler) reconcileVirtualServiceHeaderRoutes(virtualService v1alpha1
return fmt.Errorf("[reconcileVirtualServiceHeaderRoutes] failed to remove http route from virtual service: %w", err)
}

// HTTP Routes
httpRoutesI, err := GetHttpRoutesI(obj)
if err != nil {
return err
}

httpRoutesI = append(httpRoutesI, createHeaderRoute(virtualService, obj, headerRouting, canarySvc, canarySubset))

err = unstructured.SetNestedSlice(obj.Object, httpRoutesI, "spec", Http)
Expand Down
43 changes: 43 additions & 0 deletions rollout/trafficrouting/istio/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2857,3 +2857,46 @@ func AssertReconcileUpdateMirror(t *testing.T, vsvc string, ro *v1alpha1.Rollout
assert.Equal(t, "update", actions[0].GetVerb())
return client
}

func TestReconcileHeaderRouteAvoidDuplicates(t *testing.T) {
ro := rolloutWithHttpRoutes("stable", "canary", "vsvc", []string{"primary"})
obj := unstructuredutil.StrToUnstructuredUnsafe(regularVsvc)
client := testutil.NewFakeDynamicClient(obj)
vsvcLister, druleLister := getIstioListers(client)
r := NewReconciler(ro, client, record.NewFakeEventRecorder(), vsvcLister, druleLister)
client.ClearActions()

const headerName = "test-header-route"
r.rollout.Spec.Strategy.Canary.TrafficRouting.ManagedRoutes = append(r.rollout.Spec.Strategy.Canary.TrafficRouting.ManagedRoutes, []v1alpha1.MangedRoutes{{
Name: headerName,
},
}...)

var setHeader = &v1alpha1.SetHeaderRoute{
Name: headerName,
Match: []v1alpha1.HeaderRoutingMatch{
{
HeaderName: "browser",
HeaderValue: &v1alpha1.StringMatch{
Prefix: "Firefox",
},
},
},
}

err := r.SetHeaderRoute(setHeader)
assert.Nil(t, err)

err = r.SetHeaderRoute(setHeader)
assert.Nil(t, err)

iVirtualService, err := client.Resource(istioutil.GetIstioVirtualServiceGVR()).Namespace(r.rollout.Namespace).Get(context.TODO(), ro.Spec.Strategy.Canary.TrafficRouting.Istio.VirtualService.Name, metav1.GetOptions{})
assert.NoError(t, err)
// HTTP Routes
httpRoutes := extractHttpRoutes(t, iVirtualService)

// Assertions
assert.Equal(t, httpRoutes[0].Name, headerName)
assert.Equal(t, httpRoutes[1].Name, "primary")
assert.Equal(t, httpRoutes[2].Name, "secondary")
}