Skip to content

Commit

Permalink
Merge pull request #10 from buttahtoast/master
Browse files Browse the repository at this point in the history
Manifests 0.2.0
  • Loading branch information
oliverbaehler authored Jan 5, 2021
2 parents 3846ecf + 608057a commit cb86081
Show file tree
Hide file tree
Showing 58 changed files with 870 additions and 191 deletions.
1 change: 1 addition & 0 deletions charts/manifests/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@

# Custom
README.md.gotmpl
plugin/
20 changes: 11 additions & 9 deletions charts/manifests/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ apiVersion: v2
name: manifests
description: "Bedag's Manifest chart. Library full of basic kubernetes manifests."
type: library
version: 0.1.2
version: 0.2.0
icon: "https://www.bedag.ch/wGlobal/wGlobal/layout/images/logo.svg"
keywords:
- Bedag
- Manifests
- Library
- Bedag
- Manifests
- Library
maintainers:
- name: oliverbaehler
email: [email protected]
- name: oliverbaehler
email: [email protected]
- name: SRE
email: [email protected]
dependencies:
- name: "library"
version: 0.2.0
repository: https://buttahtoast.github.io/helm-charts/
- name: "library"
version: "~0.3.0"
repository: "https://buttahtoast.github.io/helm-charts/"
annotations:
artifacthub.io/containsSecurityUpdates: "false"
artifacthub.io/prerelease: "true"
3 changes: 1 addition & 2 deletions charts/manifests/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Major Changes to functions are documented with the version affected. **Before up

For Artifacthub Users: The entire documentation can be found in the GitHub Repository.

We tried our best with the documentation. Since it's a very different approach on writing helm charts it's hard to explain. Therefor we suggest taking a look at other charts in this chart repository, since they (might) be written with the help of this library. We expect users of this library to have a deep know-hopw of Helm und Go Sprig. If that's not the case yet, we recommend coming back later, because the usage might frustrate you more than you actually benefit from it. We are planing to expand the documentation in the future, but currently there's a single person developing this project. So your contribution is welcome, if you are a fan of the project! :)
We tried our best with the documentation. Since it's a very different approach on writing helm charts it's hard to explain. Therefor we suggest taking a look at other charts in this chart repository, since they (might) be written with the help of this library. We expect users of this library to have a deep know-hopw of Helm und Go Sprig. If that's not the case yet, we recommend coming back later, because the usage might frustrate you more than you actually benefit from it. We are planing to expand the documentation in the future. Your contribution is welcome, if you are a fan of the project! :)

We recommend looking thirst through the **Kubernetes Manifests** section.

Expand All @@ -54,7 +54,6 @@ We recommend looking thirst through the **Kubernetes Manifests** section.
* **[Development](./templates/README.md)**
* **[Values](./templates/values/README.md)**
* **[Utilities](./templates/utils/README.md)**
* **[Manifest Testing](../../manifests-testing/README.md)**

{{/*
Chart Sources
Expand Down
30 changes: 30 additions & 0 deletions charts/manifests/plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Values Generator

This is currently only a temporary solution.

# Install

To install this plugin, clone the entire git repository.

Make sure the script is executable:

```
chmod +x helm-charts/charts/manifests/plugin/generator.sh
```

## Local

You can install Helm Plugins local. This means, in the HELM_PLUGIN directory will be a symbolic link created given to the directory. This is how you would install it locally:

```
helm install helm-charts/charts/manifests/plugin
```
Since it's a symbolic link, the git repository has to persist.

# Usage

Learn which arguments are available:

```
helm manifests -h
```
69 changes: 69 additions & 0 deletions charts/manifests/plugin/generator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

## -- Help Context
show_help() {
cat << EOF
Usage: ${0##*/} [-h] [-p] ]
-m [manifest] Manifest Name
-p [preset] Preset Name
-k [parentkey] Custom Parent Key
-P [keypath] Custom Key Path
-a [helm args] Additional Helm Arguments
-M Minimal Structure
-h Show this context
EOF
}

## -- Defaults
MANIFEST=""
PRESET=""
HELM_ARGS=""
KEYPATH=""
MINIMAL=""
PARENTKEY=""

## -- Opting arguments
OPTIND=1; # Reset OPTIND, to clear getopts when used in a prior script
while getopts ":ha:P:k:m:p:k:M" opt; do
case ${opt} in
m)
MANIFEST="${OPTARG}"
;;
p)
PRESET="${OPTARG}"
;;
k)
PARENTKEY="${OPTARG}"
;;
P)
KEYPATH="${OPTARG}"
;;
a)
HELM_ARGS="${OPTARG}"
;;
M)
MINIMAL="true"
;;
h)
show_help
exit 0
;;
?)
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))

