Skip to content

Commit 093335b

Browse files
authored
Reject watch resume main (kptdev#1104)
* Reject watch resume calls Signed-off-by: Gergely Nagy <gergely.l.nagy@ericsson.com> * Add WatchList feature flag Signed-off-by: Gergely Nagy <gergely.l.nagy@ericsson.com> * Fix watch tests: remove goto statements and correct error assertions - Remove all goto statements from watch_test.go and e2e/api/watch_test.go, replacing them with helper functions for better readability. - Fix test assertions to use IsResourceExpired instead of IsGone, matching the implementation which uses NewResourceExpired (standard k8s pattern for stale resourceVersion). - Fix StatusReasonExpired assertion (was incorrectly expecting StatusReasonGone). - Extract hasExactResourceVersion variable for clarity in createGenericWatch. - Add cancel() call before returning 410 to avoid context leak. Signed-off-by: Gergely Nagy <gergely.l.nagy@ericsson.com> * Fix empty line Signed-off-by: Gergely Nagy <gergely.l.nagy@ericsson.com> --------- Signed-off-by: Gergely Nagy <gergely.l.nagy@ericsson.com>
1 parent e9755d8 commit 093335b

3 files changed

Lines changed: 630 additions & 59 deletions

File tree

pkg/registry/porch/watch.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ import (
2323
"github.com/kptdev/porch/pkg/engine"
2424
"github.com/kptdev/porch/pkg/repository"
2525
"go.opentelemetry.io/otel/trace"
26+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2627
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"k8s.io/apimachinery/pkg/runtime"
2930
"k8s.io/apimachinery/pkg/watch"
3031
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
32+
"k8s.io/apiserver/pkg/features"
33+
utilfeature "k8s.io/apiserver/pkg/util/feature"
3134
"k8s.io/klog/v2"
3235
)
3336

@@ -37,8 +40,17 @@ func createGenericWatch(ctx context.Context, r packageReader, filter repository.
3740

3841
allowWatchBookmarks := options != nil && options.AllowWatchBookmarks
3942
sendInitialEvents := options != nil && options.SendInitialEvents != nil && *options.SendInitialEvents
43+
hasExactResourceVersion := options != nil && len(options.ResourceVersion) > 0 && options.ResourceVersion != "0"
4044
allowWatchBookmarks = effectiveAllowWatchBookmarks(allowWatchBookmarks, sendInitialEvents)
4145

46+
// A non-zero resourceVersion without sendInitialEvents is a plain watch resume.
47+
// Porch doesn't support RV-based resumption; return 410 to force a full re-list.
48+
if utilfeature.DefaultFeatureGate.Enabled(features.WatchList) && hasExactResourceVersion && !sendInitialEvents {
49+
klog.V(2).Infof("watch: returning 410 Gone for plain watch resume (resourceVersion=%q)", options.ResourceVersion)
50+
cancel()
51+
return nil, apierrors.NewResourceExpired("resourceVersion is not supported for watch without sendInitialEvents")
52+
}
53+
4254
w := &watcher{
4355
cancel: cancel,
4456
resultChan: make(chan watch.Event, 64),

0 commit comments

Comments
 (0)