From be08ccf48799c0a5e7e6cd105439e07c41b93256 Mon Sep 17 00:00:00 2001 From: shravan Date: Mon, 17 Feb 2020 13:12:30 +0530 Subject: [PATCH] 536 cli now supports policies with generate --- pkg/kyverno/apply/command.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/kyverno/apply/command.go b/pkg/kyverno/apply/command.go index 9f8d651361..15132caa50 100644 --- a/pkg/kyverno/apply/command.go +++ b/pkg/kyverno/apply/command.go @@ -348,5 +348,28 @@ func applyPolicyOnResource(policy *v1.ClusterPolicy, resource *unstructured.Unst } } + var policyHasGenerate bool + for _, rule := range policy.Spec.Rules { + if rule.HasGenerate() { + policyHasGenerate = true + } + } + + if policyHasGenerate { + generateResponse := engine.Generate(engine.PolicyContext{Policy: *policy, NewResource: *resource}) + if len(generateResponse.PolicyResponse.Rules) > 0 { + fmt.Printf("\n\nGenerate:") + fmt.Printf("\nResource is valid") + fmt.Printf("\n\n") + } else { + fmt.Printf("\n\nGenerate:") + fmt.Printf("\nResource is invalid") + for i, r := range generateResponse.PolicyResponse.Rules { + fmt.Printf("\n%d. %s", i+1, r.Message) + } + fmt.Printf("\n\n") + } + } + return nil }