diff --git a/modules/helm/main.k b/modules/helm/main.k index 1479187..5e0ddb5 100644 --- a/modules/helm/main.k +++ b/modules/helm/main.k @@ -1,6 +1,7 @@ """ This module provides an interface for the kclx Helm plugin. """ +import regex import kcl_plugin.helm as helm_plugin schema Chart: @@ -9,50 +10,73 @@ schema Chart: Attributes ---------- chart: str - The name of the chart to install. + The Helm chart name. repoURL: str - The URL of the chart repository. + The URL of the Helm chart repository. targetRevision: str - Version of the chart to install. - namespace: str, optional. - Namespace to install the chart into. + TargetRevision defines the semver tag for the chart's version. releaseName: str, optional. - Name of the release. + The Helm release name to use. If omitted it will use the chart name. + namespace: str, optional. + Namespace is an optional namespace to template with. + project: str, optional. + Project is a reference to the project this chart's releases belong to, + e.g. the Argo AppProject. This is used to segregate Helm chart caches. + helmVersion: str, default is "v3", optional. + HelmVersion is the version of Helm to use. One of: [v2, v3]. skipCRDs: bool, default is False, optional. - Set to `True` to skip installing CRDs. + Set to `True` to skip the custom resource definition installation step + (Helm's `--skip-crds`). + passCredentials: bool, default is False, optional. + Set to `True` to pass credentials to all domains (Helm's `--pass-credentials`). values: any, default is {}, optional. - Chart values. + Specifies Helm values to be passed to helm template. + """ + chart: str + repoURL: str + targetRevision: str + releaseName?: str + namespace?: str + project?: str + helmVersion?: str = "v3" + skipCRDs?: bool = False + passCredentials?: bool = False + values?: any = {} + + check: + not regex.match(repoURL, r"^oci://"), \ + "Invalid repoURL: ${repoURL}. OCI registries must not include a scheme (e.g. `oci://`)" + any x in ["v2", "v3"] { + x == helmVersion + }, "Invalid helmVersion: ${helmVersion}. Must be one of: [v2, v3]" + +template = lambda chart: Chart -> [{str:}] { + """Render Helm chart templates using `kclx`'s `kcl_plugin.helm.template`. Examples -------- + ```kcl helm.template(helm.Chart { chart = "my-chart" - targetRevision = "1.0.0" repoURL = "https://jacobcolvin.com/helm-charts" + targetRevision = "1.0.0" values = { foo = "bar" bar = "foo" } }) + ``` """ - chart: str - targetRevision: str - repoURL: str - releaseName?: str - namespace?: str - project?: str - skipCRDs?: bool = False - values?: any = {} - -template = lambda c: Chart -> {str:} { helm_plugin.template( - chart=c.chart, - target_revision=c.targetRevision, - repo_url=c.repoURL, - release_name=c.releaseName, - namespace=c.namespace, - project=c.project, - skip_crds=c.skipCRDs, - values=c.values, + chart=chart.chart, + repo_url=chart.repoURL, + target_revision=chart.targetRevision, + release_name=chart.releaseName, + namespace=chart.namespace, + project=chart.project, + helm_version=chart.helmVersion, + skip_crds=chart.skipCRDs, + pass_credentials=chart.passCredentials, + values=chart.values, ) } diff --git a/modules/helm/main_test.k b/modules/helm/main_test.k new file mode 100644 index 0000000..06f305a --- /dev/null +++ b/modules/helm/main_test.k @@ -0,0 +1,21 @@ +test_Chart = lambda { + https = Chart { + chart = "test-https" + repoURL = "https://example.com" + targetRevision = "0.1.0" + helmVersion = "v3" + } + + oci = Chart { + chart = "test-oci" + repoURL = "example.com" + targetRevision = "0.1.0" + } + + helmV2 = Chart { + chart = "test-helm-v2" + repoURL = "https://example.com" + targetRevision = "0.1.0" + helmVersion = "v2" + } +} diff --git a/pkg/helm/plugin.go b/pkg/helm/plugin.go index 739e34c..177cf02 100644 --- a/pkg/helm/plugin.go +++ b/pkg/helm/plugin.go @@ -28,7 +28,7 @@ func init() { "pass_credentials": "bool", "values": "{str:any}", }, - ResultType: "{str:any}", + ResultType: "[{str:any}]", }, Body: func(args *plugin.MethodArgs) (*plugin.MethodResult, error) { safeArgs := pluginutil.SafeMethodArgs{Args: args}