Skip to content

Commit e31aed6

Browse files
committed
Add Helm chart
Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp>
1 parent a81feb3 commit e31aed6

File tree

24 files changed

+1316
-16
lines changed

24 files changed

+1316
-16
lines changed

Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ help: ## Display this help.
2121
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
2222

2323
.PHONY: manifests
24-
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
25-
$(CONTROLLER_GEN) rbac:roleName=imageprefetch-controller-role crd paths="./..." output:crd:artifacts:config=config/crd/bases
24+
manifests: controller-gen kustomize yq ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
25+
$(CONTROLLER_GEN) rbac:roleName=controller-manager-role crd paths="./..." output:crd:artifacts:config=config/crd/bases
26+
echo '{{- if .Values.crds.enabled }}' > charts/ofen/templates/generated/crds/crds.yaml
27+
$(KUSTOMIZE) build config/kustomize-to-helm/overlays/crds | $(YQ) e "." - >> charts/ofen/templates/generated/crds/crds.yaml
28+
echo '{{- end }}' >> charts/ofen/templates/generated/crds/crds.yaml
29+
kustomize build config/kustomize-to-helm/overlays/templates | yq e "." -p yaml - > charts/ofen/templates/generated/generated.yaml
2630

2731
.PHONY: generate
2832
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -138,6 +142,7 @@ GINKGO = $(LOCALBIN)/ginkgo
138142
APPLYCONFIGURATION_GEN = $(LOCALBIN)/applyconfiguration-gen
139143
MODELS_SCHEMA = $(LOCALBIN)/models-schema
140144
KAPTEST ?= $(LOCALBIN)/kaptest
145+
YQ ?= $(LOCALBIN)/yq
141146

142147
## Tool Versions
143148
KUSTOMIZE_VERSION ?= v5.6.0
@@ -148,6 +153,7 @@ GINKGO_VERSION ?= v2.23.4
148153
CODE_GENERATOR_VERSION ?= v0.31.1
149154
MODELS_SCHEMA_VERSION ?= v1.31.1
150155
KAPTEST_VERSION ?= v0.1.2
156+
YQ_VERSION ?= v4.47.1
151157

152158
.PHONY: kustomize
153159
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -196,6 +202,15 @@ $(KAPTEST): $(LOCALBIN)
196202
tar -xzf kaptest_Linux_x86_64.tar.gz -C $(LOCALBIN) kaptest && \
197203
rm -f kaptest_Linux_x86_64.tar.gz
198204

205+
.PHONY: yq
206+
yq: $(YQ) ## Download yq locally if necessary.
207+
$(YQ): $(LOCALBIN)
208+
curl -sLO "https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_linux_amd64.tar.gz" && \
209+
tar -xzf yq_linux_amd64.tar.gz ./yq_linux_amd64 && \
210+
mv yq_linux_amd64 $(YQ) && \
211+
chmod +x $(YQ) && \
212+
rm -f yq_linux_amd64.tar.gz
213+
199214
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
200215
# $1 - target path with name of binary
201216
# $2 - package url which can be installed

charts/ofen/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/ofen/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: ofen
3+
description: Ofen is a kubernetes controller that prefetch(preheat) container images.
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "0.1.0"

