Skip to content
Draft
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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ jobs:
- name: Run chart-testing (lint)
run: ct lint --config .github/ct-lint.yaml --target-branch master

- name: Install helm-unittest plugin
run: helm plugin install https://github.com/helm-unittest/helm-unittest --version v0.6.3

- name: Run helm-unittest (changed charts only)
run: |
set -euo pipefail
changed="$(ct list-changed --config .github/ct.yaml --target-branch master || true)"
if [[ -z "${changed}" ]]; then
echo "No chart changes detected"
exit 0
fi
for chart in ${changed}; do
if [[ "${chart}" == "lib-k8s-as-helm" ]]; then
continue
fi
if compgen -G "charts/${chart}/tests/*.yaml" > /dev/null; then
helm unittest "charts/${chart}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI script doubles chart path causing tests to never run

The ct list-changed command returns paths like charts/resourcequota, but the script prepends charts/ again in the compgen check and helm unittest command, creating invalid paths like charts/charts/resourcequota. This causes the unit test step to either always skip tests (if no matching path found) or fail (if attempting to run). The library chart exclusion check on line 43 also compares chart (which contains charts/lib-k8s-as-helm) against just lib-k8s-as-helm, so it will never match.

Additional Locations (1)

Fix in Cursor Fix in Web

else
echo "Skipping helm-unittest for charts/${chart} (no tests)"
fi
done

