@@ -130,9 +130,12 @@ func (pe *PolicyEnforcer) Enforce(ctx context.Context, obj runtime.Object, usern
130130 Validations : []ValidationResult {},
131131 }
132132
133- // Get resource type
133+ // Get resource type from GVK
134134 gvk := obj .GetObjectKind ().GroupVersionKind ()
135- resourceType := strings .ToLower (gvk .Kind ) + "s"
135+ resourceType := gvk .Kind
136+
137+ // Normalize resource type to lowercase for comparison
138+ resourceTypeLower := strings .ToLower (resourceType )
136139
137140 // Load all policies
138141 var policyList policyv1alpha1.PolicyList
@@ -150,7 +153,7 @@ func (pe *PolicyEnforcer) Enforce(ctx context.Context, obj runtime.Object, usern
150153 // Process each policy
151154 for _ , policy := range policyList .Items {
152155 // Check if policy applies to this resource
153- if ! pe .policyAppliesTo (& policy , resourceType , u ) {
156+ if ! pe .policyAppliesTo (& policy , resourceTypeLower , u ) {
154157 continue
155158 }
156159
@@ -196,10 +199,19 @@ func (pe *PolicyEnforcer) policyAppliesTo(policy *policyv1alpha1.Policy, resourc
196199 namespace := obj .GetNamespace ()
197200
198201 for _ , rs := range policy .Spec .Resources {
199- // Check if resource type matches
202+ // Check if resource type matches (support both singular and plural forms)
200203 resourceMatches := false
201204 for _ , res := range rs .Resources {
202- if strings .ToLower (res ) == strings .ToLower (resourceType ) || res == "*" {
205+ resLower := strings .ToLower (res )
206+ // Match if:
207+ // 1. Exact match (case insensitive)
208+ // 2. Wildcard match
209+ // 3. Singular matches plural (e.g., "pod" matches "pod" or "pods")
210+ // 4. Plural matches singular (e.g., "pods" matches "pod")
211+ if resLower == resourceType ||
212+ res == "*" ||
213+ resLower == resourceType + "s" ||
214+ resLower + "s" == resourceType {
203215 resourceMatches = true
204216 break
205217 }
@@ -329,9 +341,11 @@ func GenerateSidecarInjectionPatch(containerName, image string) []PatchOperation
329341 Image : image ,
330342 }
331343
344+ // Marshal container to JSON (error ignored as Container is a known type that always marshals successfully)
332345 containerJSON , _ := json .Marshal (sidecarContainer )
333346 var containerMap map [string ]interface {}
334- json .Unmarshal (containerJSON , & containerMap )
347+ // Unmarshal to map (error ignored as valid JSON from Marshal above)
348+ _ = json .Unmarshal (containerJSON , & containerMap )
335349
336350 return []PatchOperation {
337351 {
0 commit comments