diff --git a/README.md b/README.md index d5ad03c..7e99eb4 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ API Object | Status | Link `ReplicaSet` | TODO | `ReplicationController` | TODO | `StatefulSet` | TODO | -`Job` | TODO | +`Job` | :heavy_check_mark: | [job](https://github.com/ameijer/k8s-as-helm/tree/master/charts/job) `CronJob` | TODO | `Deployment` | TODO | `DaemonSet` | TODO | diff --git a/charts/job/Chart.lock b/charts/job/Chart.lock new file mode 100644 index 0000000..5f9112a --- /dev/null +++ b/charts/job/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: lib-k8s-as-helm + repository: file://../lib-k8s-as-helm + version: 1.1.0 +digest: sha256:af89aadcdc81278d8787e1b5887a225e145d531b8cb4cd54ddc6b3412051448e +generated: "2021-04-24T17:29:22.069848381-04:00" diff --git a/charts/job/Chart.yaml b/charts/job/Chart.yaml new file mode 100644 index 0000000..1703cf3 --- /dev/null +++ b/charts/job/Chart.yaml @@ -0,0 +1,18 @@ +apiVersion: v2 +appVersion: "v1.0.0" +home: https://github.com/ameijer/k8s-as-helm +description: Helm Chart representing a single Job Kubernetes API object +name: job +version: 1.0.0 +icon: https://ameijer.github.io/k8s-as-helm/icon.png +dependencies: +- name: lib-k8s-as-helm + version: 1.1.0 + repository: file://../lib-k8s-as-helm +maintainers: + - name: ameijer + url: https://github.com/ameijer +keywords: +- job +- api +- primitives diff --git a/charts/job/NOTES.txt b/charts/job/NOTES.txt new file mode 100644 index 0000000..b793e59 --- /dev/null +++ b/charts/job/NOTES.txt @@ -0,0 +1,2 @@ + +The Job Chart {{ .Release.Name }} has been installed into your cluster! diff --git a/charts/job/README.md b/charts/job/README.md new file mode 100644 index 0000000..2d29334 --- /dev/null +++ b/charts/job/README.md @@ -0,0 +1,55 @@ +# Job 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/job +``` + +## 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 pod chart deploys a single Kubernetes Job object. + +## Installation + +```console +$ helm repo add k8s-as-helm https://ameijer.github.io/k8s-as-helm/ +$ helm install my-release k8s-as-helm/job +``` + +## Configuration + +The following table lists the configurable parameters of the pod chart and their default values. + +Parameter | Description | Default +--- | --- | --- +`nameOverride` | override name of the chart component | .Release.Name +`apiVersion` | api version of k8s object | `"batch/v1"` +`annotations` | annotations in yaml map format to be added to the object | `null` +`labels` | labels to add to Job object | `null` +`containers` | Array of container objects in the job pods | `[]` +`containers[].name` | The name of the given container | `null` +`containers[].image` | The image of the given container | `null` +`containers[].extraSettings` | YAML representation of additional config settings for the given container | `null` +`containers[].volumeMounts` | Map of volume mount names to settings for each given mount | `null` +`dnsPolicy` | The job pod DNS policy | `ClusterFirst` +`restartPolicy` | The restart policy of the pods in the job | `Always` +`saName` | The job pod service account name | `default` +`tgps` | The job pods' terminationGracePeriodSeconds setting | `30` +`extraSettings` | Yaml representation of any additional required pod settings | `null` +`volumes` | Mapping of volume name to volume settings for each volume mount used by the job pods | `null` +`backoffLimit` | The job's backoffLimit settings. Leave unset to use defaults | `null` +`activeDeadlineSeconds` | The maximum time the job may take. Leave unset to use default 600 seconds | `null` +`parallelism` | The parallelism of the pods in the job. Leave unset to use default of no parallelism | `null` +`completions` | The number of successful pod completions for the job. Leave unset to use the default of 1 | `null` +`completionMode` | Set to `Indexed` to pass an index to each pod. Leave unset to omit index passing. | `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) diff --git a/charts/job/charts/lib-k8s-as-helm-1.1.0.tgz b/charts/job/charts/lib-k8s-as-helm-1.1.0.tgz new file mode 100644 index 0000000..d49f6e1 Binary files /dev/null and b/charts/job/charts/lib-k8s-as-helm-1.1.0.tgz differ diff --git a/charts/job/ci/ci-values.yaml b/charts/job/ci/ci-values.yaml new file mode 100644 index 0000000..20d91c0 --- /dev/null +++ b/charts/job/ci/ci-values.yaml @@ -0,0 +1,23 @@ +labels: + "test": "true" + +containers: + testcontainer1: + image: busybox + extraSettings: + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - | + echo "hello world, running the job!" +restartPolicy: Never +extraSettings: + securityContext: + runAsNonRoot: true + runAsUser: 1000 + +backoffLimit: 7 +completions: 7 +parallelism: 2 +activeDeadlineSeconds: 601 diff --git a/charts/job/templates/_helpers.tpl b/charts/job/templates/_helpers.tpl new file mode 100644 index 0000000..ecd3cc1 --- /dev/null +++ b/charts/job/templates/_helpers.tpl @@ -0,0 +1,14 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Setup a chart name +*/}} +{{- define "job.name" -}} +{{- default .Release.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Return the appropriate apiVersion for the object +*/}} +{{- define "apiVersion" -}} +{{- default "batch/v1" .Values.apiVersion -}} +{{- end -}} diff --git a/charts/job/templates/job.yaml b/charts/job/templates/job.yaml new file mode 100644 index 0000000..2780163 --- /dev/null +++ b/charts/job/templates/job.yaml @@ -0,0 +1,17 @@ +kind: Job +apiVersion: {{ template "apiVersion" . }} +metadata: + name: {{ template "job.name" . }} +{{- if .Values.annotations }} + annotations: +{{ toYaml .Values.annotations | indent 4}} +{{- end }} + labels: + app: {{ template "job.name" . }} + chart: {{ .Chart.Name }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{- if .Values.labels }} +{{ toYaml .Values.labels | indent 4 }} +{{- end }} +{{ tpl ( include "k8s-as-helm-lib.job.tpl" . ) . }} diff --git a/charts/job/values.yaml b/charts/job/values.yaml new file mode 100644 index 0000000..e69de29 diff --git a/charts/lib-k8s-as-helm/Chart.yaml b/charts/lib-k8s-as-helm/Chart.yaml index 47aa8c2..3165d0b 100644 --- a/charts/lib-k8s-as-helm/Chart.yaml +++ b/charts/lib-k8s-as-helm/Chart.yaml @@ -3,7 +3,7 @@ appVersion: 1.0.0 home: https://github.com/ameijer/k8s-as-helm description: Library chart backing portions of the k8s-as-helm project name: lib-k8s-as-helm -version: 1.0.1 +version: 1.1.0 icon: https://ameijer.github.io/k8s-as-helm/icon.png type: library maintainers: diff --git a/charts/lib-k8s-as-helm/templates/_job.yaml b/charts/lib-k8s-as-helm/templates/_job.yaml new file mode 100644 index 0000000..6d3e62d --- /dev/null +++ b/charts/lib-k8s-as-helm/templates/_job.yaml @@ -0,0 +1,20 @@ +{{- define "k8s-as-helm-lib.job.tpl" -}} +spec: +{{ if .Values.backoff }} + backoffLimit: {{ .Values.backoff }} +{{- end }} +{{ if .Values.deadlineSec }} + activeDeadlineSeconds: {{ .Values.deadlineSec }} +{{- end }} +{{ if .Values.parallelism }} + parallelism: {{ .Values.parallelism }} +{{- end }} +{{ if .Values.completions }} + completions: {{ .Values.completions }} +{{- end }} +{{ if .Values.completionMode }} + completionMode: {{ .Values.completionMode }} +{{- end }} + template: +{{ tpl ( include "k8s-as-helm-lib.pod.tpl" . ) . | indent 4 }} +{{- end -}}