Skip to content

Commit

Permalink
fix: creating ClusterAdmissionReports fails for resources with colon …
Browse files Browse the repository at this point in the history
…in name (#8530) (#8532)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
gcp-cherry-pick-bot[bot] and eddycharly committed Sep 26, 2023
1 parent e788bf0 commit 7dfb538
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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

0 comments on commit 7dfb538

Please sign in to comment.