Skip to content

Commit

Permalink
pass typemeta in ingress subtranslator (#6296)
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Jul 5, 2024
1 parent 13a8df8 commit ff56bce
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 77 deletions.
6 changes: 1 addition & 5 deletions internal/dataplane/translator/subtranslator/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,7 @@ func (m *ingressTranslationMeta) translateIntoKongRoute() *kongstate.Route {
routeName := m.backend.intoKongRouteName(k8stypes.NamespacedName{Namespace: m.ingressNamespace, Name: m.ingressName}, ingressHost)

route := &kongstate.Route{
Ingress: util.K8sObjectInfo{
Namespace: m.parentIngress.GetNamespace(),
Name: m.parentIngress.GetName(),
Annotations: m.parentIngress.GetAnnotations(),
},
Ingress: util.FromK8sObject(m.parentIngress),
Route: kong.Route{
Name: kong.String(routeName),
StripPath: kong.Bool(false),
Expand Down
6 changes: 1 addition & 5 deletions internal/dataplane/translator/subtranslator/ingress_atc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ func (m *ingressTranslationMeta) translateIntoKongExpressionRoute() *kongstate.R
)

route := &kongstate.Route{
Ingress: util.K8sObjectInfo{
Namespace: m.parentIngress.GetNamespace(),
Name: m.parentIngress.GetName(),
Annotations: m.parentIngress.GetAnnotations(),
},
Ingress: util.FromK8sObject(m.parentIngress),
Route: kong.Route{
Name: kong.String(routeName),
StripPath: kong.Bool(false),
Expand Down
29 changes: 19 additions & 10 deletions internal/dataplane/translator/subtranslator/ingress_atc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestTranslateIngressATC(t *testing.T) {
{
name: "a basic ingress resource with a single rule and prefix path type",
ingress: &netv1.Ingress{
TypeMeta: ingressTypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "test-ingress",
Namespace: corev1.NamespaceDefault,
Expand Down Expand Up @@ -74,8 +75,9 @@ func TestTranslateIngressATC(t *testing.T) {
},
Routes: []kongstate.Route{{
Ingress: util.K8sObjectInfo{
Name: "test-ingress",
Namespace: corev1.NamespaceDefault,
Name: "test-ingress",
Namespace: corev1.NamespaceDefault,
GroupVersionKind: ingressGVK,
},
Route: kong.Route{
Name: kong.String("default.test-ingress.test-service.konghq.com.80"),
Expand All @@ -90,7 +92,7 @@ func TestTranslateIngressATC(t *testing.T) {
StripPath: kong.Bool(false),
ResponseBuffering: kong.Bool(true),
RequestBuffering: kong.Bool(true),
Tags: kong.StringSlice("k8s-name:test-ingress", "k8s-namespace:default"),
Tags: kong.StringSlice("k8s-name:test-ingress", "k8s-namespace:default", "k8s-kind:Ingress", "k8s-group:networking.k8s.io", "k8s-version:v1"),
},
ExpressionRoutes: true,
}},
Expand All @@ -106,6 +108,7 @@ func TestTranslateIngressATC(t *testing.T) {
{
name: "a basic ingress resource with a single rule, and only one path results in a single kong service and route",
ingress: &netv1.Ingress{
TypeMeta: ingressTypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "test-ingress",
Namespace: corev1.NamespaceDefault,
Expand Down Expand Up @@ -148,8 +151,9 @@ func TestTranslateIngressATC(t *testing.T) {
},
Routes: []kongstate.Route{{
Ingress: util.K8sObjectInfo{
Name: "test-ingress",
Namespace: corev1.NamespaceDefault,
Name: "test-ingress",
Namespace: corev1.NamespaceDefault,
GroupVersionKind: ingressGVK,
},
Route: kong.Route{
Name: kong.String("default.test-ingress.test-service.konghq.com.80"),
Expand All @@ -164,7 +168,7 @@ func TestTranslateIngressATC(t *testing.T) {
StripPath: kong.Bool(false),
ResponseBuffering: kong.Bool(true),
RequestBuffering: kong.Bool(true),
Tags: kong.StringSlice("k8s-name:test-ingress", "k8s-namespace:default"),
Tags: kong.StringSlice("k8s-name:test-ingress", "k8s-namespace:default", "k8s-kind:Ingress", "k8s-group:networking.k8s.io", "k8s-version:v1"),
},
ExpressionRoutes: true,
}},
Expand All @@ -180,6 +184,7 @@ func TestTranslateIngressATC(t *testing.T) {
{
name: "an ingress with method, protocol, and header annotations",
ingress: &netv1.Ingress{
TypeMeta: ingressTypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "test-ingress-annotations",
Namespace: corev1.NamespaceDefault,
Expand Down Expand Up @@ -234,6 +239,7 @@ func TestTranslateIngressATC(t *testing.T) {
"konghq.com/protocols": "http",
"konghq.com/headers.foo": "bar",
},
GroupVersionKind: ingressGVK,
},
Route: kong.Route{
Name: kong.String("default.test-ingress-annotations.test-service.konghq.com.80"),
Expand All @@ -249,7 +255,7 @@ func TestTranslateIngressATC(t *testing.T) {
StripPath: kong.Bool(false),
ResponseBuffering: kong.Bool(true),
RequestBuffering: kong.Bool(true),
Tags: kong.StringSlice("k8s-name:test-ingress-annotations", "k8s-namespace:default"),
Tags: kong.StringSlice("k8s-name:test-ingress-annotations", "k8s-namespace:default", "k8s-kind:Ingress", "k8s-group:networking.k8s.io", "k8s-version:v1"),
},
ExpressionRoutes: true,
}},
Expand All @@ -276,6 +282,7 @@ func TestTranslateIngressATC(t *testing.T) {
{
name: "KongServiceFacade used as a backend",
ingress: &netv1.Ingress{
TypeMeta: ingressTypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "test-ingress",
Namespace: "default",
Expand Down Expand Up @@ -334,8 +341,9 @@ func TestTranslateIngressATC(t *testing.T) {
},
Routes: []kongstate.Route{{
Ingress: util.K8sObjectInfo{
Name: "test-ingress",
Namespace: corev1.NamespaceDefault,
Name: "test-ingress",
Namespace: corev1.NamespaceDefault,
GroupVersionKind: ingressGVK,
},
Route: kong.Route{
Name: kong.String("default.test-ingress.konghq.com.svc-facade.svc.facade"),
Expand All @@ -350,7 +358,7 @@ func TestTranslateIngressATC(t *testing.T) {
StripPath: kong.Bool(false),
ResponseBuffering: kong.Bool(true),
RequestBuffering: kong.Bool(true),
Tags: kong.StringSlice("k8s-name:test-ingress", "k8s-namespace:default"),
Tags: kong.StringSlice("k8s-name:test-ingress", "k8s-namespace:default", "k8s-kind:Ingress", "k8s-group:networking.k8s.io", "k8s-version:v1"),
},
ExpressionRoutes: true,
}},
Expand All @@ -377,6 +385,7 @@ func TestTranslateIngressATC(t *testing.T) {
{
name: "not existing KongServiceFacade used as a backend",
ingress: &netv1.Ingress{
TypeMeta: ingressTypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "test-ingress",
Namespace: "default",
Expand Down
Loading

0 comments on commit ff56bce

Please sign in to comment.