charts/ofen/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Ofen Helm Chart
2+
3+
## How to use Ofen Helm repository
4+
5+
You need to add this repository to your Helm repositories:
6+
7+
```console
8+
helm repo add ofen https://cybozu-go.github.io/ofen/
9+
helm repo update
10+
```
11+
12+
## Quick start
13+
14+
### Installing the Chart
15+
16+
To install the chart with the release name `ofen` using a dedicated namespace(recommended):
17+
18+
```console
19+
$ helm install --create-namespace --namespace ofen-system ofen ofen/ofen
20+
```
21+
22+
Specify parameters using `--set key=value[,key=value]` argument to `helm install`.
23+
24+
Alternatively a YAML file that specifies the values for the parameters can be provided like this:
25+
26+
```console
27+
$ helm install --create-namespace --namespace ofen-system ofen -f values.yaml ofen/ofen
28+
```
29+
30+
## Values
31+
32+
| Key | Type | Default | Description |
33+
| ---------------------------- | ------ | --------------------------------------------- | ---------------------------------------------------------------------------------- |
34+
| crds.enabled | bool | `true` | Install and update CRDs as part of the Helm chart. |
35+
| crds.keep | bool | `true` | Keep existing CRDs during uninstallation. |
36+
| controller.replicas | int | `2` | Number of replicas for the ofen-controller Deployment. |
37+
| controller.image.repository | string | `"ghcr.io/cybozu-go/ofen"` | ofen-controller image repository to use. |
38+
| controller.image.pullPolicy | string | `"IfNotPresent"` | ofen-controller image pull policy. |
39+
| controller.image.tag | string | `""` | ofen-controller image tag to use. |
40+
| controller.imagePullSecrets | list | `[]` | Secrets for pulling the ofen-controller image from a private repository. |
41+
| controller.resources | object | `{"requests":{"cpu":"100m","memory":"20Mi"}}` | Resource requests and limits for the ofen-controller Deployment. |
42+
| controller.extraArgs | list | `[]` | Additional command line arguments to pass to the ofen-controller binary. |
43+
| daemon.image.repository | string | `"ghcr.io/cybozu-go/ofend"` | ofen-daemon image repository to use. |
44+
| daemon.image.pullPolicy | string | `"IfNotPresent"` | ofen-daemon image pull policy. |
45+
| daemon.image.tag | string | `""` | ofen-daemon image tag to use. |
46+
| daemon.imagePullSecrets | list | `[]` | Secrets for pulling the ofen-daemon image from a private repository. |
47+
| daemon.resources | object | `{"requests":{"cpu":"100m","memory":"20Mi"}}` | Resource requests and limits for the ofen-daemon DaemonSet. |
48+
| daemon.extraArgs | list | `[]` | Additional command line arguments to pass to the ofen-daemon binary. |
49+
| daemon.containerdSockPath | string | `"/run/containerd/containerd.sock"` | Path to the containerd socket. |
50+
| daemon.containerdHostDirPath | string | `"/etc/containerd/certs.d"` | Path to the host directory where containerd certificate configurations are stored. |
51+
| allowRegistries.ghcr | string | `"ghcr.io/"` | Allow pulling images from the ghcr.io registry. |
52+
| allowRegistries.quay | string | `"quay.io/"` | Allow pulling images from the quay.io registry. |
53+
54+
## Generate Manifests
55+
56+
You can use the `helm template` command to render manifests.
57+
58+
```console
59+
$ helm template --namespace ofen ofen ofen/ofen
60+
```
61+
62+
## CRD considerations
63+
64+
### Installing or updating CRDs
65+
66+
Ofen Helm Chart installs or updates CRDs by default. If you want to manage CRDs on your own, turn off the `crds.enabled` parameter.
67+
68+
### Removing CRDs
69+
70+
Helm does not remove the CRDs due to the [`helm.sh/resource-policy: keep` annotation](https://helm.sh/docs/howto/charts_tips_and_tricks/#tell-helm-not-to-uninstall-a-resource).
71+
When uninstalling, please remove the CRDs manually.

charts/ofen/templates/NOTES.txt

Whitespace-only changes.

charts/ofen/templates/_helpers.tpl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "ofen.name" -}}
5+
{{- default .Chart.Name | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "ofen.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "ofen.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "ofen.labels" -}}
37+
helm.sh/chart: {{ include "ofen.chart" . }}
38+
{{- if .Chart.AppVersion }}
39+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
40+
{{- end }}
41+
app.kubernetes.io/managed-by: {{ .Release.Service }}
42+
{{- end }}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: ofend-daemon
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
app.kubernetes.io/component: daemon
8+
app.kubernetes.io/name: {{ include "ofen.name" . }}-daemon
9+
{{- include "ofen.labels" . | nindent 4 }}
10+
spec:
11+
selector:
12+
matchLabels:
13+
app.kubernetes.io/component: daemon
14+
app.kubernetes.io/name: {{ include "ofen.name" . }}-daemon
15+
template:
16+
metadata:
17+
labels:
18+
app.kubernetes.io/component: daemon
19+
app.kubernetes.io/name: {{ include "ofen.name" . }}-daemon
20+
spec:
21+
containers:
22+
- name: ofend
23+
image: "{{ .Values.daemon.image.repository }}:{{ default .Chart.AppVersion .Values.daemon.image.tag }}"
24+
imagePullPolicy: {{ .Values.daemon.image.pullPolicy }}
25+
args:
26+
- --containerd-socket={{ .Values.daemon.containerdSockPath }}
27+
- --containerd-host-dir={{ .Values.daemon.containerdHostDirPath }}
28+
{{- with .Values.daemon.extraArgs }}
29+
{{- toYaml . | nindent 12 }}
30+
{{- end }}
31+
env:
32+
- name: NODE_NAME
33+
valueFrom:
34+
fieldRef:
35+
fieldPath: spec.nodeName
36+
ports:
37+
- containerPort: 8081
38+
name: health
39+
protocol: TCP
40+
- containerPort: 8080
41+
name: metrics
42+
protocol: TCP
43+
{{- with .Values.daemon.resources }}
44+
resources: {{ toYaml . | nindent 12 }}
45+
{{- end }}
46+
livenessProbe:
47+
httpGet:
48+
path: /healthz
49+
port: health
50+
initialDelaySeconds: 15
51+
periodSeconds: 20
52+
readinessProbe:
53+
httpGet:
54+
path: /readyz
55+
port: health
56+
initialDelaySeconds: 5
57+
periodSeconds: 10
58+
volumeMounts:
59+
- name: containerd-sock
60+
mountPath: {{ .Values.daemon.containerdSockPath }}
61+
- name: containerd-host-dir
62+
mountPath: {{ .Values.daemon.containerdHostDirPath }}
63+
securityContext:
64+
runAsUser: 0 # Run as root to mount containerd socket
65+
serviceAccountName: '{{ template "ofen.fullname" . }}-controller-manager'
66+
terminationGracePeriodSeconds: 10
67+
volumes:
68+
- name: containerd-sock
69+
hostPath:
70+
path: {{ .Values.daemon.containerdSockPath }}
71+
- name: containerd-host-dir
72+
hostPath:
73+
path: {{ .Values.daemon.containerdHostDirPath }}
74+
tolerations:
75+
- key: node-role.kubernetes.io/control-plane
76+
effect: NoSchedule
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: ofen-controller
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
app.kubernetes.io/component: controller
8+
app.kubernetes.io/name: {{ include "ofen.name" . }}-controller
9+
{{- include "ofen.labels" . | nindent 4 }}
10+
spec:
11+
replicas: {{ .Values.controller.replicas }}
12+
selector:
13+
matchLabels:
14+
app.kubernetes.io/component: controller
15+
app.kubernetes.io/name: {{ include "ofen.name" . }}-controller
16+
template:
17+
metadata:
18+
labels:
19+
app.kubernetes.io/component: controller
20+
app.kubernetes.io/name: {{ include "ofen.name" . }}-controller
21+
spec:
22+
containers:
23+
- name: manager
24+
image: "{{ .Values.controller.image.repository }}:{{ default .Chart.AppVersion .Values.controller.image.tag }}"
25+
imagePullPolicy: {{ .Values.controller.image.pullPolicy }}
26+
args:
27+
- -leader-elect=true
28+
{{- with .Values.controller.extraArgs }}
29+
{{- toYaml . | nindent 12 }}
30+
{{- end }}
31+
ports:
32+
- containerPort: 8081
33+
name: health
34+
protocol: TCP
35+
- containerPort: 8080
36+
name: metrics
37+
protocol: TCP
38+
{{- with .Values.controller.resources }}
39+
resources: {{ toYaml . | nindent 12 }}
40+
{{- end }}
41+
securityContext:
42+
allowPrivilegeEscalation: false
43+
livenessProbe:
44+
httpGet:
45+
path: /healthz
46+
port: health
47+
initialDelaySeconds: 15
48+
periodSeconds: 20
49+
readinessProbe:
50+
httpGet:
51+
path: /readyz
52+
port: health
53+
initialDelaySeconds: 5
54+
periodSeconds: 10
55+
securityContext:
56+
runAsNonRoot: true
57+
serviceAccountName: '{{ template "ofen.fullname" . }}-controller-manager'
58+
terminationGracePeriodSeconds: 10

0 commit comments

Comments
 (0)