Skip to content

Commit

Permalink
Merge pull request #24 from ameijer/job
Browse files Browse the repository at this point in the history
first pass at job
  • Loading branch information
ameijer authored Apr 24, 2021
2 parents a74bcd3 + 659d0c2 commit b9c315e
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ API Object | Status | Link
`ReplicaSet` | TODO |
`ReplicationController` | TODO |
`StatefulSet` | TODO |
`Job` | TODO |
`Job` | :heavy_check_mark: | [job](https:/ameijer/k8s-as-helm/tree/master/charts/job)
`CronJob` | TODO |
`Deployment` | TODO |
`DaemonSet` | TODO |
Expand Down
6 changes: 6 additions & 0 deletions charts/job/Chart.lock
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions charts/job/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v2
appVersion: "v1.0.0"
home: https:/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:/ameijer
keywords:
- job
- api
- primitives
2 changes: 2 additions & 0 deletions charts/job/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

The Job Chart {{ .Release.Name }} has been installed into your cluster!
55 changes: 55 additions & 0 deletions charts/job/README.md
Original file line number Diff line number Diff line change
@@ -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:/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)
Binary file added charts/job/charts/lib-k8s-as-helm-1.1.0.tgz
Binary file not shown.
23 changes: 23 additions & 0 deletions charts/job/ci/ci-values.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions charts/job/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 "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 -}}
17 changes: 17 additions & 0 deletions charts/job/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -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" . ) . }}
Empty file added charts/job/values.yaml
Empty file.
2 changes: 1 addition & 1 deletion charts/lib-k8s-as-helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ appVersion: 1.0.0
home: https:/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:
Expand Down
20 changes: 20 additions & 0 deletions charts/lib-k8s-as-helm/templates/_job.yaml
Original file line number Diff line number Diff line change
@@ -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 -}}

0 comments on commit b9c315e

Please sign in to comment.