From 33142a4dec405edc90722b591823149370c4e93c Mon Sep 17 00:00:00 2001 From: Sergey Ptashnik Date: Fri, 30 Jan 2026 19:26:17 +0300 Subject: [PATCH] Set ingress class via ingressClassName for Contour Since version 1.18 (released in July 2021), Contour supports field HTTPProxy.spec.ingressClassName as a way to specify ingress class for HTTPProxy. Using this field allows to avoid problems emerging from improper annotation cleanup, diffing and copying (see issue #1848). Signed-off-by: Sergey Ptashnik --- pkg/router/contour.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/router/contour.go b/pkg/router/contour.go index ebb2ddea..da0b5134 100644 --- a/pkg/router/contour.go +++ b/pkg/router/contour.go @@ -46,7 +46,6 @@ type ContourRouter struct { // Reconcile creates or updates the HTTP proxy func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error { - const annotation = "projectcontour.io/ingress.class" apexName, primaryName, canaryName := canary.GetServiceNames() @@ -163,6 +162,10 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error { } newMetadata.Annotations = filterMetadata(newMetadata.Annotations) + if cr.ingressClass != "" { + newSpec.IngressClassName = cr.ingressClass + } + proxy, err := cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{}) if errors.IsNotFound(err) { proxy = &contourv1.HTTPProxy{ @@ -189,10 +192,7 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error { } if cr.ingressClass != "" { - if proxy.Annotations == nil { - proxy.Annotations = make(map[string]string) - } - proxy.Annotations[annotation] = cr.ingressClass + proxy.Spec.IngressClassName = cr.ingressClass } _, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Create(context.TODO(), proxy, metav1.CreateOptions{}) @@ -382,6 +382,10 @@ func (cr *ContourRouter) SetRoutes( } } + if cr.ingressClass != "" { + proxy.Spec.IngressClassName = cr.ingressClass + } + _, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Update(context.TODO(), proxy, metav1.UpdateOptions{}) if err != nil { return fmt.Errorf("HTTPProxy %s.%s update error: %w", apexName, canary.Namespace, err)