## -- Helm Values
HELM_VALUES=""
[ -n "$MANIFEST" ] && HELM_VALUES="--set doc.manifest=${MANIFEST}"
[ -n "$PRESET" ] && HELM_VALUES="${HELM_VALUES} --set doc.preset=${PRESET}"
[ -n "$KEYPATH" ] && HELM_VALUES="${HELM_VALUES} --set doc.path=${KEYPATH}"
[ -n "$PARENTKEY" ] && HELM_VALUES="${HELM_VALUES} --set doc.key=${PARENTKEY}"
[ -n "$MINIMAL" ] && HELM_VALUES="${HELM_VALUES} --set doc.minimal=true"

## -- Execute Helm
$HELM_BIN template $HELM_VALUES ${HELM_ARGS} --dependency-update values-generator/
6 changes: 6 additions & 0 deletions charts/manifests/plugin/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: "manifests"
version: "0.1.0"
usage: "Get Manifest Values"
description: "Get Manifest Values"
ignoreFlags: false
command: "bash ./generator.sh"
23 changes: 23 additions & 0 deletions charts/manifests/plugin/values-generator/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
10 changes: 10 additions & 0 deletions charts/manifests/plugin/values-generator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v2
name: values
description: A Helm chart for Kubernetes
type: application
version: 1.0.0
appVersion: 1.16.0
dependencies:
- name: "manifests"
version: ">=0.1.0"
repository: https://bedag.github.io/helm-charts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- include "bedag-lib.values.generator" $ | nindent 0 }}
26 changes: 26 additions & 0 deletions charts/manifests/plugin/values-generator/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Enabled Values Generator
doc:

## Define which manifest to generate (e.g. "statfulset")
## On of .manifest or .preset has to be set, otherwise the function returns empty
manifest: ""

## Define which manifest to generate (e.g. "permissions")
## On of .manifest or .preset has to be set, otherwise the function returns empty
## The .manifest field takes precedence over the .preset field, if both are set.
preset: ""

## If you want your values to be in a more complex structure, you can define the yaml path
## This mostly matters for all the helm-docs fields being generated.
#path: "custom.sub.path"
path: ""

## Overwrite the top key for the values.
## E.g. for the manifest statefulset the default top key is "statefulset", which has all other
## keys as child. With this option you can change this key to e.g. "frontend"
key: ""

## A single manifest can have a lot of values. With enabling minimal output the values
## which come from sub templates or manifests will only be referenced as comment but not printed
## to keep your values slim.
minimal: false
8 changes: 4 additions & 4 deletions charts/manifests/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ args:

The default values for this preset go here:

**templates/values/presets/_say.yaml**
**templates/values/presets/_says.yaml**

```
{{- define "bedag-lib.presets.values.says" -}}
Expand Down Expand Up @@ -134,7 +134,7 @@ First i am creating the main file (do whatever structure you like, just make sur
*/}}
{{- define "bedag-lib.manifest.servicemonitor.values" -}}
{{- include "lib.utils.template" (dict "value" (include "bedag-lib.mergedValues" (dict "type" "serviceMonitor" "root" .)) "context" .context) -}}
{{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.mergedValues" (dict "type" "serviceMonitor" "root" .)) "context" .context) -}}
{{- end }}
Expand All @@ -157,7 +157,7 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "bedag-lib.fullname" . }}
labels: {{- include "lib.utils.labels" (dict "labels" $serviceMonitor.labels "context" $context)| nindent 4 }}
labels: {{- include "lib.utils.common.labels" (dict "labels" $serviceMonitor.labels "context" $context)| nindent 4 }}
{{- if $serviceMonitor.namespace }}
namespace: {{ $serviceMonitor.namespace }}
{{- end }}
Expand All @@ -167,7 +167,7 @@ spec:
{{- end }}
selector:
matchLabels:
endpoints: {{- include "lib.utils.template" (dict "value" $serviceMonitor.endpoints "context" $context) | nindent 4 }}
endpoints: {{- include "lib.utils.strings.template" (dict "value" $serviceMonitor.endpoints "context" $context) | nindent 4 }}
namespaceSelector:
matchNames:
{{- if $serviceMonitor.namespaceSelector }}
Expand Down
45 changes: 42 additions & 3 deletions charts/manifests/templates/manifests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ resources:
{{- if .Release.IsInstall }}
replicaCount: 1
{{- end }}
- type: "services"
- type: "service"
name: "headless"
values {{ toYaml .Values.service | nindent 6 }}
{{- end }}
Expand Down Expand Up @@ -114,7 +114,7 @@ resources:
This can be useful when adding CRDs or appending lose Kubernetes Resources to a release (By Chart User).


## [Extras](./templates/_bundleExtras.yaml)
## [Extras](./templates/_bundleExtras.tpl)

There are some extras/functionalities, which are only enabled when using a resource in a bundle. Getting the resource just by it's manifest template won't allow the functionality.

Expand Down Expand Up @@ -599,6 +599,45 @@ resources:
...
```

## ServiceMonitor

