1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/cmd/cli/kubectl-kyverno/resource/duplicate.go
Charles-Edouard Brétéché cdd8b4383f
refactor: cli test command test execution (#8266)
* refactor: cli test command test execution

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* error

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* tests

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-05 13:19:05 +00:00

34 lines
778 B
Go

package resource
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type ResourceKey struct {
schema.GroupKind
Namespace string
Name string
}
type ResourceMap = map[ResourceKey]*unstructured.Unstructured
func RemoveDuplicates(resources []*unstructured.Unstructured) (ResourceMap, ResourceMap) {
duplicates := ResourceMap{}
uniques := ResourceMap{}
for _, resource := range resources {
if resource != nil {
key := ResourceKey{
GroupKind: resource.GroupVersionKind().GroupKind(),
Namespace: resource.GetNamespace(),
Name: resource.GetName(),
}
if uniques[key] == nil {
uniques[key] = resource
} else {
duplicates[key] = resource
}
}
}
return uniques, duplicates
}