Skip to content

Commit

Permalink
propagate annotations and labels from ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
ReToCode committed Mar 31, 2023
1 parent d5e7718 commit 442d207
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/ingress/resources/destinationrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand All @@ -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{
Expand Down
25 changes: 25 additions & 0 deletions pkg/reconciler/ingress/resources/destinationrule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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",
},
},
}
)
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 442d207

Please sign in to comment.