kubeval-chart:
runs-on: ubuntu-latest
needs:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ API Object | Status | Link
`RoleBinding` | :heavy_check_mark: | [rolebinding](https://github.com/ameijer/k8s-as-helm/tree/master/charts/rolebinding)
`ServiceAccount` | :heavy_check_mark: | [serviceaccount](https://github.com/ameijer/k8s-as-helm/tree/master/charts/serviceaccount)
`NetworkPolicy` | :heavy_check_mark: | [networkpolicy](https://github.com/ameijer/k8s-as-helm/tree/master/charts/networkpolicy)
`ResourceQuota` | :heavy_check_mark: | [resourcequota](https://github.com/ameijer/k8s-as-helm/tree/master/charts/resourcequota)
`LimitRange` | :heavy_check_mark: | [limitrange](https://github.com/ameijer/k8s-as-helm/tree/master/charts/limitrange)

## Contributing

Expand Down
16 changes: 16 additions & 0 deletions charts/limitrange/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v2
appVersion: "v1.0.0"
home: https://github.com/ameijer/k8s-as-helm
description: Helm Chart representing a single LimitRange Kubernetes API object
name: limitrange
version: 1.0.0
icon: https://ameijer.github.io/k8s-as-helm/icon.png
maintainers:
- name: ameijer
url: https://github.com/ameijer
keywords:
- limitrange
- limits
- limit
- api
- primitives
2 changes: 2 additions & 0 deletions charts/limitrange/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

The LimitRange Chart {{ .Release.Name }} has been installed into your cluster!
40 changes: 40 additions & 0 deletions charts/limitrange/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# LimitRange Chart
[![Artifact HUB](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/k8s-as-helm)](https://artifacthub.io/packages/search?repo=k8s-as-helm)

## TL;DR;

```console
$ helm repo add k8s-as-helm https://ameijer.github.io/k8s-as-helm/
$ helm install my-release k8s-as-helm/limitrange
```

## Introduction

Helm charts are great! They are really configurable and let you build complicated software stacks in seconds. Tools like [Helmfile](https://github.com/roboll/helmfile) combine helm charts together to allow you to set up an environment consisting entirely of helm releases.

Let's say, though, you want to add additional code to a third party helm chart. You could make a new chart with your K8s API resource and the third party chart as a dependency, but that requires maintenance which might not be worth it if you only needed a single additional resource created. That's where k8s-as-helm charts come in. These charts wrap a single Kubernetes resource in a helm chart with all the key parameters exposed.

The limitrange chart deploys a single Kubernetes LimitRange object.

## Installation

```console
$ helm repo add k8s-as-helm https://ameijer.github.io/k8s-as-helm/
$ helm install my-release k8s-as-helm/limitrange
```

## Configuration

The following table lists the configurable parameters of the limitrange chart and their default values.

Parameter | Description | Default
--- | --- | ---
`nameOverride` | override name of the chart component | .Release.Name
`apiVersion` | api version of k8s object | `"v1"`
`annotations` | annotations in yaml map format to be added to the object | `null`
`labels` | labels to add to LimitRange object | `null`
`limits` | (REQUIRED) spec.limits list | `[]`

## Example Configuration

For some examples of values used to configure this chart, see [the ci/example values for this chart](./ci/ci-values.yaml)
26 changes: 26 additions & 0 deletions charts/limitrange/ci/ci-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
annotations:
example.com/annotation: "true"
labels:
test: "true"
ci: "true"

limits:
- type: Container
default:
cpu: 500m
memory: 512Mi
defaultRequest:
cpu: 200m
memory: 256Mi
max:
cpu: "1"
memory: 1Gi
min:
cpu: 100m
memory: 128Mi
maxLimitRequestRatio:
cpu: "10"
- type: Pod
max:
cpu: "2"
memory: 2Gi
14 changes: 14 additions & 0 deletions charts/limitrange/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Setup a chart name
*/}}
{{- define "limitrange.name" -}}
{{- default .Release.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for the object
*/}}
{{- define "apiVersion" -}}
{{- default "v1" .Values.apiVersion -}}
{{- end -}}
21 changes: 21 additions & 0 deletions charts/limitrange/templates/limitrange.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: {{ template "apiVersion" . }}
kind: LimitRange
metadata:
{{- if .Values.annotations }}
annotations:
{{ toYaml .Values.annotations | indent 4}}
{{- end }}
labels:
app: {{ template "limitrange.name" . }}
chart: {{ .Chart.Name }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- if .Values.labels }}
{{ toYaml .Values.labels | indent 4 }}
{{- end }}
name: {{ template "limitrange.name" . }}
spec:
{{- if .Values.limits }}
limits:
{{ toYaml .Values.limits | indent 4 }}
{{- end }}
45 changes: 45 additions & 0 deletions charts/limitrange/tests/limitrange_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
suite: limitrange
templates:
- templates/limitrange.yaml
tests:
- it: should render a LimitRange with limits
values:
- values/basic.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: LimitRange
- equal:
path: apiVersion
value: v1
- equal:
path: metadata.name
value: RELEASE-NAME
- equal:
path: spec.limits
value:
- type: Container
default:
cpu: 500m
memory: 512Mi

- it: should omit annotations when unset
set:
limits[0].type: Container
asserts:
- notExists:
path: metadata.annotations

- it: should include annotations and labels when set
set:
annotations.test: "true"
labels.extra: "label"
limits[0].type: Container
asserts:
- equal:
path: metadata.annotations.test
value: "true"
- equal:
path: metadata.labels.extra
value: label
5 changes: 5 additions & 0 deletions charts/limitrange/tests/values/basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
limits:
- type: Container
default:
cpu: 500m
memory: 512Mi
9 changes: 9 additions & 0 deletions charts/limitrange/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: "v1"

nameOverride: null

annotations: null
labels: null

# (REQUIRED) LimitRange spec.limits list. See Kubernetes LimitRange documentation.
limits: []
16 changes: 16 additions & 0 deletions charts/resourcequota/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v2
appVersion: "v1.0.0"
home: https://github.com/ameijer/k8s-as-helm
description: Helm Chart representing a single ResourceQuota Kubernetes API object
name: resourcequota
version: 1.0.0
icon: https://ameijer.github.io/k8s-as-helm/icon.png
maintainers:
- name: ameijer
url: https://github.com/ameijer
keywords:
- resourcequota
- quota
- resource
- api
- primitives
2 changes: 2 additions & 0 deletions charts/resourcequota/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

The ResourceQuota Chart {{ .Release.Name }} has been installed into your cluster!
42 changes: 42 additions & 0 deletions charts/resourcequota/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ResourceQuota Chart
[![Artifact HUB](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/k8s-as-helm)](https://artifacthub.io/packages/search?repo=k8s-as-helm)

## TL;DR;

```console
$ helm repo add k8s-as-helm https://ameijer.github.io/k8s-as-helm/
$ helm install my-release k8s-as-helm/resourcequota
```

## Introduction

Helm charts are great! They are really configurable and let you build complicated software stacks in seconds. Tools like [Helmfile](https://github.com/roboll/helmfile) combine helm charts together to allow you to set up an environment consisting entirely of helm releases.

Let's say, though, you want to add additional code to a third party helm chart. You could make a new chart with your K8s API resource and the third party chart as a dependency, but that requires maintenance which might not be worth it if you only needed a single additional resource created. That's where k8s-as-helm charts come in. These charts wrap a single Kubernetes resource in a helm chart with all the key parameters exposed.

The resourcequota chart deploys a single Kubernetes ResourceQuota object.

## Installation

```console
$ helm repo add k8s-as-helm https://ameijer.github.io/k8s-as-helm/
$ helm install my-release k8s-as-helm/resourcequota
```

## Configuration

The following table lists the configurable parameters of the resourcequota chart and their default values.

Parameter | Description | Default
--- | --- | ---
`nameOverride` | override name of the chart component | .Release.Name
`apiVersion` | api version of k8s object | `"v1"`
`annotations` | annotations in yaml map format to be added to the object | `null`
`labels` | labels to add to ResourceQuota object | `null`
`hard` | (REQUIRED) map of resource quota hard limits | `null`
`scopes` | optional list of scopes | `[]`
`scopeSelector` | optional scope selector for priority class, etc. | `null`

## Example Configuration

For some examples of values used to configure this chart, see [the ci/example values for this chart](./ci/ci-values.yaml)
22 changes: 22 additions & 0 deletions charts/resourcequota/ci/ci-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
annotations:
example.com/annotation: "true"
labels:
test: "true"
ci: "true"

hard:
pods: "10"
requests.cpu: "4"
requests.memory: 8Gi
limits.cpu: "8"
limits.memory: 16Gi

scopes:
- NotTerminating

scopeSelector:
matchExpressions:
- scopeName: PriorityClass
operator: In
values:
- high
14 changes: 14 additions & 0 deletions charts/resourcequota/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Setup a chart name
*/}}
{{- define "resourcequota.name" -}}
{{- default .Release.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for the object
*/}}
{{- define "apiVersion" -}}
{{- default "v1" .Values.apiVersion -}}
{{- end -}}
32 changes: 32 additions & 0 deletions charts/resourcequota/templates/resourcequota.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: {{ template "apiVersion" . }}
kind: ResourceQuota
metadata:
{{- if .Values.annotations }}
annotations:
{{ toYaml .Values.annotations | indent 4}}
{{- end }}
labels:
app: {{ template "resourcequota.name" . }}
chart: {{ .Chart.Name }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- if .Values.labels }}
{{ toYaml .Values.labels | indent 4 }}
{{- end }}
name: {{ template "resourcequota.name" . }}
spec:
{{- if .Values.hard }}
hard:
{{ toYaml .Values.hard | indent 4 }}
{{- end }}
{{- if .Values.scopes }}
scopes:
{{ toYaml .Values.scopes | indent 4 }}
{{- end }}
{{- if .Values.scopeSelector }}
scopeSelector:
{{- if .Values.scopeSelector.matchExpressions }}
matchExpressions:
{{ toYaml .Values.scopeSelector.matchExpressions | indent 6 }}
{{- end }}
{{- end }}
Loading