Skip to content

Commit

Permalink
Merge pull request #62 from Peefy/argo-application-field-validation-m…
Browse files Browse the repository at this point in the history
…odule

feat: add argo application field validation module
  • Loading branch information
Peefy authored Nov 9, 2023
2 parents 5b7b2bb + 5ba565d commit 9058fce
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions argo-application-field-validation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Introduction

`argo-application-field-validation` is a KCL validation module, which can be used to perform some validation on Argo `Application` fields.

## Resource

The code source and document are [here](https://github.com/kcl-lang/artifacthub/tree/main/argo-application-field-validation)
5 changes: 5 additions & 0 deletions argo-application-field-validation/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "argo-application-field-validation"
version = "0.1.0"
description = "`argo-application-field-validation` is a kcl validation module, which can be used to perform some validation on Argo `Application` fields."

31 changes: 31 additions & 0 deletions argo-application-field-validation/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import yaml

# Define the validation function
validate = lambda item {
if item.kind == "Application" and item.apiVersion.startswith("argoproj.io"):
path = item?.spec?.source?.path
chart = item?.spec?.source?.chart
assert (path or chart) and not (path and chart), "`spec.source.path` OR `spec.source.chart` should be specified but never both."
item
}
# Validate All resource
items = [validate(i) for i in option("items") or []]

if option("__test__"):
validate(yaml.decode("""\
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: badapp01
namespace: default
spec:
project: foo
source:
repoURL: https://github.com/argoproj/argocd-example-apps.git
targetRevision: HEAD
path: guestbook
# chart: foo
destination:
server: https://kubernetes.default.svc
namespace: guestbook
"""))

0 comments on commit 9058fce

Please sign in to comment.