Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add argo application field validation module #62

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
"""))