Skip to content

Commit

Permalink
fix(platform): watch cluster/clustercredential/application with options
Browse files Browse the repository at this point in the history
  • Loading branch information
xdonggao committed Aug 22, 2023
1 parent 4cd32bb commit aafde18
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/application/registry/application/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions pkg/platform/registry/cluster/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions pkg/platform/registry/clustercredential/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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"
Expand Down Expand Up @@ -96,6 +97,22 @@ 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) {
_, tenantID := authentication.UsernameAndTenantID(ctx)
if tenantID != "" {
if options == nil {
options = &metainternal.ListOptions{}
}
if options.FieldSelector == nil {
options.FieldSelector = fields.OneTermEqualSelector("tenantID", tenantID)
} else {
options.FieldSelector = fields.AndSelectors(options.FieldSelector, fields.OneTermEqualSelector("tenantID", tenantID))
}
}
return r.Store.Watch(ctx, options)
}

// 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)
Expand Down

0 comments on commit aafde18

Please sign in to comment.