Skip to content

Instantly share code, notes, and snippets.

@erdii
Created October 9, 2023 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdii/df4c80089c1a5ac76739603264f65cf5 to your computer and use it in GitHub Desktop.
Save erdii/df4c80089c1a5ac76739603264f65cf5 to your computer and use it in GitHub Desktop.
controllerof_lookup.go
package controllers
import (
"k8s.io/apimachinery/pkg/runtime/schema"
corev1alpha1 "package-operator.run/apis/core/v1alpha1"
)
type ControllerOfLookupKey struct {
schema.GroupKind
Namespace, Name string
}
type ControllerOfLookup map[ControllerOfLookupKey]struct{}
func NewControllerOfLookup(controlledObjectReferences []corev1alpha1.ControlledObjectReference) ControllerOfLookup {
l := ControllerOfLookup{}
for _, obj := range controlledObjectReferences {
l[ControllerOfLookupKey{
GroupKind: schema.GroupKind{
Group: obj.Group,
Kind: obj.Kind,
},
Namespace: obj.Namespace,
Name: obj.Name,
}] = struct{}{}
}
return l
}
func (l ControllerOfLookup) Has(gk schema.GroupKind, namespace, name string) bool {
_, has := l[ControllerOfLookupKey{
GroupKind: gk,
Namespace: namespace,
Name: name,
}]
return has
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment