1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

fix: use the correct API version for VAPs in the generated events (#9392)

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
Co-authored-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
This commit is contained in:
Mariam Fahmy 2024-01-18 16:02:07 +02:00 committed by GitHub
parent 14b4bd7d2c
commit b4acbdea2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View file

@ -23,6 +23,8 @@ type GenericPolicy interface {
GetPolicy() interface{} GetPolicy() interface{}
// GetType returns policy type // GetType returns policy type
GetType() PolicyType GetType() PolicyType
// GetAPIVersion returns policy API version
GetAPIVersion() string
// GetName returns policy name // GetName returns policy name
GetName() string GetName() string
// GetNamespace returns policy namespace // GetNamespace returns policy namespace
@ -51,6 +53,10 @@ func (p *KyvernoPolicy) GetType() PolicyType {
return KyvernoPolicyType return KyvernoPolicyType
} }
func (p *KyvernoPolicy) GetAPIVersion() string {
return "kyverno.io/v1"
}
func (p *KyvernoPolicy) GetName() string { func (p *KyvernoPolicy) GetName() string {
return p.policy.GetName() return p.policy.GetName()
} }
@ -97,6 +103,10 @@ func (p *ValidatingAdmissionPolicy) GetType() PolicyType {
return ValidatingAdmissionPolicyType return ValidatingAdmissionPolicyType
} }
func (p *ValidatingAdmissionPolicy) GetAPIVersion() string {
return "admissionregistration.k8s.io/v1alpha1"
}
func (p *ValidatingAdmissionPolicy) GetName() string { func (p *ValidatingAdmissionPolicy) GetName() string {
return p.policy.GetName() return p.policy.GetName()
} }

View file

@ -19,8 +19,7 @@ func NewPolicyFailEvent(source Source, reason Reason, engineResponse engineapi.E
} }
pol := engineResponse.Policy() pol := engineResponse.Policy()
regarding := corev1.ObjectReference{ regarding := corev1.ObjectReference{
// TODO: iirc it's not safe to assume api version is set APIVersion: pol.GetAPIVersion(),
APIVersion: "kyverno.io/v1",
Kind: pol.GetKind(), Kind: pol.GetKind(),
Name: pol.GetName(), Name: pol.GetName(),
Namespace: pol.GetNamespace(), Namespace: pol.GetNamespace(),
@ -94,8 +93,7 @@ func NewPolicyAppliedEvent(source Source, engineResponse engineapi.EngineRespons
action = ResourcePassed action = ResourcePassed
} }
regarding := corev1.ObjectReference{ regarding := corev1.ObjectReference{
// TODO: iirc it's not safe to assume api version is set APIVersion: policy.GetAPIVersion(),
APIVersion: "kyverno.io/v1",
Kind: policy.GetKind(), Kind: policy.GetKind(),
Name: policy.GetName(), Name: policy.GetName(),
Namespace: policy.GetNamespace(), Namespace: policy.GetNamespace(),