Skip to content

Commit acd4fd9

Browse files
committed
dont pass in opts to NewSubscription interface, just pass in if legacy mode is true
1 parent 06e64e6 commit acd4fd9

File tree

8 files changed

+31
-34
lines changed

8 files changed

+31
-34
lines changed

pkg/cache/v3/delta_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/envoyproxy/go-control-plane/pkg/cache/v3"
2020
"github.com/envoyproxy/go-control-plane/pkg/log"
2121
rsrc "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
22-
"github.com/envoyproxy/go-control-plane/pkg/server/config"
2322
"github.com/envoyproxy/go-control-plane/pkg/server/stream/v3"
2423
"github.com/envoyproxy/go-control-plane/pkg/test/resource/v3"
2524
)
@@ -40,7 +39,7 @@ func TestSnapshotCacheDeltaWatch(t *testing.T) {
4039
// Make our initial request as a wildcard to get all resources and make sure the wildcard requesting works as intended
4140
for _, typ := range testTypes {
4241
watches[typ] = make(chan cache.DeltaResponse, 1)
43-
subscriptions[typ] = stream.NewDeltaSubscription(nil, nil, nil, config.NewOpts(), typ)
42+
subscriptions[typ] = stream.NewDeltaSubscription(nil, nil, nil, true)
4443
_, err := c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
4544
Node: &core.Node{
4645
Id: "node",
@@ -121,7 +120,7 @@ func TestDeltaRemoveResources(t *testing.T) {
121120

122121
for _, typ := range testTypes {
123122
watches[typ] = make(chan cache.DeltaResponse, 1)
124-
sub := stream.NewDeltaSubscription(nil, nil, nil, config.NewOpts(), typ)
123+
sub := stream.NewDeltaSubscription(nil, nil, nil, true)
125124
subscriptions[typ] = &sub
126125
// We don't specify any resource name subscriptions here because we want to make sure we test wildcard
127126
// functionality. This means we should receive all resources back without requesting a subscription by name.
@@ -211,7 +210,7 @@ func TestConcurrentSetDeltaWatch(t *testing.T) {
211210
},
212211
TypeUrl: rsrc.EndpointType,
213212
ResourceNamesSubscribe: []string{clusterName},
214-
}, stream.NewDeltaSubscription([]string{clusterName}, nil, nil, config.NewOpts(), rsrc.EndpointType), responses)
213+
}, stream.NewDeltaSubscription([]string{clusterName}, nil, nil, true), responses)
215214

216215
require.NoError(t, err)
217216
defer cancel()
@@ -228,7 +227,7 @@ func TestSnapshotDeltaCacheWatchTimeout(t *testing.T) {
228227

229228
// Create a non-buffered channel that will block sends.
230229
watchCh := make(chan cache.DeltaResponse)
231-
sub := stream.NewDeltaSubscription(names[rsrc.EndpointType], nil, nil, config.NewOpts(), rsrc.EndpointType)
230+
sub := stream.NewDeltaSubscription(names[rsrc.EndpointType], nil, nil, true)
232231
_, err := c.CreateDeltaWatch(&discovery.DeltaDiscoveryRequest{
233232
Node: &core.Node{
234233
Id: key,
@@ -278,7 +277,7 @@ func TestSnapshotCacheDeltaWatchCancel(t *testing.T) {
278277
},
279278
TypeUrl: typ,
280279
ResourceNamesSubscribe: names[typ],
281-
}, stream.NewDeltaSubscription(names[typ], nil, nil, config.NewOpts(), typ), responses)
280+
}, stream.NewDeltaSubscription(names[typ], nil, nil, true), responses)
282281
require.NoError(t, err)
283282

284283
// Cancel the watch

pkg/cache/v3/linear_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/envoyproxy/go-control-plane/pkg/cache/types"
3333
"github.com/envoyproxy/go-control-plane/pkg/log"
3434
"github.com/envoyproxy/go-control-plane/pkg/resource/v3"
35-
"github.com/envoyproxy/go-control-plane/pkg/server/config"
3635
"github.com/envoyproxy/go-control-plane/pkg/server/stream/v3"
3736
)
3837

