From 42c575a0090eb5f327f420ea12f0d8381b950345 Mon Sep 17 00:00:00 2001 From: michelia Date: Wed, 26 Jan 2022 19:31:03 +0800 Subject: [PATCH] Fixed errors in obtaining object relationships Issue: https://github.com/harvester/harvester/issues/1857 --- pkg/stores/proxy/proxy_store.go | 10 +++++----- pkg/summarycache/summarycache.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/stores/proxy/proxy_store.go b/pkg/stores/proxy/proxy_store.go index 7978377..368f687 100644 --- a/pkg/stores/proxy/proxy_store.go +++ b/pkg/stores/proxy/proxy_store.go @@ -80,7 +80,7 @@ func NewProxyStore(clientGetter ClientGetter, notifier RelationshipNotifier, loo } func (s *Store) ByID(apiOp *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) { - result, err := s.byID(apiOp, schema, id) + result, err := s.byID(apiOp, schema, apiOp.Namespace, id) return toAPI(schema, result), err } @@ -117,8 +117,8 @@ func toAPI(schema *types.APISchema, obj runtime.Object) types.APIObject { return apiObject } -func (s *Store) byID(apiOp *types.APIRequest, schema *types.APISchema, id string) (*unstructured.Unstructured, error) { - k8sClient, err := s.clientGetter.TableClient(apiOp, schema, apiOp.Namespace) +func (s *Store) byID(apiOp *types.APIRequest, schema *types.APISchema, namespace, id string) (*unstructured.Unstructured, error) { + k8sClient, err := s.clientGetter.TableClient(apiOp, schema, namespace) if err != nil { return nil, err } @@ -312,7 +312,7 @@ func (s *Store) listAndWatch(apiOp *types.APIRequest, k8sClient dynamic.Resource if s.notifier != nil { eg.Go(func() error { for rel := range s.notifier.OnInboundRelationshipChange(ctx, schema, apiOp.Namespace) { - obj, err := s.byID(apiOp, schema, rel.Name) + obj, err := s.byID(apiOp, schema, rel.Namespace, rel.Name) if err == nil { result <- s.toAPIEvent(apiOp, schema, watch.Modified, obj) } @@ -524,7 +524,7 @@ func (s *Store) Delete(apiOp *types.APIRequest, schema *types.APISchema, id stri return types.APIObject{}, err } - obj, err := s.byID(apiOp, schema, id) + obj, err := s.byID(apiOp, schema, apiOp.Namespace, id) if err != nil { // ignore lookup error return types.APIObject{}, validation.ErrorCode{ diff --git a/pkg/summarycache/summarycache.go b/pkg/summarycache/summarycache.go index 89f9fc8..5c53069 100644 --- a/pkg/summarycache/summarycache.go +++ b/pkg/summarycache/summarycache.go @@ -80,11 +80,10 @@ func (s *SummaryCache) OnInboundRelationshipChange(ctx context.Context, schema * s.cbs[id] = cb go func() { - defer close(ret) for rel := range cb { if rel.Kind == kind && rel.APIVersion == apiVersion && - rel.Namespace == namespace { + (namespace == "" || namespace == rel.Namespace) { ret <- rel } } @@ -95,10 +94,11 @@ func (s *SummaryCache) OnInboundRelationshipChange(ctx context.Context, schema * s.Lock() defer s.Unlock() close(cb) + defer close(ret) delete(s.cbs, id) }() - return cb + return ret } func (s *SummaryCache) SummaryAndRelationship(obj runtime.Object) (*summary.SummarizedObject, []Relationship) {