Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed errors in obtaining object relationships #37

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/stores/proxy/proxy_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions pkg/summarycache/summarycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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) {
Expand Down