@@ -224,7 +223,7 @@ func hashResource(t *testing.T, resource types.Resource) string {
224223

225224
func createWildcardDeltaWatch(t *testing.T, initialReq bool, c *LinearCache, w chan DeltaResponse) {
226225
t.Helper()
227-
sub := stream.NewDeltaSubscription(nil, nil, nil, config.NewOpts(), testType)
226+
sub := stream.NewDeltaSubscription(nil, nil, nil, true)
228227
req := &DeltaRequest{TypeUrl: testType}
229228
if !initialReq {
230229
req.ResponseNonce = "1"
@@ -238,7 +237,7 @@ func createWildcardDeltaWatch(t *testing.T, initialReq bool, c *LinearCache, w c
238237
}
239238

240239
func subFromRequest(req *Request) stream.Subscription {
241-
return stream.NewSotwSubscription(req.GetResourceNames(), config.NewOpts(), req.GetTypeUrl())
240+
return stream.NewSotwSubscription(req.GetResourceNames(), true)
242241
}
243242

244243
// This method represents the expected behavior of client and servers regarding the request and the subscription.
@@ -251,7 +250,7 @@ func updateFromSotwResponse(resp Response, sub *stream.Subscription, req *Reques
251250
}
252251

253252
func subFromDeltaRequest(req *DeltaRequest) stream.Subscription {
254-
return stream.NewDeltaSubscription(req.GetResourceNamesSubscribe(), req.GetResourceNamesUnsubscribe(), req.GetInitialResourceVersions(), config.NewOpts(), req.GetTypeUrl())
253+
return stream.NewDeltaSubscription(req.GetResourceNamesSubscribe(), req.GetResourceNamesUnsubscribe(), req.GetInitialResourceVersions(), true)
255254
}
256255

257256
func TestLinearInitialResources(t *testing.T) {

pkg/cache/v3/simple_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/envoyproxy/go-control-plane/pkg/cache/v3"
3737
"github.com/envoyproxy/go-control-plane/pkg/log"
3838
rsrc "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
39-
"github.com/envoyproxy/go-control-plane/pkg/server/config"
4039
"github.com/envoyproxy/go-control-plane/pkg/server/stream/v3"
4140
"github.com/envoyproxy/go-control-plane/pkg/test/resource/v3"
4241
)
@@ -55,7 +54,7 @@ func (group) ID(node *core.Node) string {
5554
}
5655

5756
func subFromRequest(req *cache.Request) stream.Subscription {
58-
return stream.NewSotwSubscription(req.GetResourceNames(), config.NewOpts(), req.GetTypeUrl())
57+
return stream.NewSotwSubscription(req.GetResourceNames(), true)
5958
}
6059

6160
// This method represents the expected behavior of client and servers regarding the request and the subscription.
@@ -602,7 +601,7 @@ func TestAvertPanicForWatchOnNonExistentSnapshot(t *testing.T) {
602601
ResourceNames: []string{"rtds"},
603602
TypeUrl: rsrc.RuntimeType,
604603
}
605-
ss := stream.NewSotwSubscription([]string{"rtds"}, config.NewOpts(), rsrc.RuntimeType)
604+
ss := stream.NewSotwSubscription([]string{"rtds"}, true)
606605
ss.SetReturnedResources(map[string]string{"cluster": "abcdef"})
607606
responder := make(chan cache.Response)
608607
_, err := c.CreateWatch(req, ss, responder)

pkg/server/delta/v3/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (s *server) processDelta(str stream.DeltaStream, reqCh <-chan *discovery.De
218218
// We also set the subscription as wildcard based on its legacy meaning (no resource name sent in resource_names_subscribe).
219219
// If the subscription starts with this legacy mode, adding new resources will not unsubscribe from wildcard.
220220
// It can still be done by explicitly unsubscribing from "*"
221-
watch.subscription = stream.NewDeltaSubscription(req.GetResourceNamesSubscribe(), req.GetResourceNamesUnsubscribe(), req.GetInitialResourceVersions(), s.opts, typeURL)
221+
watch.subscription = stream.NewDeltaSubscription(req.GetResourceNamesSubscribe(), req.GetResourceNamesUnsubscribe(), req.GetInitialResourceVersions(), s.opts.IsLegacyWildcardActive(typeURL))
222222
} else {
223223
watch.Cancel()
224224

pkg/server/sotw/v3/ads.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (s *server) processADS(sw *streamWrapper, reqCh chan *discovery.DiscoveryRe
107107
subscription.SetResourceSubscription(req.GetResourceNames())
108108
} else {
109109
s.opts.Logger.Debugf("[sotw ads] New subscription for type %s and stream %d", typeURL, sw.ID)
110-
subscription = stream.NewSotwSubscription(req.GetResourceNames(), s.opts, typeURL)
110+
subscription = stream.NewSotwSubscription(req.GetResourceNames(), s.opts.IsLegacyWildcardActive(typeURL))
111111
}
112112

113113
cancel, err := s.cache.CreateWatch(req, subscription, respChan)

pkg/server/sotw/v3/xds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (s *server) process(str stream.Stream, reqCh chan *discovery.DiscoveryReque
128128
subscription.SetResourceSubscription(req.GetResourceNames())
129129
} else {
130130
s.opts.Logger.Debugf("[sotw] New subscription for type %s and stream %d", typeURL, sw.ID)
131-
subscription = stream.NewSotwSubscription(req.GetResourceNames(), s.opts, typeURL)
131+
subscription = stream.NewSotwSubscription(req.GetResourceNames(), s.opts.IsLegacyWildcardActive(typeURL))
132132
}
133133

134134
responder := make(chan cache.Response, 1)

pkg/server/stream/v3/subscription.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package stream
22

3-
import "github.com/envoyproxy/go-control-plane/pkg/server/config"
4-
53
const (
64
explicitWildcard = "*"
75
)
@@ -48,8 +46,8 @@ func newSubscription(emptyRequest, allowLegacyWildcard bool, initialResourceVers
4846
return state
4947
}
5048

51-
func NewSotwSubscription(subscribed []string, opts config.Opts, typeURL string) Subscription {
52-
sub := newSubscription(len(subscribed) == 0, opts.IsLegacyWildcardActive(typeURL), nil)
49+
func NewSotwSubscription(subscribed []string, allowLegacyWildcard bool) Subscription {
50+
sub := newSubscription(len(subscribed) == 0, allowLegacyWildcard, nil)
5351
sub.SetResourceSubscription(subscribed)
5452
return sub
5553
}
@@ -99,8 +97,8 @@ func (s *Subscription) SetResourceSubscription(subscribed []string) {
9997
s.subscribedResourceNames = subscribedResources
10098
}
10199

102-
func NewDeltaSubscription(subscribed, unsubscribed []string, initialResourceVersions map[string]string, opts config.Opts, typeURL string) Subscription {
103-
sub := newSubscription(len(subscribed) == 0, opts.IsLegacyWildcardActive(typeURL), initialResourceVersions)
100+
func NewDeltaSubscription(subscribed, unsubscribed []string, initialResourceVersions map[string]string, allowLegacyWildcard bool) Subscription {
101+
sub := newSubscription(len(subscribed) == 0, allowLegacyWildcard, initialResourceVersions)
104102
sub.UpdateResourceSubscriptions(subscribed, unsubscribed)
105103
return sub
106104
}

pkg/server/stream/v3/subscription_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestSotwSubscriptions(t *testing.T) {
1212
t.Run("legacy mode properly handled", func(t *testing.T) {
13-
sub := NewSotwSubscription([]string{}, config.NewOpts(), "")
13+
sub := NewSotwSubscription([]string{}, true)
1414
assert.True(t, sub.IsWildcard())
1515

1616
// Requests always set empty in legacy mode
@@ -37,7 +37,7 @@ func TestSotwSubscriptions(t *testing.T) {
3737

3838
t.Run("new wildcard mode from start", func(t *testing.T) {
3939
// A resource is provided so the subscription was created in wildcard
40-
sub := NewSotwSubscription([]string{"*"}, config.NewOpts(), "")
40+
sub := NewSotwSubscription([]string{"*"}, true)
4141
assert.True(t, sub.IsWildcard())
4242
assert.Empty(t, sub.SubscribedResources())
4343

@@ -75,7 +75,7 @@ func TestSotwSubscriptions(t *testing.T) {
7575

7676
func TestDeltaSubscriptions(t *testing.T) {
7777
t.Run("legacy mode properly handled", func(t *testing.T) {
78-
sub := NewDeltaSubscription([]string{}, []string{}, map[string]string{"resource": "version"}, config.NewOpts(), "")
78+
sub := NewDeltaSubscription([]string{}, []string{}, map[string]string{"resource": "version"}, true)
7979
assert.True(t, sub.IsWildcard())
8080
assert.Empty(t, sub.SubscribedResources())
8181
assert.Equal(t, map[string]string{"resource": "version"}, sub.ReturnedResources())
@@ -104,7 +104,7 @@ func TestDeltaSubscriptions(t *testing.T) {
104104

105105
t.Run("new wildcard mode", func(t *testing.T) {
106106
// A resource is provided so the subscription was created in wildcard
107-
sub := NewDeltaSubscription([]string{"*"}, []string{}, map[string]string{"resource": "version"}, config.NewOpts(), "")
107+
sub := NewDeltaSubscription([]string{"*"}, []string{}, map[string]string{"resource": "version"}, true)
108108
assert.True(t, sub.IsWildcard())
109109
assert.Empty(t, sub.SubscribedResources())
110110

@@ -166,8 +166,9 @@ func TestSotwSubscriptionsWithDeactivatedLegacyWildcard(t *testing.T) {
166166
deactivateOpt := config.DeactivateLegacyWildcard()
167167
deactivateOpt(&opts)
168168

169+
typeURL := "type.googleapis.com/envoy.config.cluster.v3.Cluster"
169170
// Create subscription with empty resource list (would normally be legacy wildcard)
170-
sub := NewSotwSubscription([]string{}, opts, "type.googleapis.com/envoy.config.cluster.v3.Cluster")
171+
sub := NewSotwSubscription([]string{}, opts.IsLegacyWildcardActive(typeURL))
171172

172173
// With deactivated legacy wildcard, subscription should NOT be wildcard initially
173174
// because allowLegacyWildcard=false means empty list doesn't trigger legacy behavior
@@ -194,11 +195,11 @@ func TestSotwSubscriptionsWithDeactivatedLegacyWildcardForTypes(t *testing.T) {
194195
deactivateOpt(&opts)
195196

196197
// Both cluster and endpoint should have legacy wildcard deactivated
197-
subCluster := NewSotwSubscription([]string{}, opts, clusterType)
198+
subCluster := NewSotwSubscription([]string{}, opts.IsLegacyWildcardActive(clusterType))
198199
subCluster.SetResourceSubscription([]string{})
199200
assert.False(t, subCluster.IsWildcard())
200201

201-
subEndpoint := NewSotwSubscription([]string{}, opts, endpointType)
202+
subEndpoint := NewSotwSubscription([]string{}, opts.IsLegacyWildcardActive(endpointType))
202203
subEndpoint.SetResourceSubscription([]string{})
203204
assert.False(t, subEndpoint.IsWildcard())
204205

@@ -207,7 +208,7 @@ func TestSotwSubscriptionsWithDeactivatedLegacyWildcardForTypes(t *testing.T) {
207208
assert.True(t, subEndpoint.IsWildcard())
208209

209210
// Route should still have legacy wildcard enabled
210-
subRoute := NewSotwSubscription([]string{}, opts, routeType)
211+
subRoute := NewSotwSubscription([]string{}, opts.IsLegacyWildcardActive(routeType))
211212
subRoute.SetResourceSubscription([]string{})
212213
assert.True(t, subRoute.IsWildcard())
213214
})
@@ -219,8 +220,9 @@ func TestDeltaSubscriptionsWithDeactivatedLegacyWildcard(t *testing.T) {
219220
deactivateOpt := config.DeactivateLegacyWildcard()
220221
deactivateOpt(&opts)
221222

223+
typeURL := "type.googleapis.com/envoy.config.cluster.v3.Cluster"
222224
// Create subscription with empty resource list (would normally be legacy wildcard)
223-
sub := NewDeltaSubscription([]string{}, []string{}, map[string]string{"resource": "version"}, opts, "type.googleapis.com/envoy.config.cluster.v3.Cluster")
225+
sub := NewDeltaSubscription([]string{}, []string{}, map[string]string{"resource": "version"}, opts.IsLegacyWildcardActive(typeURL))
224226

225227
// With deactivated legacy wildcard, subscription should NOT be wildcard initially
226228
assert.False(t, sub.IsWildcard())
@@ -248,11 +250,11 @@ func TestDeltaSubscriptionsWithDeactivatedLegacyWildcardForTypes(t *testing.T) {
248250
deactivateOpt(&opts)
249251

250252
// Both cluster and endpoint should have legacy wildcard deactivated
251-
subCluster := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts, clusterType)
253+
subCluster := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts.IsLegacyWildcardActive(clusterType))
252254
subCluster.UpdateResourceSubscriptions(nil, nil)
253255
assert.False(t, subCluster.IsWildcard())
254256

255-
subEndpoint := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts, endpointType)
257+
subEndpoint := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts.IsLegacyWildcardActive(endpointType))
256258
subEndpoint.UpdateResourceSubscriptions(nil, nil)
257259
assert.False(t, subEndpoint.IsWildcard())
258260

@@ -261,7 +263,7 @@ func TestDeltaSubscriptionsWithDeactivatedLegacyWildcardForTypes(t *testing.T) {
261263
assert.True(t, subEndpoint.IsWildcard())
262264

263265
// Route should still have legacy wildcard enabled
264-
subRoute := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts, routeType)
266+
subRoute := NewDeltaSubscription([]string{}, []string{}, map[string]string{}, opts.IsLegacyWildcardActive(routeType))
265267
subRoute.UpdateResourceSubscriptions(nil, nil)
266268
assert.True(t, subRoute.IsWildcard())
267269
})

0 commit comments

Comments
 (0)