Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/router/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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{
Expand All @@ -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{})
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
4 changes: 2 additions & 2 deletions test/contour/test-canary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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'
Loading