1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

753 final fixes

This commit is contained in:
shravan 2020-04-04 17:13:29 +05:30
parent d4baf44fd9
commit 2599b29a09

View file

@ -302,10 +302,10 @@ func generateRuleForControllers(rule kyverno.Rule, controllers string, log logr.
}
// overwrite Kinds by pod controllers defined in the annotation
controllerRule.MatchResources.Kinds = strings.Split(controllers, ",")
controllerRule.MatchResources.Kinds = replacePodWithPodControllers(controllerRule.MatchResources.Kinds, strings.Split(controllers, ","))
if len(exclude.Kinds) != 0 {
controllerRule.ExcludeResources = exclude.DeepCopy()
controllerRule.ExcludeResources.Kinds = strings.Split(controllers, ",")
controllerRule.ExcludeResources.Kinds = replacePodWithPodControllers(controllerRule.ExcludeResources.Kinds, strings.Split(controllers, ","))
}
if rule.Mutation.Overlay != nil {
@ -395,3 +395,16 @@ func defaultPodControllerAnnotation(ann map[string]string) ([]byte, error) {
}
return patchByte, nil
}
func replacePodWithPodControllers(kinds []string, controllers []string) []string {
var kindsWithoutPod []string
for _, kind := range kinds {
if strings.ToLower(kind) == "pod" {
continue
}
kindsWithoutPod = append(kindsWithoutPod, kind)
}
return append(kindsWithoutPod, controllers...)
}