Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4
knative.dev/caching v0.0.0-20260310014150-a5ed06aee227
knative.dev/hack v0.0.0-20260310014051-c448fdb867e2
knative.dev/networking v0.0.0-20260310141215-8340ed7fd0e1
knative.dev/networking v0.0.0-20260313010219-0055e9277729
knative.dev/pkg v0.0.0-20260310013839-5504026dd1b6
sigs.k8s.io/randfill v1.0.0
sigs.k8s.io/yaml v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ knative.dev/caching v0.0.0-20260310014150-a5ed06aee227 h1:/cRSCs/jiJoxwQ1NL3KJWp
knative.dev/caching v0.0.0-20260310014150-a5ed06aee227/go.mod h1:NlTx/oxLKjMnMjoHbE4OtlPkHMu9IVdSl7eJCmXhUiI=
knative.dev/hack v0.0.0-20260310014051-c448fdb867e2 h1:b35SGLEp03D8oGf8mE9HBt3yfNgYpAK0fw46hFXs9w4=
knative.dev/hack v0.0.0-20260310014051-c448fdb867e2/go.mod h1:L5RzHgbvam0u8QFHfzCX6MKxu/a/gIGEdaRBqNiVbl0=
knative.dev/networking v0.0.0-20260310141215-8340ed7fd0e1 h1:MA7om/7ZLLj7dXmaHTUCoGOgd8AfCCdsKvBPBhPtisg=
knative.dev/networking v0.0.0-20260310141215-8340ed7fd0e1/go.mod h1:72PhQ+qnOAwz9FFK8y301eWuiQ6vD9qVUFnDBjNhju8=
knative.dev/networking v0.0.0-20260313010219-0055e9277729 h1:sF6e1RnluIKCiZBPrz7BxIWkAkLU8hiSSK+1NusRmGM=
knative.dev/networking v0.0.0-20260313010219-0055e9277729/go.mod h1:72PhQ+qnOAwz9FFK8y301eWuiQ6vD9qVUFnDBjNhju8=
knative.dev/pkg v0.0.0-20260310013839-5504026dd1b6 h1:oVpQ0Y+FUmRQer8kdqJjQL20KveZa5sCfnBWeJi4nyQ=
knative.dev/pkg v0.0.0-20260310013839-5504026dd1b6/go.mod h1:ziEj0TQOWvBw7t/VSkqaZlv++Qk8FfiuI72ZDmv23nI=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
Expand Down
49 changes: 41 additions & 8 deletions pkg/reconciler/route/resources/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ func MakeIngressWithRollout(
ingressClass string,
acmeChallenges ...netv1alpha1.HTTP01Challenge,
) (*netv1alpha1.Ingress, error) {
spec, err := makeIngressSpec(ctx, r, tls, tc, ro, acmeChallenges...)
spec, tagToHost, err := makeIngressSpec(ctx, r, tls, tc, ro, acmeChallenges...)
if err != nil {
return nil, err
}
return &netv1alpha1.Ingress{

ing := &netv1alpha1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: names.Ingress(r),
Namespace: r.Namespace,
Expand All @@ -98,7 +99,24 @@ func MakeIngressWithRollout(
OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(r)},
},
Spec: spec,
}, nil
}

if len(tagToHost) > 0 {
ing.Annotations[networking.TagToHostAnnotationKey] = serializeTagToHostMap(ctx, tagToHost)
}

return ing, nil
}

func serializeTagToHostMap(ctx context.Context, mapping map[string][]string) string {
sr, err := json.Marshal(mapping)
if err != nil {
// This must never happen in the normal course of things.
logging.FromContext(ctx).Warnw("Error serializing tag to host mapping: "+spew.Sprint(mapping),
zap.Error(err))
return ""
}
return string(sr)
}

