Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: creating ClusterAdmissionReports fails for resources with colon in name (cherry-pick #8530) #8532

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/utils/controller/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ func SetAnnotation(obj metav1.Object, key, value string) {
obj.SetAnnotations(annotations)
}

func GetAnnotation(obj metav1.Object, key string) string {
annotations := obj.GetAnnotations()
if annotations == nil {
return ""
}
return annotations[key]
}

func HasAnnotation(obj metav1.Object, key string) bool {
annotations := obj.GetAnnotations()
if annotations == nil {
Expand Down
16 changes: 8 additions & 8 deletions pkg/utils/report/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
const (
LabelDomain = "kyverno.io"
// resource labels
LabelResourceHash = "audit.kyverno.io/resource.hash"
LabelResourceUid = "audit.kyverno.io/resource.uid"
LabelResourceGVR = "audit.kyverno.io/resource.gvr"
LabelResourceNamespace = "audit.kyverno.io/resource.namespace"
LabelResourceName = "audit.kyverno.io/resource.name"
LabelResourceHash = "audit.kyverno.io/resource.hash"
LabelResourceUid = "audit.kyverno.io/resource.uid"
LabelResourceGVR = "audit.kyverno.io/resource.gvr"
AnnotationResourceNamespace = "audit.kyverno.io/resource.namespace"
AnnotationResourceName = "audit.kyverno.io/resource.name"
// policy labels
LabelDomainClusterPolicy = "cpol.kyverno.io"
LabelDomainPolicy = "pol.kyverno.io"
Expand Down Expand Up @@ -99,8 +99,8 @@ func SetResourceGVR(report kyvernov1alpha2.ReportInterface, gvr schema.GroupVers
}

func SetResourceNamespaceAndName(report kyvernov1alpha2.ReportInterface, namespace, name string) {
controllerutils.SetLabel(report, LabelResourceNamespace, namespace)
controllerutils.SetLabel(report, LabelResourceName, name)
controllerutils.SetAnnotation(report, AnnotationResourceNamespace, namespace)
controllerutils.SetAnnotation(report, AnnotationResourceName, name)
}

func CalculateResourceHash(resource unstructured.Unstructured) string {
Expand Down Expand Up @@ -152,7 +152,7 @@ func GetResourceGVR(report metav1.Object) schema.GroupVersionResource {
}

func GetResourceNamespaceAndName(report kyvernov1alpha2.ReportInterface) (string, string) {
return controllerutils.GetLabel(report, LabelResourceNamespace), controllerutils.GetLabel(report, LabelResourceName)
return controllerutils.GetAnnotation(report, AnnotationResourceNamespace), controllerutils.GetAnnotation(report, AnnotationResourceName)
}

func GetResourceHash(report metav1.Object) string {
Expand Down