Skip to content

Commit

Permalink
test case - handle backend updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Apr 16, 2024
1 parent 0567677 commit 2d11b73
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
151 changes: 151 additions & 0 deletions pkg/reconciler/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,157 @@ func TestReconcileProbing(t *testing.T) {
},
}},
},
}, {
Name: "updated ingress - backend headers change",
Key: "ns/name",
Objects: append([]runtime.Object{
ing(withBasicSpec,
withGatewayAPIclass,
withFinalizer,
makeItReady,
withBackendAppendHeaders("key", "value")),
httpRoute(t, ing(withBasicSpec, withGatewayAPIclass), httpRouteReady),
}, servicesAndEndpoints...),
Ctx: withStatusManager(&fakeStatusManager{
FakeIsProbeActive: func(types.NamespacedName) (status.ProbeState, bool) {
return status.ProbeState{Ready: true, Version: "previous"}, true
},
FakeDoProbes: func(context.Context, status.Backends) (status.ProbeState, error) {
return status.ProbeState{Ready: false}, nil
},
}),
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: ing(withBasicSpec,
withGatewayAPIclass,
withFinalizer,
makeItReady,
makeLoadBalancerNotReady,
withBackendAppendHeaders("key", "value"),
),
}},
WantUpdates: []clientgotesting.UpdateActionImpl{{
Object: &gatewayapi.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: "example.com",
Namespace: "ns",
Annotations: map[string]string{
networking.IngressClassAnnotationKey: gatewayAPIIngressClassName,
},
Labels: map[string]string{
networking.VisibilityLabelKey: "",
},
OwnerReferences: []metav1.OwnerReference{{
APIVersion: "networking.internal.knative.dev/v1alpha1",
Kind: "Ingress",
Name: "name",
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
}},
},
Spec: gatewayapi.HTTPRouteSpec{
CommonRouteSpec: gatewayapi.CommonRouteSpec{
ParentRefs: []gatewayapi.ParentReference{{
Group: ptr.To[gatewayapi.Group]("gateway.networking.k8s.io"),
Kind: ptr.To[gatewayapi.Kind]("Gateway"),
Namespace: ptr.To[gatewayapi.Namespace]("istio-system"),
Name: "istio-gateway",
}},
},
Hostnames: []gatewayapi.Hostname{"example.com"},
Rules: []gatewayapi.HTTPRouteRule{{
Matches: []gatewayapi.HTTPRouteMatch{{
Path: &gatewayapi.HTTPPathMatch{
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
Value: ptr.To("/"),
},
Headers: []gatewayapi.HTTPHeaderMatch{{
Type: ptr.To(gatewayapiv1.HeaderMatchExact),
Name: header.HashKey,
Value: header.HashValueOverride,
}},
}},
Filters: []gatewayapi.HTTPRouteFilter{{
Type: gatewayapiv1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayapi.HTTPHeaderFilter{
Set: []gatewayapi.HTTPHeader{{
Name: header.HashKey,
Value: "3531718c72349578ea2293f8ec1cd980d551f70295c1b0b4c10abfc0b2a248f8",
}},
},
}},
BackendRefs: []gatewayapi.HTTPBackendRef{{
Filters: []gatewayapiv1.HTTPRouteFilter{{
Type: gatewayapiv1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayapi.HTTPHeaderFilter{
Set: []gatewayapi.HTTPHeader{{
Name: "key",
Value: "value",
}, {
Name: "K-Serving-Revision",
Value: "goo",
}, {
Name: "K-Serving-Namespace",
Value: "ns",
}},
},
}},
BackendRef: gatewayapi.BackendRef{
BackendObjectReference: gatewayapiv1.BackendObjectReference{
Group: ptr.To[gatewayapi.Group](""),
Kind: ptr.To[gatewayapi.Kind]("Service"),
Name: "goo",
Port: ptr.To[gatewayapi.PortNumber](123),
},
Weight: ptr.To[int32](100),
},
}},
}, {
Matches: []gatewayapi.HTTPRouteMatch{{
Path: &gatewayapi.HTTPPathMatch{
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
Value: ptr.To("/"),
},
}},
BackendRefs: []gatewayapi.HTTPBackendRef{{
Filters: []gatewayapiv1.HTTPRouteFilter{{
Type: gatewayapiv1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayapi.HTTPHeaderFilter{
Set: []gatewayapi.HTTPHeader{{
Name: "key",
Value: "value",
}, {
Name: "K-Serving-Revision",
Value: "goo",
}, {
Name: "K-Serving-Namespace",
Value: "ns",
}},
},
}},
BackendRef: gatewayapi.BackendRef{
BackendObjectReference: gatewayapiv1.BackendObjectReference{
Group: ptr.To[gatewayapi.Group](""),
Kind: ptr.To[gatewayapi.Kind]("Service"),
Name: "goo",
Port: ptr.To[gatewayapi.PortNumber](123),
},
Weight: ptr.To[int32](100),
},
}},
}},
},
Status: gatewayapi.HTTPRouteStatus{
RouteStatus: gatewayapi.RouteStatus{
Parents: []gatewayapi.RouteParentStatus{{
Conditions: []metav1.Condition{{
Type: string(gatewayapi.RouteConditionAccepted),
Status: metav1.ConditionTrue,
}},
}},
},
},
},
}},
}}

table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler {
Expand Down
6 changes: 6 additions & 0 deletions pkg/reconciler/ingress/lister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ func withThirdRevisionSpec(i *v1alpha1.Ingress) {
i.Spec.Rules[0].HTTP.Paths[0].Splits[0].AppendHeaders["K-Serving-Revision"] = "third-revision"
}

func withBackendAppendHeaders(key, val string) IngressOption {
return func(i *v1alpha1.Ingress) {
i.Spec.Rules[0].HTTP.Paths[0].Splits[0].AppendHeaders[key] = val
}
}

func withInternalSpec(i *v1alpha1.Ingress) {
i.Spec.Rules = append(i.Spec.Rules, v1alpha1.IngressRule{
Hosts: []string{"foo.svc", "foo.svc.cluster.local"},
Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/ingress/reconcile_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ func (c *Reconciler) reconcileHTTPRouteUpdate(
for _, backend := range oldBackends {
resources.AddOldBackend(desired, *hash, backend)
}
} else if probeHash != *hash {
desired, err = resources.MakeHTTPRoute(ctx, ing, rule)
} else {
// Noop
if probe.Version != "" {
Expand Down

0 comments on commit 2d11b73

Please sign in to comment.