Files
cc4fb45d70 feat: upstream enterprise preview (#1841)
feat: upstream enterprise preview

---------

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Co-authored-by: CorentinPtrl <pitrel.corentin@gmail.com>
2026-05-28 00:58:58 +02:00

50 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright 2020-2026 Project Capsule Authors
// SPDX-License-Identifier: Apache-2.0
package gvk
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type ResourceKey struct {
Group string
Version string
Kind string
Namespace string
Name string
}
// keyFromUnstructured builds a stable identity for dedupe.
// Prefer UID if you want “same object even if renamed” semantics; for Kubernetes resources
// name+namespace+GVK is typically what you want for “dont process duplicates”.
func KeyFromUnstructured(o *unstructured.Unstructured) (ResourceKey, bool) {
if o == nil {
return ResourceKey{}, false
}
gvk := o.GroupVersionKind()
if gvk.Empty() {
gvk.Kind = o.GetKind()
gv, err := schema.ParseGroupVersion(o.GetAPIVersion())
if err == nil {
gvk.Group = gv.Group
gvk.Version = gv.Version
}
}
if gvk.Kind == "" || o.GetName() == "" {
return ResourceKey{}, false
}
return ResourceKey{
Group: gvk.Group,
Version: gvk.Version,
Kind: gvk.Kind,
Namespace: o.GetNamespace(),
Name: o.GetName(),
}, true
}