Skip to content

Commit

Permalink
Add a KCL module to wrap the helm plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroPower committed Dec 20, 2024
1 parent b851d1b commit e4a420b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: goreleaser
name: release

on:
push:
Expand All @@ -11,7 +11,7 @@ permissions:

jobs:
goreleaser:
name: release
name: goreleaser
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -49,3 +49,41 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SKIP_DARWIN_BUILD: "true"

kcl-mod:
name: kcl-mod
runs-on: ubuntu-latest
steps:
- name: Install kcl
run: wget -q https://kcl-lang.io/script/install-cli.sh -O - | /bin/bash

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Login to GitHub Container Registry
run: kcl registry login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io

- name: Publish to GitHub Container Registry
run: |
# Get the tag version without the 'v' prefix
VERSION=${GITHUB_REF#refs/tags/v}
# Find all directories under modules
for dir in ./modules/*/; do
if [ -d "$dir" ]; then
echo "Processing module: $dir"
cd "$dir"
if [ -f "kcl.mod" ]; then
PKG_NAME=$(basename $dir)
# Update the version in kcl.mod file
sed -i "s/^version = .*/version = \"${VERSION}\"/" "kcl.mod"
kcl mod push oci://ghcr.io/${{ github.actor }}/kclx/$PKG_NAME
fi
cd -
fi
done
4 changes: 4 additions & 0 deletions modules/helm/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "helm"
edition = "v0.11.0"
version = "0.0.1"
Empty file added modules/helm/kcl.mod.lock
Empty file.
58 changes: 58 additions & 0 deletions modules/helm/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
This module provides an interface for the kclx Helm plugin.
"""
import kcl_plugin.helm as helm_plugin

schema Chart:
"""Helm chart resource.

Attributes
----------
chart: str
The name of the chart to install.
repoURL: str
The URL of the chart repository.
targetRevision: str
Version of the chart to install.
namespace: str, optional.
Namespace to install the chart into.
releaseName: str, optional.
Name of the release.
skipCRDs: bool, default is False, optional.
Set to `True` to skip installing CRDs.
values: any, default is {}, optional.
Chart values.

Examples
--------
helm.template(helm.Chart {
chart = "my-chart"
targetRevision = "1.0.0"
repoURL = "https://jacobcolvin.com/helm-charts"
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,
)
}

0 comments on commit e4a420b

Please sign in to comment.