Skip to content

Commit 6e01cdb

Browse files
authored
Add helm chart (#22)
* Add Helm chart Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Refactor labels in DaemonSet and Deployment templates to remove suffixes Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Remove leader election configuration from deployment and values files Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Add imagePullSecrets configuration to DaemonSet and Deployment templates Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Add support for nodeSelector, affinity, tolerations, topologySpreadConstraints, and priorityClassName in controller values Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Add support for nodeSelector, affinity, tolerations, and priorityClassName in daemon values Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Refactor ConfigMap labels to use centralized label template Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Remove redundant app.kubernetes.io/name label from DaemonSet and Deployment templates Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Add PodDisruptionBudget template for controller component Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> * Add pod anti-affinity rules for ofen-controller Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp> --------- Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp>
1 parent a81feb3 commit 6e01cdb

25 files changed

+1400
-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: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 | list | `[]` | Allow pulling images from some registries. |
52+
53+
## Generate Manifests
54+
55+
You can use the `helm template` command to render manifests.
56+
57+
```console
58+
$ helm template --namespace ofen ofen ofen/ofen
59+
```
60+
61+
## CRD considerations
62+
63+
### Installing or updating CRDs
64+
65+
Ofen Helm Chart installs or updates CRDs by default. If you want to manage CRDs on your own, turn off the `crds.enabled` parameter.
66+
67+
### Removing CRDs
68+
69+
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).
70+
When uninstalling, please remove the CRDs manually.

charts/ofen/templates/NOTES.txt

Whitespace-only changes.

