You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by kv...@apache.org on 2022/03/06 13:59:03 UTC

[apisix-ingress-controller] branch master updated: chore: shorten the route name for Ingress transformations (#898)

This is an automated email from the ASF dual-hosted git repository.

kvn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git


The following commit(s) were added to refs/heads/master by this push:
     new 8348d01  chore: shorten the route name for Ingress transformations (#898)
8348d01 is described below

commit 8348d010507f679a17f6126e779780c76358446c
Author: Jintao Zhang <zh...@gmail.com>
AuthorDate: Sun Mar 6 21:58:57 2022 +0800

    chore: shorten the route name for Ingress transformations (#898)
    
    Signed-off-by: Jintao Zhang <zh...@gmail.com>
---
 pkg/kube/translation/ingress.go | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/pkg/kube/translation/ingress.go b/pkg/kube/translation/ingress.go
index 48fe18d..aa17b4b 100644
--- a/pkg/kube/translation/ingress.go
+++ b/pkg/kube/translation/ingress.go
@@ -123,7 +123,7 @@ func (t *translator) translateIngressV1(ing *networkingv1.Ingress) (*TranslateCo
 				}
 			}
 			route := apisixv1.NewDefaultRoute()
-			route.Name = composeIngressRouteName(rule.Host, pathRule.Path)
+			route.Name = composeIngressRouteName(ing.Namespace, ing.Name, rule.Host, pathRule.Path)
 			route.ID = id.GenID(route.Name)
 			route.Host = rule.Host
 			route.Uris = uris
@@ -240,7 +240,7 @@ func (t *translator) translateIngressV1beta1(ing *networkingv1beta1.Ingress) (*T
 				}
 			}
 			route := apisixv1.NewDefaultRoute()
-			route.Name = composeIngressRouteName(rule.Host, pathRule.Path)
+			route.Name = composeIngressRouteName(ing.Namespace, ing.Name, rule.Host, pathRule.Path)
 			route.ID = id.GenID(route.Name)
 			route.Host = rule.Host
 			route.Uris = uris
@@ -360,7 +360,7 @@ func (t *translator) translateIngressExtensionsV1beta1(ing *extensionsv1beta1.In
 				}
 			}
 			route := apisixv1.NewDefaultRoute()
-			route.Name = composeIngressRouteName(rule.Host, pathRule.Path)
+			route.Name = composeIngressRouteName(ing.Namespace, ing.Name, rule.Host, pathRule.Path)
 			route.ID = id.GenID(route.Name)
 			route.Host = rule.Host
 			route.Uris = uris
@@ -423,18 +423,27 @@ func (t *translator) translateUpstreamFromIngressV1beta1(namespace string, svcNa
 	return ups, nil
 }
 
-func composeIngressRouteName(host, path string) string {
-	p := make([]byte, 0, len(host)+len(path)+len("ingress")+2)
+// In the past, we used host + path directly to form its route name for readability,
+// but this method can cause problems in some scenarios.
+// For example, the generated name is too long.
+// The current APISIX limit its maximum length to 100.
+// ref: https://github.com/apache/apisix-ingress-controller/issues/781
+// We will construct the following structure for easy reading and debugging.
+// ing_namespace_ingressName_id
+func composeIngressRouteName(namespace, name, host, path string) string {
+	pID := id.GenID(host + path)
+	p := make([]byte, 0, len(namespace)+len(name)+len("ing")+len(pID)+3)
 	buf := bytes.NewBuffer(p)
 
-	buf.WriteString("ingress")
+	buf.WriteString("ing")
+	buf.WriteByte('_')
+	buf.WriteString(namespace)
 	buf.WriteByte('_')
-	buf.WriteString(host)
+	buf.WriteString(name)
 	buf.WriteByte('_')
-	buf.WriteString(path)
+	buf.WriteString(pID)
 
 	return buf.String()
-
 }
 
 func composeIngressPluginName(svc, name string) string {