-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from Peefy/argo-application-field-validation-m…
…odule feat: add argo application field validation module
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""")) |