Skip to content

Fix probing when KIngress has multiple visibilities (External/ClusterLocal) #693

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

Merged
merged 7 commits into from
Apr 19, 2024
6 changes: 6 additions & 0 deletions pkg/reconciler/ingress/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type HTTPRoute struct {
Hostname string
Rules []RuleBuilder
StatusConditions []metav1.Condition
ClusterLocal bool
}

func (r HTTPRoute) Build() *gatewayapi.HTTPRoute {
Expand Down Expand Up @@ -79,6 +80,11 @@ func (r HTTPRoute) Build() *gatewayapi.HTTPRoute {
},
}

if r.ClusterLocal {
route.Labels[networking.VisibilityLabelKey] = "cluster-local"
route.Spec.CommonRouteSpec.ParentRefs[0].Name = gatewayapi.ObjectName(privateName)
}

for _, hostname := range hostnames {
route.Spec.Hostnames = append(
route.Spec.Hostnames,
Expand Down
26 changes: 14 additions & 12 deletions pkg/reconciler/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,35 @@ func (c *Reconciler) reconcileIngress(ctx context.Context, ing *v1alpha1.Ingress
ing.Status.InitializeConditions()

var (
hash string
err error
ingressHash string
err error
probeKey = types.NamespacedName{
Name: ing.Name,
Namespace: ing.Namespace,
}
)

if hash, err = ingress.InsertProbe(ing); err != nil {
if ingressHash, err = ingress.InsertProbe(ing); err != nil {
return fmt.Errorf("failed to add knative probe header: %w", err)
}

backends := status.Backends{
Version: hash,
Key: types.NamespacedName{
Name: ing.Name,
Namespace: ing.Namespace,
},
Version: ingressHash,
Key: probeKey,
}

probe, _ := c.statusManager.IsProbeActive(probeKey)

for _, rule := range ing.Spec.Rules {
rule := rule

httproute, err := c.reconcileHTTPRoute(ctx, &hash, ing, &rule)
httproute, routeHash, err := c.reconcileHTTPRoute(ctx, probe, ingressHash, ing, &rule)
if err != nil {
return err
}

backends.Version = routeHash

if isHTTPRouteReady(httproute) {
ing.Status.MarkNetworkConfigured()
gatherProbes(&backends, httproute, rule.Visibility)
Expand All @@ -124,9 +129,6 @@ func (c *Reconciler) reconcileIngress(ctx context.Context, ing *v1alpha1.Ingress
}
}

// Hash might have changed depending on HTTPRoute reconciliation
backends.Version = hash

externalIngressTLS := ing.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP)
listeners := make([]*gatewayapi.Listener, 0, len(externalIngressTLS))
for _, tls := range externalIngressTLS {
Expand Down
Loading