From 442d207e94df451cc5c9dd8ba835fc51233946c5 Mon Sep 17 00:00:00 2001 From: Reto Lehmann Date: Fri, 31 Mar 2023 08:22:19 +0200 Subject: [PATCH] propagate annotations and labels from ingress --- cmd/controller/main.go | 1 + .../ingress/resources/destinationrule.go | 9 +++++++ .../ingress/resources/destinationrule_test.go | 25 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/cmd/controller/main.go b/cmd/controller/main.go index d50872813e..808ad732f2 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -32,6 +32,7 @@ func main() { // resilient to clusters containing malformed resources. v1beta1.VirtualServiceUnmarshaler.AllowUnknownFields = true v1beta1.GatewayUnmarshaler.AllowUnknownFields = true + v1beta1.DestinationRuleUnmarshaler.AllowUnknownFields = true ctx := informerfiltering.GetContextWithFilteringLabelSelector(signals.NewContext()) sharedmain.MainWithContext(ctx, "net-istio-controller", ingress.NewController, serverlessservice.NewController) diff --git a/pkg/reconciler/ingress/resources/destinationrule.go b/pkg/reconciler/ingress/resources/destinationrule.go index da3d11c996..69f50d7616 100644 --- a/pkg/reconciler/ingress/resources/destinationrule.go +++ b/pkg/reconciler/ingress/resources/destinationrule.go @@ -20,7 +20,9 @@ import ( istiov1alpha3 "istio.io/api/networking/v1alpha3" "istio.io/client-go/pkg/apis/networking/v1alpha3" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/networking/pkg/apis/networking" "knative.dev/networking/pkg/apis/networking/v1alpha1" + "knative.dev/pkg/kmap" "knative.dev/pkg/kmeta" ) @@ -40,6 +42,7 @@ func MakeInternalEncryptionDestinationRule(host string, ing *v1alpha1.Ingress, h Name: host, Namespace: ing.Namespace, OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(ing)}, + Annotations: ing.GetAnnotations(), }, Spec: istiov1alpha3.DestinationRule{ Host: host, @@ -53,6 +56,12 @@ func MakeInternalEncryptionDestinationRule(host string, ing *v1alpha1.Ingress, h }, } + // Populate the Ingress labels. + dr.Labels = kmap.Filter(ing.GetLabels(), func(k string) bool { + return k != RouteLabelKey && k != RouteNamespaceLabelKey + }) + dr.Labels[networking.IngressLabelKey] = ing.Name + if http2 { dr.Spec.TrafficPolicy.ConnectionPool = &istiov1alpha3.ConnectionPoolSettings{ Http: &istiov1alpha3.ConnectionPoolSettings_HTTPSettings{ diff --git a/pkg/reconciler/ingress/resources/destinationrule_test.go b/pkg/reconciler/ingress/resources/destinationrule_test.go index 6d216cfa9e..d316aa7c31 100644 --- a/pkg/reconciler/ingress/resources/destinationrule_test.go +++ b/pkg/reconciler/ingress/resources/destinationrule_test.go @@ -24,6 +24,7 @@ import ( istiov1alpha3 "istio.io/api/networking/v1alpha3" "istio.io/client-go/pkg/apis/networking/v1alpha3" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/networking/pkg/apis/networking" "knative.dev/networking/pkg/apis/networking/v1alpha1" "knative.dev/pkg/kmeta" ) @@ -34,6 +35,14 @@ var ( ObjectMeta: metav1.ObjectMeta{ Name: "my-ingress", Namespace: "my-namespace", + Annotations: map[string]string{ + "my-annotation": "my-value", + }, + Labels: map[string]string{ + "my-label": "my-value-ignored", + RouteLabelKey: "my-route", + RouteNamespaceLabelKey: "my-route-namespace", + }, }, } ) @@ -45,6 +54,14 @@ func TestMakeInternalEncryptionDestinationRuleHttp1(t *testing.T) { Name: host, Namespace: ing.Namespace, OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(ing)}, + Annotations: map[string]string{ + "my-annotation": "my-value", + }, + Labels: map[string]string{ + networking.IngressLabelKey: "my-ingress", + RouteLabelKey: "my-route", + RouteNamespaceLabelKey: "my-route-namespace", + }, }, Spec: istiov1alpha3.DestinationRule{ Host: host, @@ -70,6 +87,14 @@ func TestMakeInternalEncryptionDestinationRuleHttp2(t *testing.T) { Name: host, Namespace: ing.Namespace, OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(ing)}, + Annotations: map[string]string{ + "my-annotation": "my-value", + }, + Labels: map[string]string{ + networking.IngressLabelKey: "my-ingress", + RouteLabelKey: "my-route", + RouteNamespaceLabelKey: "my-route-namespace", + }, }, Spec: istiov1alpha3.DestinationRule{ Host: host,