Skip to content

Commit 9a3a2f3

Browse files
committed
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 <nnz1024@gmail.com>
1 parent d4cc9bf commit 9a3a2f3

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

pkg/router/contour.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ type ContourRouter struct {
4646

4747
// Reconcile creates or updates the HTTP proxy
4848
func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
49-
const annotation = "projectcontour.io/ingress.class"
5049

5150
apexName, primaryName, canaryName := canary.GetServiceNames()
5251

@@ -163,6 +162,10 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
163162
}
164163
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
165164

165+
if cr.ingressClass != "" {
166+
newSpec.IngressClassName = cr.ingressClass
167+
}
168+
166169
proxy, err := cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{})
167170
if errors.IsNotFound(err) {
168171
proxy = &contourv1.HTTPProxy{
@@ -189,10 +192,7 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
189192
}
190193

191194
if cr.ingressClass != "" {
192-
if proxy.Annotations == nil {
193-
proxy.Annotations = make(map[string]string)
194-
}
195-
proxy.Annotations[annotation] = cr.ingressClass
195+
proxy.Spec.IngressClassName = cr.ingressClass
196196
}
197197

198198
_, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Create(context.TODO(), proxy, metav1.CreateOptions{})
@@ -382,6 +382,10 @@ func (cr *ContourRouter) SetRoutes(
382382
}
383383
}
384384

385+
if cr.ingressClass != "" {
386+
proxy.Spec.IngressClassName = cr.ingressClass
387+
}
388+
385389
_, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Update(context.TODO(), proxy, metav1.UpdateOptions{})
386390
if err != nil {
387391
return fmt.Errorf("HTTPProxy %s.%s update error: %w", apexName, canary.Namespace, err)

0 commit comments

Comments
 (0)