Skip to content

Commit 801d766

Browse files
review
1 parent 15666ba commit 801d766

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

pkg/cache/internal/cached_resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type CachedResource struct {
3838
// cacheVersion is the version of the cache at the time of last update, used in sotw.
3939
cacheVersion string
4040

41-
// onDemandOnly indicates if this resource is only sent when explicitly requested (ODCDS support).
41+
// onDemandOnly indicates if this resource is only sent when explicitly requested.
4242
// When false (default), resource is sent to wildcard subscriptions.
4343
// When true, resource is only sent when explicitly requested by name.
4444
onDemandOnly bool
@@ -80,7 +80,7 @@ func WithResourceTTL(ttl *time.Duration) CachedResourceOption {
8080
return func(r *CachedResource) { r.ttl = ttl }
8181
}
8282

83-
// OnDemandOnly marks the resource as on-demand only (for ODCDS support).
83+
// OnDemandOnly marks the resource as on-demand only.
8484
func OnDemandOnly(onDemandOnly bool) CachedResourceOption {
8585
return func(r *CachedResource) { r.onDemandOnly = onDemandOnly }
8686
}

pkg/cache/types/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type SnapshotResource struct {
2222
// Optional
2323
Version string
2424

25-
// Optional - marks resource as on-demand only (e.g. for OdCDS).
25+
// Optional - marks resource as on-demand only.
2626
// Only supported for the snapshot cache.
2727
// When false (default), this resource is sent to all clients with wildcard subscriptions.
2828
// When true, this resource is only sent when explicitly requested by name.

pkg/cache/v3/simple.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (cache *snapshotCache) sendHeartbeats(ctx context.Context, node string) {
211211
if watch.subscription.IsWildcard() {
212212
resourcesToReturn = make(map[string]*internal.CachedResource, len(resources))
213213
for _, res := range resources {
214-
// Include wildcard-eligible resources for wildcard subscriptions (ODCDS support)
214+
// Include wildcard-eligible resources for wildcard subscriptions
215215
if !res.OnDemandOnly() {
216216
addResource(res)
217217
}
@@ -521,7 +521,7 @@ func createResponse(snapshot ResourceSnapshot, watch ResponseWatch, ads bool) (*
521521
if watch.subscription.IsWildcard() {
522522
changedResources = make(map[string]struct{}, len(resources))
523523
for name, res := range resources {
524-
// Include wildcard-eligible resources for wildcard subscriptions (ODCDS support)
524+
// Include wildcard-eligible resources for wildcard subscriptions
525525
if res.OnDemandOnly() {
526526
continue
527527
}
@@ -559,20 +559,12 @@ func createResponse(snapshot ResourceSnapshot, watch ResponseWatch, ads bool) (*
559559
continue
560560
}
561561

562-
if watch.subscription.IsWildcard() {
563-
// For wildcard subscriptions: delete if resource is on-demand only AND not explicitly subscribed
564-
if !res.OnDemandOnly() {
565-
continue
566-
}
562+
if watch.subscription.IsWildcard() && !res.OnDemandOnly() {
563+
continue
564+
}
567565

568-
if _, explicitlySubscribed := subscribedResources[name]; !explicitlySubscribed {
569-
deletedResources = append(deletedResources, name)
570-
}
571-
} else {
572-
// For non-wildcard subscriptions, check if resource is no longer watched
573-
if _, explicitlySubscribed := subscribedResources[name]; !explicitlySubscribed {
574-
deletedResources = append(deletedResources, name)
575-
}
566+
if _, explicitlySubscribed := subscribedResources[name]; !explicitlySubscribed {
567+
deletedResources = append(deletedResources, name)
576568
}
577569
}
578570

@@ -591,7 +583,7 @@ func createResponse(snapshot ResourceSnapshot, watch ResponseWatch, ads bool) (*
591583
resourcesToReturn = make([]*internal.CachedResource, 0, len(resources))
592584
returnedResources = make(map[string]string, len(resources))
593585
for name, resource := range resources {
594-
// Include wildcard-eligible resources for wildcard subscriptions (ODCDS support)
586+
// Include wildcard-eligible resources for wildcard subscriptions
595587
if !resource.OnDemandOnly() {
596588
resourcesToReturn = append(resourcesToReturn, resource)
597589
returnedResources[name] = version
@@ -606,7 +598,6 @@ func createResponse(snapshot ResourceSnapshot, watch ResponseWatch, ads bool) (*
606598
if !ok {
607599
continue
608600
}
609-
// Check if already added (for ODCDS: wildcard + explicit subscriptions)
610601
if _, alreadyAdded := returnedResources[name]; !alreadyAdded {
611602
resourcesToReturn = append(resourcesToReturn, resource)
612603
returnedResources[name] = version
@@ -738,7 +729,7 @@ func createDeltaResponse(snapshot ResourceSnapshot, watch DeltaResponseWatch, re
738729

739730
if watch.subscription.IsWildcard() {
740731
for _, res := range resources {
741-
// Include wildcard-eligible resources for wildcard subscriptions (ODCDS support)
732+
// Include wildcard-eligible resources for wildcard subscriptions
742733
if !res.OnDemandOnly() {
743734
if err := addIfChanged(res); err != nil {
744735
return nil, fmt.Errorf("failed to compute resource version for %s: %w", res.Name, err)

0 commit comments

Comments
 (0)