Skip to content

Commit 06e64e6

Browse files
committed
address comments
1 parent bf5f5af commit 06e64e6

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

pkg/server/config/config.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ func NewOpts() Opts {
2424
}
2525
}
2626

27-
// LegacyWildcardDeactivated returns whether legacy wildcard mode is deactivated for all resource types
28-
func (o Opts) LegacyWildcardDeactivated() bool {
29-
return o.legacyWildcardDeactivated
30-
}
31-
32-
// LegacyWildcardDeactivatedTypes returns the set of resource types for which legacy wildcard mode is deactivated
33-
func (o Opts) LegacyWildcardDeactivatedTypes() map[string]struct{} {
34-
return o.legacyWildcardDeactivatedTypes
27+
// IsLegacyWildcardActive returns whether legacy wildcard mode is active for the given resource type.
28+
// Returns true if legacy wildcard mode is active, false if it has been deactivated.
29+
func (o Opts) IsLegacyWildcardActive(typeURL string) bool {
30+
if o.legacyWildcardDeactivated {
31+
return false
32+
}
33+
if len(o.legacyWildcardDeactivatedTypes) > 0 {
34+
if _, found := o.legacyWildcardDeactivatedTypes[typeURL]; found {
35+
return false
36+
}
37+
}
38+
return true
3539
}
3640

3741
// Each xDS implementation should implement their own functional opts.

pkg/server/stream/v3/subscription.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ type Subscription struct {
1111
// wildcard indicates if the subscription currently has a wildcard watch.
1212
wildcard bool
1313

14-
// allowLegacyWildcard indicates that an empty request should be treated as a wildcard request.
15-
// If in the stream at some point subscribes explicitly a resource or a explicitly makes wildcard
16-
// request, then subsequent empty requests should not be treated as wildcard and so this
17-
// flag will be set to false.
14+
// allowLegacyWildcard indicates that the stream never provided any resource
15+
// and is de facto wildcard.
16+
// As soon as a resource or an explicit subscription to wildcard is provided,
17+
// this flag will be set to false
1818
allowLegacyWildcard bool
1919

2020
// subscribedResourceNames provides the resources explicitly requested by the client
@@ -26,17 +26,7 @@ type Subscription struct {
2626
}
2727

2828
// newSubscription initializes a subscription state.
29-
func newSubscription(emptyRequest bool, initialResourceVersions map[string]string, opts config.Opts, typeURL string) Subscription {
30-
allowLegacyWildcard := emptyRequest
31-
32-
if opts.LegacyWildcardDeactivated() {
33-
allowLegacyWildcard = false
34-
} else if typeMap := opts.LegacyWildcardDeactivatedTypes(); len(typeMap) > 0 {
35-
if _, found := typeMap[typeURL]; found {
36-
allowLegacyWildcard = false
37-
}
38-
}
39-
29+
func newSubscription(emptyRequest, allowLegacyWildcard bool, initialResourceVersions map[string]string) Subscription {
4030
// By default we set the subscription as a wildcard only if the request was empty
4131
// and in legacy mode. Later on, outside of this constructor, when we actually
4232
// process the request, if the request was non-empty, it may have an
@@ -59,7 +49,7 @@ func newSubscription(emptyRequest bool, initialResourceVersions map[string]strin
5949
}
6050

6151
func NewSotwSubscription(subscribed []string, opts config.Opts, typeURL string) Subscription {
62-
sub := newSubscription(len(subscribed) == 0, nil, opts, typeURL)
52+
sub := newSubscription(len(subscribed) == 0, opts.IsLegacyWildcardActive(typeURL), nil)
6353
sub.SetResourceSubscription(subscribed)
6454
return sub
6555
}
@@ -110,7 +100,7 @@ func (s *Subscription) SetResourceSubscription(subscribed []string) {
110100
}
111101

112102
func NewDeltaSubscription(subscribed, unsubscribed []string, initialResourceVersions map[string]string, opts config.Opts, typeURL string) Subscription {
113-
sub := newSubscription(len(subscribed) == 0, initialResourceVersions, opts, typeURL)
103+
sub := newSubscription(len(subscribed) == 0, opts.IsLegacyWildcardActive(typeURL), initialResourceVersions)
114104
sub.UpdateResourceSubscriptions(subscribed, unsubscribed)
115105
return sub
116106
}

0 commit comments

Comments
 (0)