Created
October 9, 2023 09:04
-
-
Save erdii/df4c80089c1a5ac76739603264f65cf5 to your computer and use it in GitHub Desktop.
controllerof_lookup.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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