1
0
mirror of https://github.com/rancher/steve.git synced 2025-08-31 15:11:31 +00:00

Fixed errors in obtaining object relationships

Issue: https://github.com/harvester/harvester/issues/1857
(cherry picked from commit 42c575a009)
This commit is contained in:
michelia
2022-01-26 19:31:03 +08:00
committed by Michael Bolot
parent c69493b52d
commit da22f551c6
2 changed files with 8 additions and 8 deletions

View File

@@ -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
}
@@ -317,7 +317,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)
}
@@ -529,7 +529,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{

View File

@@ -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) {