Skip to content

Commit 5c3cb90

Browse files
authored
Merge pull request #1870 from nnz1024/contour-ingress-class
Set ingress class via ingressClassName for Contour HTTPProxy
2 parents f7e42a8 + fa5cc76 commit 5c3cb90

3 files changed

Lines changed: 12 additions & 8 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)

pkg/router/contour_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestContourRouter_Reconcile(t *testing.T) {
5050
require.Len(t, services, 2)
5151
assert.Equal(t, int64(100), services[0].Weight)
5252
assert.Equal(t, int64(0), services[1].Weight)
53-
assert.Equal(t, "contour", proxy.Annotations["projectcontour.io/ingress.class"])
53+
assert.Equal(t, "contour", proxy.Spec.IngressClassName)
5454

5555
// test update
5656
cd, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})

test/contour/test-canary.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ until ${ok}; do
9090
fi
9191
done
9292

93-
kubectl -n test get httpproxy podinfo -oyaml | grep 'projectcontour.io/ingress.class: contour'
93+
kubectl -n test get httpproxy podinfo -oyaml | grep 'ingressClassName: contour'
9494

9595
echo '✔ Canary initialization test passed'
9696

@@ -269,4 +269,4 @@ echo '✔ A/B testing promotion test passed'
269269

270270
kubectl -n projectcontour logs deployment/flagger
271271

272-
echo '✔ All tests passed'
272+
echo '✔ All tests passed'

0 commit comments

Comments
 (0)