mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
cdd8b4383f
* 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>
34 lines
778 B
Go
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
|
|
}
|