From 481de38b086c443f87566c7240f0ce835e73437e Mon Sep 17 00:00:00 2001 From: Justin Toh Date: Sat, 11 Sep 2021 22:41:42 +0800 Subject: [PATCH] fix: Exclude duplicated resource types When resource types migrate to a new API group, its old version will still be accessible for the next few versions of Kubernetes (eg. "events.v1" -> "events.v1.events.k8s.io") so we filter them out to avoid wasting effort on processing the same set of objects received from the resource's old & new API twice. Signed-off-by: Justin Toh --- pkg/cmd/lineage/lineage.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/lineage/lineage.go b/pkg/cmd/lineage/lineage.go index f752de7..775320e 100644 --- a/pkg/cmd/lineage/lineage.go +++ b/pkg/cmd/lineage/lineage.go @@ -234,10 +234,19 @@ func (o *CmdOptions) getAPIResources() ([]Resource, error) { continue } for _, resource := range list.APIResources { - // filter resources that can be watched, listed & get + // Filter resources that can be watched, listed & get if len(resource.Verbs) == 0 || !sets.NewString(resource.Verbs...).HasAll("watch", "list", "get") { continue } + // Exclude duplicated resources (for Kubernetes v1.18 & above) + switch { + // migrated to "events.v1.events.k8s.io" + case gv.Group == "" && resource.Name == "events": + continue + // migrated to "ingresses.v1.networking.k8s.io" + case gv.Group == "extensions" && resource.Name == "ingresses": + continue + } resources = append(resources, Resource{ APIGroupVersionResource: schema.GroupVersionResource{ Group: gv.Group,