From 7b67bbbcf361983e563663424e13f2b6cf6d5392 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Wed, 1 Mar 2023 11:00:12 +0100 Subject: [PATCH] Disable SendInitialEvents for etcd and watch cache --- staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go | 8 ++++++++ staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go index f37024b6d82..7e4ddcf66e2 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go @@ -34,6 +34,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" "k8s.io/apiserver/pkg/audit" @@ -497,6 +498,13 @@ type namespacedName struct { // Watch implements storage.Interface. func (c *Cacher) Watch(ctx context.Context, key string, opts storage.ListOptions) (watch.Interface, error) { + if opts.SendInitialEvents != nil { + return nil, errors.NewInvalid( + schema.GroupKind{Group: c.groupResource.Group, Kind: c.groupResource.Resource}, + "", + field.ErrorList{field.Forbidden(field.NewPath("sendInitialEvents"), "for watch is not yet implemented by the watch cache")}, + ) + } pred := opts.Predicate // If the resourceVersion is unset, ensure that the rv // from which the watch is being served, is the latest diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go index 5342be2ae91..2fc237de331 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go @@ -33,6 +33,7 @@ import ( "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/conversion" @@ -863,6 +864,13 @@ func growSlice(v reflect.Value, maxCapacity int, sizes ...int) { // Watch implements storage.Interface.Watch. func (s *store) Watch(ctx context.Context, key string, opts storage.ListOptions) (watch.Interface, error) { + if opts.SendInitialEvents != nil { + return nil, apierrors.NewInvalid( + schema.GroupKind{Group: s.groupResource.Group, Kind: s.groupResource.Resource}, + "", + field.ErrorList{field.Forbidden(field.NewPath("sendInitialEvents"), "for watch is unsupported by an etcd cluster")}, + ) + } preparedKey, err := s.prepareKey(key) if err != nil { return nil, err