From 08116ee201248079b6bb2bceccc23227e8c9377d Mon Sep 17 00:00:00 2001 From: GaoXiaodong <13814823514@163.com> Date: Tue, 22 Aug 2023 18:09:37 +0800 Subject: [PATCH] fix(platform): watch cluster/clustercredential/application with options (#2307) Co-authored-by: xdonggao --- pkg/application/registry/application/storage/storage.go | 7 +++++++ pkg/platform/registry/cluster/storage/storage.go | 7 +++++++ .../registry/clustercredential/storage/storage.go | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/pkg/application/registry/application/storage/storage.go b/pkg/application/registry/application/storage/storage.go index c6322777c6..7711c37048 100644 --- a/pkg/application/registry/application/storage/storage.go +++ b/pkg/application/registry/application/storage/storage.go @@ -28,6 +28,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" genericregistry "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/generic/registry" "k8s.io/apiserver/pkg/registry/rest" @@ -119,6 +120,12 @@ func (r *GenericREST) ShortNames() []string { return []string{"app"} } +// Watch selects resources in the storage which match to the selector. 'options' can be nil. +func (r *GenericREST) Watch(ctx context.Context, options *metainternal.ListOptions) (watch.Interface, error) { + wrappedOptions := apiserverutil.PredicateListOptions(ctx, options) + return r.Store.Watch(ctx, wrappedOptions) +} + // List selects resources in the storage which match to the selector. 'options' can be nil. func (r *GenericREST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) { wrappedOptions := apiserverutil.PredicateListOptions(ctx, options) diff --git a/pkg/platform/registry/cluster/storage/storage.go b/pkg/platform/registry/cluster/storage/storage.go index 7dc9a0199a..9a9bdb5195 100644 --- a/pkg/platform/registry/cluster/storage/storage.go +++ b/pkg/platform/registry/cluster/storage/storage.go @@ -26,6 +26,7 @@ import ( metainternal "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" genericregistry "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/generic/registry" "k8s.io/apiserver/pkg/registry/rest" @@ -163,6 +164,12 @@ func (r *REST) ShortNames() []string { return []string{"cls"} } +// Watch selects resources in the storage which match to the selector. 'options' can be nil. +func (r *REST) Watch(ctx context.Context, options *metainternal.ListOptions) (watch.Interface, error) { + wrappedOptions := apiserverutil.PredicateListOptions(ctx, options) + return r.Store.Watch(ctx, wrappedOptions) +} + // List selects resources in the storage which match to the selector. 'options' can be nil. func (r *REST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) { wrappedOptions := apiserverutil.PredicateListOptions(ctx, options) diff --git a/pkg/platform/registry/clustercredential/storage/storage.go b/pkg/platform/registry/clustercredential/storage/storage.go index 2763ba7bb9..1c927a26b7 100644 --- a/pkg/platform/registry/clustercredential/storage/storage.go +++ b/pkg/platform/registry/clustercredential/storage/storage.go @@ -25,12 +25,14 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" genericregistry "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/generic/registry" "k8s.io/apiserver/pkg/registry/rest" platforminternalclient "tkestack.io/tke/api/client/clientset/internalversion/typed/platform/internalversion" "tkestack.io/tke/api/platform" "tkestack.io/tke/pkg/apiserver/authentication" + apiserverutil "tkestack.io/tke/pkg/apiserver/util" "tkestack.io/tke/pkg/platform/registry/clustercredential" "tkestack.io/tke/pkg/platform/util" "tkestack.io/tke/pkg/util/log" @@ -96,6 +98,12 @@ func (r *REST) ShortNames() []string { return []string{"cc"} } +// Watch selects resources in the storage which match to the selector. 'options' can be nil. +func (r *REST) Watch(ctx context.Context, options *metainternal.ListOptions) (watch.Interface, error) { + wrappedOptions := apiserverutil.PredicateListOptions(ctx, options) + return r.Store.Watch(ctx, wrappedOptions) +} + // List selects resources in the storage which match to the selector. 'options' can be nil. func (r *REST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) { _, tenantID := authentication.UsernameAndTenantID(ctx)