func serializeRollout(ctx context.Context, r *traffic.Rollout) string {
Expand All @@ -120,7 +138,9 @@ func makeIngressSpec(
tc *traffic.Config,
ro *traffic.Rollout,
acmeChallenges ...netv1alpha1.HTTP01Challenge,
) (netv1alpha1.IngressSpec, error) {
) (netv1alpha1.IngressSpec, map[string][]string, error) {
tagToHost := make(map[string][]string)

// Domain should have been specified in route status
// before calling this func.
names := make([]string, 0, len(tc.Targets))
Expand Down Expand Up @@ -152,7 +172,7 @@ func makeIngressSpec(
for _, visibility := range visibilities {
domains, err := domains.GetDomainsForVisibility(ctx, name, r, visibility)
if err != nil {
return netv1alpha1.IngressSpec{}, err
return netv1alpha1.IngressSpec{}, nil, err
}
domainRules := makeIngressRules(domains, r.Namespace,
visibility, tc.Targets[name], ro.RolloutsByTag(name), networkConfig.SystemInternalTLSEnabled())
Expand Down Expand Up @@ -205,19 +225,32 @@ func makeIngressSpec(
}

rules = append(rules, domainRules...)

if name != traffic.DefaultTarget {
longestDomain := ""
for d := range domains {
if len(longestDomain) < len(d) {
longestDomain = d
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this works but was wondering whether this is the best solution.
I checked GetDomainsForVisibility which only seems to be used in 3 places in total (1 is a test) - we could return the "primary domain" besides the current domains and have a deterministic choice?
Just a suggestion - I'm also fine with the current approach 😀

/lgtm
/retest
/hold in case you want to change this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - please take a look


tagToHost[name] = append(tagToHost[name], longestDomain)
}
}
}

httpOption, err := servingnetworking.GetHTTPOption(ctx, config.FromContext(ctx).Network, r.GetAnnotations())
if err != nil {
return netv1alpha1.IngressSpec{}, err
return netv1alpha1.IngressSpec{}, nil, err
}

return netv1alpha1.IngressSpec{
spec := netv1alpha1.IngressSpec{
Rules: rules,
TLS: tls,
HTTPOption: httpOption,
}, nil
}

return spec, tagToHost, nil
}

// MakeACMEIngressPath converts an ACME challenge into an HTTPIngressPath.
Expand Down
14 changes: 8 additions & 6 deletions pkg/reconciler/route/resources/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func TestMakeIngressWithTaggedRollout(t *testing.T) {
networking.IngressClassAnnotationKey: ingressClass,
networking.RolloutAnnotationKey: `{"configurations":[{"configurationName":"valhalla","percent":100,"revisions":[{"revisionName":"valhalla-01982","percent":100}],"stepParams":{}},{"configurationName":"thor","tag":"tagged","percent":100,"revisions":[{"revisionName":"thor-02020","percent":100}],"stepParams":{}}]}`,
"test-annotation": "bar",
networking.TagToHostAnnotationKey: `{"tagged":["tagged-test-route.test-ns.svc.cluster.local","tagged-test-route.test-ns.example.com"]}`,
},
OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(r)},
}
Expand Down Expand Up @@ -245,6 +246,7 @@ func TestMakeIngressWithActualRollout(t *testing.T) {
Annotations: map[string]string{
networking.IngressClassAnnotationKey: ingressClass,
networking.RolloutAnnotationKey: serializeRollout(context.Background(), ro),
networking.TagToHostAnnotationKey: `{"hammer":["hammer-test-route.test-ns.svc.cluster.local","hammer-test-route.test-ns.example.com"]}`,
},
OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(r)},
}
Expand Down Expand Up @@ -587,7 +589,7 @@ func TestMakeIngressSpecCorrectRules(t *testing.T) {

tc := &traffic.Config{Targets: targets}
ro := tc.BuildRollout()
ci, err := makeIngressSpec(testContext(), r, nil /*tls*/, tc, ro)
ci, _, err := makeIngressSpec(testContext(), r, nil /*tls*/, tc, ro)
if err != nil {
t.Error("Unexpected error", err)
}
Expand Down Expand Up @@ -662,7 +664,7 @@ func TestMakeIngressSpecCorrectRuleVisibility(t *testing.T) {
Visibility: c.serviceVisibility,
}
ro := tc.BuildRollout()
ci, err := makeIngressSpec(testContext(), c.route, nil /*tls*/, tc, ro)
ci, _, err := makeIngressSpec(testContext(), c.route, nil /*tls*/, tc, ro)
if err != nil {
t.Error("Unexpected error", err)
}
Expand Down Expand Up @@ -842,7 +844,7 @@ func TestMakeIngressSpecCorrectRulesWithTagBasedRouting(t *testing.T) {

tc := &traffic.Config{Targets: targets}
ro := tc.BuildRollout()
ci, err := makeIngressSpec(ctx, r, nil /*tls*/, tc, ro)
ci, _, err := makeIngressSpec(ctx, r, nil /*tls*/, tc, ro)
if err != nil {
t.Error("Unexpected error", err)
}
Expand Down Expand Up @@ -1221,7 +1223,7 @@ func TestMakeIngressWithActivatorCA(t *testing.T) {

tc := &traffic.Config{Targets: targets}
ro := tc.BuildRollout()
ci, err := makeIngressSpec(testContextWithActivatorCA(), r, nil /*tls*/, tc, ro)
ci, _, err := makeIngressSpec(testContextWithActivatorCA(), r, nil /*tls*/, tc, ro)
if err != nil {
t.Error("Unexpected error", err)
}
Expand Down Expand Up @@ -1352,7 +1354,7 @@ func TestMakeIngressACMEChallenges(t *testing.T) {
}
ro := tc.BuildRollout()

ci, err := makeIngressSpec(testContext(), r, nil /*tls*/, tc, ro, acmeChallenge)
ci, _, err := makeIngressSpec(testContext(), r, nil /*tls*/, tc, ro, acmeChallenge)
if err != nil {
t.Error("Unexpected error", err)
}
Expand Down Expand Up @@ -1442,7 +1444,7 @@ func TestMakeIngressACMEChallengesWithTrafficTags(t *testing.T) {
}
ro := tc.BuildRollout()

ci, err := makeIngressSpec(testContext(), r, nil /*tls*/, tc, ro, acmeChallenges...)
ci, _, err := makeIngressSpec(testContext(), r, nil /*tls*/, tc, ro, acmeChallenges...)
if err != nil {
t.Fatal("Unexpected error", err)
}
Expand Down
6 changes: 3 additions & 3 deletions vendor/knative.dev/networking/pkg/apis/networking/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const (
// the rollout state in the Annotations of the Kingress or Route.Status.
RolloutAnnotationKey = GroupName + "/rollout"

// TagLabelKey is the label key attached to per-tag Ingress resources
// to indicate which traffic tag the Ingress corresponds to.
TagLabelKey = GroupName + "/tag"
// TagToHostAnnotationKey is the annotation key used for storing a JSON map of
// tags to host names
TagToHostAnnotationKey = GroupName + "/tag-to-host"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ knative.dev/caching/pkg/client/listers/caching/v1alpha1
# knative.dev/hack v0.0.0-20260310014051-c448fdb867e2
## explicit; go 1.24
knative.dev/hack
# knative.dev/networking v0.0.0-20260310141215-8340ed7fd0e1
# knative.dev/networking v0.0.0-20260313010219-0055e9277729
## explicit; go 1.25.0
knative.dev/networking/config
knative.dev/networking/pkg/apis/networking
Expand Down
Loading