Skip to content

Commit

Permalink
feat: add kyverno validation as default target under validate (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
AtzeDeVries authored Nov 26, 2024
1 parent 6359f9d commit 6219e6f
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func Validate() error {
}
mg.Deps(mg.F(kubeScore, templates))
mg.Deps(mg.F(kubeConform, templates, "api-platform"))
mg.Deps(mg.F(validateKyvernoPolicies, templates))
mg.Deps(Pallets)
fmt.Println("Validation passed")
return nil
Expand Down Expand Up @@ -76,6 +77,24 @@ func ArgoCDDiff() error {
return nil
}

// ValidateKyverno runs render Kubernetes manifests and invokes validateKyvernoPolicies.
func ValidateKyverno() error {
// Render templates and obtain paths
renderedTemplates, err := renderTemplates()
if err != nil {
return fmt.Errorf("failed to render templates: %w", err)
}

// Validate rendered templates with Kyverno
err = validateKyvernoPolicies(renderedTemplates)
if err != nil {
return fmt.Errorf("Kyverno validation failed: %w", err)
}

fmt.Println("All templates passed Kyverno validation.")
return nil
}

// validateKyvernoPolicies runs Kyverno validation on rendered Kubernetes manifests.
func validateKyvernoPolicies(renderedTemplatePaths string) error {
policyDir := "kyverno-policies" // Directory where policies are stored
Expand Down Expand Up @@ -126,24 +145,6 @@ func validateKyvernoPolicies(renderedTemplatePaths string) error {
return nil
}

// ValidateKyverno runs render Kubernetes manifests and invokes validateKyvernoPolicies.
func ValidateKyverno() error {
// Render templates and obtain paths
renderedTemplates, err := renderTemplates()
if err != nil {
return fmt.Errorf("failed to render templates: %w", err)
}

// Validate rendered templates with Kyverno
err = validateKyvernoPolicies(renderedTemplates)
if err != nil {
return fmt.Errorf("Kyverno validation failed: %w", err)
}

fmt.Println("All templates passed Kyverno validation.")
return nil
}

func kubeScore(paths string) error {
if paths == "" {
fmt.Printf("No files presented to kube-score, skipping")
Expand Down

0 comments on commit 6219e6f

Please sign in to comment.