mirror of
https://github.com/fluxcd/flagger.git
synced 2026-09-05 02:47:17 +00:00
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>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user