11package stream
22
3+ import "github.com/envoyproxy/go-control-plane/pkg/server/config"
4+
35const (
46 explicitWildcard = "*"
57)
@@ -9,10 +11,10 @@ type Subscription struct {
911 // wildcard indicates if the subscription currently has a wildcard watch.
1012 wildcard bool
1113
12- // allowLegacyWildcard indicates that the stream never provided any resource
13- // and is de facto wildcard.
14- // As soon as a resource or an explicit subscription to wildcard is provided,
15- // this flag will be set to false
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.
1618 allowLegacyWildcard bool
1719
1820 // subscribedResourceNames provides the resources explicitly requested by the client
@@ -24,10 +26,19 @@ type Subscription struct {
2426}
2527
2628// newSubscription initializes a subscription state.
27- func newSubscription (wildcard bool , initialResourceVersions map [string ]string ) Subscription {
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+
2840 state := Subscription {
29- wildcard : wildcard ,
30- allowLegacyWildcard : wildcard ,
41+ allowLegacyWildcard : allowLegacyWildcard ,
3142 subscribedResourceNames : map [string ]struct {}{},
3243 returnedResources : initialResourceVersions ,
3344 }
@@ -39,8 +50,8 @@ func newSubscription(wildcard bool, initialResourceVersions map[string]string) S
3950 return state
4051}
4152
42- func NewSotwSubscription (subscribed []string ) Subscription {
43- sub := newSubscription (len (subscribed ) == 0 , nil )
53+ func NewSotwSubscription (subscribed []string , opts config. Opts , typeURL string ) Subscription {
54+ sub := newSubscription (len (subscribed ) == 0 , nil , opts , typeURL )
4455 sub .SetResourceSubscription (subscribed )
4556 return sub
4657}
@@ -55,6 +66,7 @@ func (s *Subscription) SetResourceSubscription(subscribed []string) {
5566 if len (subscribed ) == 0 {
5667 // We were wildcard based on legacy behavior and still don't request any resource
5768 // The watch remains wildcard
69+ s .wildcard = true
5870 return
5971 }
6072
@@ -90,8 +102,8 @@ func (s *Subscription) SetResourceSubscription(subscribed []string) {
90102 s .subscribedResourceNames = subscribedResources
91103}
92104
93- func NewDeltaSubscription (subscribed , unsubscribed []string , initialResourceVersions map [string ]string ) Subscription {
94- sub := newSubscription (len (subscribed ) == 0 , initialResourceVersions )
105+ func NewDeltaSubscription (subscribed , unsubscribed []string , initialResourceVersions map [string ]string , opts config. Opts , typeURL string ) Subscription {
106+ sub := newSubscription (len (subscribed ) == 0 , initialResourceVersions , opts , typeURL )
95107 sub .UpdateResourceSubscriptions (subscribed , unsubscribed )
96108 return sub
97109}
@@ -107,6 +119,7 @@ func (s *Subscription) UpdateResourceSubscriptions(subscribed, unsubscribed []st
107119 if len (subscribed ) == 0 {
108120 // We were wildcard based on legacy behavior and still don't request any resource
109121 // The watch remains wildcard
122+ s .wildcard = true
110123 return
111124 }
112125
0 commit comments