Merge pull request #1870 from nnz1024/contour-ingress-class

Set ingress class via ingressClassName for Contour HTTPProxy
This commit is contained in:
Sanskar Jaiswal
2026-04-17 12:08:31 +05:30
committed by GitHub
3 changed files with 12 additions and 8 deletions
+9 -5
View File
@@ -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)
+1 -1
View File
@@ -50,7 +50,7 @@ func TestContourRouter_Reconcile(t *testing.T) {
require.Len(t, services, 2)
assert.Equal(t, int64(100), services[0].Weight)
assert.Equal(t, int64(0), services[1].Weight)
assert.Equal(t, "contour", proxy.Annotations["projectcontour.io/ingress.class"])
assert.Equal(t, "contour", proxy.Spec.IngressClassName)
// test update
cd, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
+2 -2
View File
@@ -90,7 +90,7 @@ until ${ok}; do
fi
done
kubectl -n test get httpproxy podinfo -oyaml | grep 'projectcontour.io/ingress.class: contour'
kubectl -n test get httpproxy podinfo -oyaml | grep 'ingressClassName: contour'
echo '✔ Canary initialization test passed'
@@ -269,4 +269,4 @@ echo '✔ A/B testing promotion test passed'
kubectl -n projectcontour logs deployment/flagger
echo '✔ All tests passed'
echo '✔ All tests passed'