charts/ofen/templates/_helpers.tpl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
app.kubernetes.io/name: {{ include "ofen.name" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
labels:
5+
{{- include "ofen.labels" . | nindent 4 }}
6+
name: '{{ template "ofen.fullname" . }}-registry-allowlist'
7+
namespace: '{{ .Release.Namespace }}'
8+
data:
9+
{{- with .Values.allowRegistries }}
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: ofen-daemon
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
app.kubernetes.io/component: daemon
8+
{{- include "ofen.labels" . | nindent 4 }}
9+
spec:
10+
selector:
11+
matchLabels:
12+
app.kubernetes.io/component: daemon
13+
app.kubernetes.io/name: {{ include "ofen.name" . }}
14+
template:
15+
metadata:
16+
labels:
17+
app.kubernetes.io/component: daemon
18+
app.kubernetes.io/name: {{ include "ofen.name" . }}
19+
spec:
20+
containers:
21+
- name: ofend
22+
image: "{{ .Values.daemon.image.repository }}:{{ default .Chart.AppVersion .Values.daemon.image.tag }}"
23+
imagePullPolicy: {{ .Values.daemon.image.pullPolicy }}
24+
args:
25+
- --containerd-socket={{ .Values.daemon.containerdSockPath }}
26+
- --containerd-host-dir={{ .Values.daemon.containerdHostDirPath }}
27+
{{- with .Values.daemon.extraArgs }}
28+
{{- toYaml . | nindent 12 }}
29+
{{- end }}
30+
env:
31+
- name: NODE_NAME
32+
valueFrom:
33+
fieldRef:
34+
fieldPath: spec.nodeName
35+
ports:
36+
- containerPort: 8081
37+
name: health
38+
protocol: TCP
39+
- containerPort: 8080
40+
name: metrics
41+
protocol: TCP
42+
{{- with .Values.daemon.resources }}
43+
resources: {{ toYaml . | nindent 12 }}
44+
{{- end }}
45+
livenessProbe:
46+
httpGet:
47+
path: /healthz
48+
port: health
49+
initialDelaySeconds: 15
50+
periodSeconds: 20
51+
readinessProbe:
52+
httpGet:
53+
path: /readyz
54+
port: health
55+
initialDelaySeconds: 5
56+
periodSeconds: 10
57+
volumeMounts:
58+
- name: containerd-sock
59+
mountPath: {{ .Values.daemon.containerdSockPath }}
60+
- name: containerd-host-dir
61+
mountPath: {{ .Values.daemon.containerdHostDirPath }}
62+
securityContext:
63+
runAsUser: 0 # Run as root to mount containerd socket
64+
serviceAccountName: '{{ template "ofen.fullname" . }}-controller-manager'
65+
terminationGracePeriodSeconds: 10
66+
{{- with .Values.daemon.imagePullSecrets }}
67+
imagePullSecrets:
68+
{{- toYaml . | nindent 8 }}
69+
{{- end }}
70+
{{- with .Values.daemon.priorityClassName}}
71+
priorityClassName: {{ quote . }}
72+
{{- end }}
73+
{{- with .Values.daemon.nodeSelector }}
74+
{{- end }}
75+
{{- with .Values.daemon.nodeSelector }}
76+
nodeSelector:
77+
{{- toYaml . | nindent 8 }}
78+
{{- end }}
79+
{{- with .Values.daemon.affinity }}
80+
affinity:
81+
{{- toYaml . | nindent 8 }}
82+
{{- end }}
83+
{{- with .Values.daemon.tolerations }}
84+
tolerations:
85+
{{- toYaml . | nindent 8 }}
86+
{{- end }}
87+
volumes:
88+
- name: containerd-sock
89+
hostPath:
90+
path: {{ .Values.daemon.containerdSockPath }}
91+
- name: containerd-host-dir
92+
hostPath:
93+
path: {{ .Values.daemon.containerdHostDirPath }}
94+
tolerations:
95+
- key: node-role.kubernetes.io/control-plane
96+
effect: NoSchedule
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
{{- include "ofen.labels" . | nindent 4 }}
9+
spec:
10+
replicas: {{ .Values.controller.replicas }}
11+
selector:
12+
matchLabels:
13+
app.kubernetes.io/component: controller
14+
app.kubernetes.io/name: {{ include "ofen.name" . }}
15+
template:
16+
metadata:
17+
labels:
18+
app.kubernetes.io/component: controller
19+
app.kubernetes.io/name: {{ include "ofen.name" . }}
20+
spec:
21+
containers:
22+
- name: manager
23+
image: "{{ .Values.controller.image.repository }}:{{ default .Chart.AppVersion .Values.controller.image.tag }}"
24+
imagePullPolicy: {{ .Values.controller.image.pullPolicy }}
25+
{{- with .Values.controller.extraArgs }}
26+
args:
27+
{{- toYaml . | nindent 12 }}
28+
{{- end }}
29+
ports:
30+
- containerPort: 8081
31+
name: health
32+
protocol: TCP
33+
- containerPort: 8080
34+
name: metrics
35+
protocol: TCP
36+
{{- with .Values.controller.resources }}
37+
resources: {{ toYaml . | nindent 12 }}
38+
{{- end }}
39+
securityContext:
40+
allowPrivilegeEscalation: false
41+
livenessProbe:
42+
httpGet:
43+
path: /healthz
44+
port: health
45+
initialDelaySeconds: 15
46+
periodSeconds: 20
47+
readinessProbe:
48+
httpGet:
49+
path: /readyz
50+
port: health
51+
initialDelaySeconds: 5
52+
periodSeconds: 10
53+
{{- with .Values.controller.priorityClassName}}
54+
priorityClassName: {{ quote . }}
55+
{{- end }}
56+
{{- with .Values.controller.nodeSelector }}
57+
nodeSelector:
58+
{{- toYaml . | nindent 8 }}
59+
{{- end }}
60+
{{- with .Values.controller.affinity }}
61+
affinity:
62+
{{- toYaml . | nindent 8 }}
63+
{{- end }}
64+
{{- with .Values.controller.tolerations }}
65+
tolerations:
66+
{{- toYaml . | nindent 8 }}
67+
{{- end }}
68+
{{- with .Values.controller.topologySpreadConstraints }}
69+
topologySpreadConstraints:
70+
{{- toYaml . | nindent 8 }}
71+
{{- end }}
72+
securityContext:
73+
runAsNonRoot: true
74+
serviceAccountName: '{{ template "ofen.fullname" . }}-controller-manager'
75+
terminationGracePeriodSeconds: 10
76+
{{- with .Values.controller.imagePullSecrets }}
77+
imagePullSecrets:
78+
{{- toYaml . | nindent 8 }}
79+
{{- end }}

0 commit comments

Comments
 (0)