From a1a462c5fb1060d0622ec450931333b06b64d016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Wed, 23 Mar 2022 12:01:37 +0100 Subject: [PATCH] Fix improper ns import resource re-id due to resources being ignored --- compose/service/namespace.go | 4 ++-- pkg/envoy/resource/types.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compose/service/namespace.go b/compose/service/namespace.go index d3b6fbe09..bfdd5518a 100644 --- a/compose/service/namespace.go +++ b/compose/service/namespace.go @@ -324,7 +324,7 @@ func (svc namespace) Clone(ctx context.Context, namespaceID uint64, dup *types.N // Correct internal references // - namespace identifiers - nn.SearchForIdentifiers(oldNsRef.Identifiers).Walk(func(r resource.Interface) error { + nn.SearchForIdentifiers(oldNsRef.ResourceType, oldNsRef.Identifiers).Walk(func(r resource.Interface) error { r.ReID(newNsRef.Identifiers) return nil }) @@ -490,7 +490,7 @@ func (svc namespace) ImportRun(ctx context.Context, sessionID uint64, dup *types // Correct internal references // - namespace identifiers - session.Resources.SearchForIdentifiers(oldNsRef.Identifiers).Walk(func(r resource.Interface) error { + session.Resources.SearchForIdentifiers(oldNsRef.ResourceType, oldNsRef.Identifiers).Walk(func(r resource.Interface) error { r.ReID(newNsRef.Identifiers) return nil }) diff --git a/pkg/envoy/resource/types.go b/pkg/envoy/resource/types.go index 2394550c4..02231bb09 100644 --- a/pkg/envoy/resource/types.go +++ b/pkg/envoy/resource/types.go @@ -155,10 +155,14 @@ func (rr InterfaceSet) Walk(f func(r Interface) error) (err error) { // SearchForIdentifiers returns the resources where the provided identifiers exist // // The Resource is matching if at least one identifier matches. -func (rr InterfaceSet) SearchForIdentifiers(ii Identifiers) (out InterfaceSet) { +func (rr InterfaceSet) SearchForIdentifiers(resource string, ii Identifiers) (out InterfaceSet) { out = make(InterfaceSet, 0, len(rr)/2) for _, r := range rr { + if r.ResourceType() != resource { + continue + } + if r.Identifiers().HasAny(ii) { out = append(out, r) }