pkg/gitops/helm_labels.go
Rama main · réplica de lectura del repositorio original.
package gitops
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/skyhook-io/radar/pkg/resourceid"
)
const helmHookAnnotation = "helm.sh/hook"
// FluxHelmLabelledRelease names the Flux HelmRelease whose origin labels obj
// carries, for reading the members of a release whose status records no
// inventory. The labels say which release rendered obj, not that the release
// installed it: a Helm hook stays outside a release's resources, and an object
// a controller owns was generated by that controller, which may have copied
// the labels from its own metadata.
func FluxHelmLabelledRelease(obj metav1.Object) (resourceid.Ref, bool) {
if obj == nil {
return resourceid.Ref{}, false
}
labels := obj.GetLabels()
name, namespace := labels[fluxHelmNameLabel], labels[fluxHelmNSLabel]
if name == "" || namespace == "" {
return resourceid.Ref{}, false
}
if _, hook := obj.GetAnnotations()[helmHookAnnotation]; hook {
return resourceid.Ref{}, false
}
if metav1.GetControllerOfNoCopy(obj) != nil {
return resourceid.Ref{}, false
}
return resourceid.Ref{Group: fluxHelmReleaseKind.Group, Kind: fluxHelmReleaseKind.Kind, Namespace: namespace, Name: name}, true
}