Skip to content

Commit

Permalink
Fix RuleName Mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Jogeleit committed Jul 6, 2021
1 parent d31b37b commit 7f56aec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pkg/kubernetes/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ func (m *mapper) MapPolicy(policy map[string]interface{}) kyverno.Policy {
func (m *mapper) mapRule(rule map[string]interface{}) kyverno.Rule {
r := kyverno.Rule{}

r.Name = rule["name"].(string)
if name, ok := rule["name"]; ok {
if n, ok := name.(string); ok {
r.Name = n
}
}
if validate, ok := rule["validate"]; ok {
r.Type = "validation"

Expand Down
5 changes: 2 additions & 3 deletions pkg/kubernetes/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ spec:
resources:
kinds:
- Pod
name: host-path
validate:
message:
pattern:
Expand Down Expand Up @@ -204,8 +203,8 @@ func Test_MapMinPolicy(t *testing.T) {
if rule.Type != "validation" {
t.Errorf("Expected Rule Type 'validation', got %s", rule.Type)
}
if rule.Name != "host-path" {
t.Errorf("Expected Rule Name 'host-path', got %s", rule.Name)
if rule.Name != "" {
t.Errorf("Expected Rule Name is empty, got %s", rule.Name)
}
if rule.ValidateMessage != "" {
t.Errorf("Expected empty Rule Message, got %s", rule.ValidateMessage)
Expand Down

0 comments on commit 7f56aec

Please sign in to comment.