Skip to content

Commit b1ab306

Browse files
authored
support exportTo specific namespaces (#24443)
* support exportTo specific namespaces Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io> * tests and bug fixes Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io> * enclose dot in quotes to differentiate from full stop Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io> * nits Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io> * update merge logic comments Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io> * merge if Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>
1 parent 4245e26 commit b1ab306

File tree

8 files changed

+756
-112
lines changed

8 files changed

+756
-112
lines changed

pilot/pkg/model/destination_rule.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,24 @@ import (
1818
"fmt"
1919

2020
networking "istio.io/api/networking/v1alpha3"
21+
22+
"istio.io/istio/pkg/config/visibility"
2123
)
2224

2325
// This function merges one or more destination rules for a given host string
2426
// into a single destination rule. Note that it does not perform inheritance style merging.
2527
// IOW, given three dest rules (*.foo.com, *.foo.com, *.com), calling this function for
2628
// each config will result in a final dest rule set (*.foo.com, and *.com).
27-
func (ps *PushContext) mergeDestinationRule(p *processedDestRules, destRuleConfig Config) {
29+
//
30+
// The following is the merge logic:
31+
// 1. Unique subsets (based on subset name) are concatenated to the original rule's list of subsets
32+
// 2. If the original rule did not have any top level traffic policy, traffic policies from the new rule will be
33+
// used.
34+
// 3. If the original rule did not have any exportTo, exportTo settings from the new rule will be used.
35+
func (ps *PushContext) mergeDestinationRule(p *processedDestRules, destRuleConfig Config, exportToMap map[visibility.Instance]bool) {
2836
rule := destRuleConfig.Spec.(*networking.DestinationRule)
2937
resolvedHost := ResolveShortnameToFQDN(rule.Host, destRuleConfig.ConfigMeta)
38+
3039
if mdr, exists := p.destRule[resolvedHost]; exists {
3140
// Deep copy destination rule, to prevent mutate it later when merge with a new one.
3241
// This can happen when there are more than one destination rule of same host in one namespace.
@@ -39,6 +48,8 @@ func (ps *PushContext) mergeDestinationRule(p *processedDestRules, destRuleConfi
3948
}
4049
// we have an another destination rule for same host.
4150
// concatenate both of them -- essentially add subsets from one to other.
51+
// Note: we only add the subsets and do not overwrite anything else like exportTo or top level
52+
// traffic policies if they already exist
4253
for _, subset := range rule.Subsets {
4354
if _, ok := existingSubset[subset.Name]; !ok {
4455
// if not duplicated, append
@@ -56,10 +67,18 @@ func (ps *PushContext) mergeDestinationRule(p *processedDestRules, destRuleConfi
5667
if mergedRule.TrafficPolicy == nil && rule.TrafficPolicy != nil {
5768
mergedRule.TrafficPolicy = rule.TrafficPolicy
5869
}
70+
71+
// If there is no exportTo in the existing rule and
72+
// the incoming rule has an explicit exportTo, use the
73+
// one from the incoming rule.
74+
if len(p.exportTo[resolvedHost]) == 0 && len(exportToMap) > 0 {
75+
p.exportTo[resolvedHost] = exportToMap
76+
}
5977
return
6078
}
6179

6280
// DestinationRule does not exist for the resolved host so add it
6381
p.hosts = append(p.hosts, resolvedHost)
6482
p.destRule[resolvedHost] = &destRuleConfig
83+
p.exportTo[resolvedHost] = exportToMap
6584
}

pilot/pkg/model/push_context.go

Lines changed: 147 additions & 85 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)