This Template returns a [ServiceMonitor](https://docs.openshift.com/container-platform/4.4/rest_api/monitoring_apis/servicemonitor-monitoring-coreos-com-v1.html) Kubernetes Manifest.

### Arguments

The following arguments are supported for this template. If a required argument is not given, the template will fail or return empty.

* `.values` - Supported key structure for this manifest (See below). Will be merged over the default values for this manifest (Optional).
* `.overwrites` - Supported key structure overwriting the structure given to `.values` (Optional).
* `.name` - Partial name for the manifest, influences the result of the `bedag-lib.fullname` template (Optional).
* `.fullname` - Full name for the manifest, influences the result of the `bedag-lib.fullname` template (Optional).
* `.context` - Inherited Root Context (Required)

### [Values](../values/manifests/_serviceMonitor.yaml)

You can access the supported values for this kubernetes manifest through clicking on values. These values represent the default values for this manifest.

### Templates

Does not implement any templates.

### Usage

```
{{ include "bedag-lib.manifest.servicemonitor" (dict "values" $.Values.serviceMonitor "fullname" "custom-sm" "context" $) }}
```

#### With Bundle

```
resources:
...
- type: "servicemonitor"
values: {{ toYaml $.Values.serviceMonitor | nindent 6 }}
fullname: "custom-sm"
...
```

## Statefulset

This Template returns a [Statefulset](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset//) Kubernetes Manifest.
Expand Down Expand Up @@ -760,7 +799,7 @@ Does not implement any templates.

See the following examples to get a better understanding of how you can use the manifest library. In the examples are no value structure documented. We are assuming that under there referenced key are the default keys for each manifest (generated by the values generator). Your creativity is the limit! :)

We are implementing structure using these structures with most charts hosted in this repository. So take a look at other charts for reference. We have extensive examples in the [manifest-testing](../../../manifests-testing) chart.
We are implementing structure using these structures with most charts hosted in this repository. So take a look at other charts for reference.

## Simple Bundle

Expand Down
8 changes: 4 additions & 4 deletions charts/manifests/templates/manifests/_bundle.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.
{{- define "bedag-lib.manifest.bundle" -}}
{{- $manifestPath := "bedag-lib.manifest." -}}
{{- if and .context (kindIs "map" .context) .bundle (kindIs "map" .bundle) -}}
{{- $context := mergeOverwrite .context (default dict (fromYaml (include "lib.utils.parentAppend" .bundle.common))) -}}
{{- $context := mergeOverwrite .context (default dict (fromYaml (include "lib.utils.dicts.parentAppend" .bundle.common))) -}}
{{- if $.bundle.name }}
{{- $_ := set $context "bundlename" $.bundle.name -}}
{{- end }}
Expand All @@ -28,14 +28,14 @@ limitations under the License.
apiVersion: v1
kind: List
metadata:
name: {{ include "bedag-lib.fullname" $context }}
labels: {{- include "lib.utils.labels" $context | nindent 4 }}
name: {{ include "bedag-lib.utils.common.fullname" $context }}
labels: {{- include "lib.utils.common.labels" $context | nindent 4 }}
items:
{{- range .bundle.resources -}}
{{- $type := required "Missing required field '.type' for resource in bundle" .type | lower }}
{{- $manifest := (cat $manifestPath $type | nospace) -}}
{{- if and (eq $type "raw") .manifest }}
- {{- include "lib.utils.template" (dict "value" .manifest "context" $context) | nindent 4 }}
- {{- include "lib.utils.strings.template" (dict "value" .manifest "context" $context) | nindent 4 }}
{{- else }}
{{- $v_params := set . "context" $context }}
{{- $values := (fromYaml (include (cat $manifest ".values" | nospace) $v_params)) }}
Expand Down
6 changes: 3 additions & 3 deletions charts/manifests/templates/manifests/_cronjob.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
*/}}
{{- define "bedag-lib.manifest.cronjob.values" -}}
{{- include "lib.utils.template" (dict "value" (include "bedag-lib.mergedValues" (dict "type" "cronjob" "root" .)) "context" .context) -}}
{{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "cronjob" "root" .)) "context" .context) -}}
{{- end }}

{{- define "bedag-lib.manifest.cronjob" -}}
Expand All @@ -31,8 +31,8 @@ apiVersion: {{ $cronjob.apiVersion }}
apiVersion: batch/v1
{{- end }}
metadata:
name: {{ include "bedag-lib.fullname" . }}
labels: {{- include "lib.utils.labels" (dict "labels" $cronjob.labels "context" $context)| nindent 4 }}
name: {{ include "bedag-lib.utils.common.fullname" . }}
labels: {{- include "lib.utils.common.labels" (dict "labels" $cronjob.labels "context" $context)| nindent 4 }}
{{- if $cronjob.annotations }}
annotations:
{{- range $anno, $val := $cronjob.annotations }}
Expand Down
Loading

0 comments on commit cb86081

Please sign in to comment.