Skip to content

Commit b63edd6

Browse files
csviriCopilot
andauthored
Generic Helm Chart (#3266)
* Generic Helm Chart - adds generic helm chart that can be reused and extended by users for their operators - adjusts metrics processing e2e test to use that helm chart - adjusts PR to run unit tests for helm chart Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * wip Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * Update helm/generic-helm-chart/templates/deployment.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * wip Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * wip Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * wip Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * wip Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * helm chart fix Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * wip Signed-off-by: Attila Mészáros <a_meszaros@apple.com> * tests for env vars Signed-off-by: Attila Mészáros <a_meszaros@apple.com> --------- Signed-off-by: Attila Mészáros <a_meszaros@apple.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9342240 commit b63edd6

File tree

22 files changed

+1491
-135
lines changed

22 files changed

+1491
-135
lines changed

.github/workflows/pr.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ jobs:
3333

3434
build:
3535
uses: ./.github/workflows/build.yml
36+
37+
helm_unit_tests:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v6
41+
- name: Set up Helm
42+
uses: azure/setup-helm@v4
43+
- name: Run Helm unit tests
44+
run: ./helm/run-tests.sh

helm/generic-helm-chart/Chart.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright Java Operator SDK Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
apiVersion: v2
18+
name: generic-operator-chart
19+
description: A generic reusable Helm chart for Java operators built with Java Operator SDK (JOSDK)
20+
type: application
21+
version: 0.1.0
22+
appVersion: "0.1.0"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "generic-operator.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
*/}}
11+
{{- define "generic-operator.fullname" -}}
12+
{{- if .Values.fullnameOverride }}
13+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
14+
{{- else }}
15+
{{- $name := default .Chart.Name .Values.nameOverride }}
16+
{{- if contains $name .Release.Name }}
17+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
18+
{{- else }}
19+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
20+
{{- end }}
21+
{{- end }}
22+
{{- end }}
23+
24+
{{/*
25+
Create chart name and version as used by the chart label.
26+
*/}}
27+
{{- define "generic-operator.chart" -}}
28+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
29+
{{- end }}
30+
31+
{{/*
32+
Common labels
33+
*/}}
34+
{{- define "generic-operator.labels" -}}
35+
helm.sh/chart: {{ include "generic-operator.chart" . }}
36+
{{ include "generic-operator.selectorLabels" . }}
37+
{{- if .Chart.AppVersion }}
38+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
39+
{{- end }}
40+
app.kubernetes.io/managed-by: {{ .Release.Service }}
41+
{{- end }}
42+
43+
{{/*
44+
Selector labels
45+
*/}}
46+
{{- define "generic-operator.selectorLabels" -}}
47+
app.kubernetes.io/name: {{ include "generic-operator.name" . }}
48+
app.kubernetes.io/instance: {{ .Release.Name }}
49+
{{- end }}
50+
51+
{{/*
52+
Create the name of the service account to use
53+
*/}}
54+
{{- define "generic-operator.serviceAccountName" -}}
55+
{{- if .Values.serviceAccount.create }}
56+
{{- default (include "generic-operator.fullname" .) .Values.serviceAccount.name }}
57+
{{- else }}
58+
{{- default "default" .Values.serviceAccount.name }}
59+
{{- end }}
60+
{{- end }}
61+
62+
{{/*
63+
Image tag - defaults to chart appVersion
64+
*/}}
65+
{{- define "generic-operator.imageTag" -}}
66+
{{- .Values.image.tag | default .Chart.AppVersion }}
67+
{{- end }}
68+
69+
{{/*
70+
Default verbs for primary resources
71+
*/}}
72+
{{- define "generic-operator.primaryVerbs" -}}
73+
- get
74+
- list
75+
- watch
76+
- patch
77+
- update
78+
{{- end }}
79+
80+
{{/*
81+
Default verbs for primary resource status
82+
*/}}
83+
{{- define "generic-operator.primaryStatusVerbs" -}}
84+
- get
85+
- patch
86+
- update
87+
{{- end }}
88+
89+
{{/*
90+
Default verbs for secondary resources
91+
*/}}
92+
{{- define "generic-operator.secondaryVerbs" -}}
93+
- get
94+
- list
95+
- watch
96+
- create
97+
- update
98+
- patch
99+
- delete
100+
{{- end }}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#
2+
# Copyright Java Operator SDK Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
{{- if .Values.rbac.create }}
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
kind: ClusterRole
20+
metadata:
21+
name: {{ include "generic-operator.fullname" . }}
22+
labels:
23+
{{- include "generic-operator.labels" . | nindent 4 }}
24+
rules:
25+
{{- /* Primary resources - the custom resources the operator reconciles */}}
26+
{{- range .Values.primaryResources }}
27+
- apiGroups:
28+
- {{ .apiGroup | quote }}
29+
resources:
30+
{{- range .resources }}
31+
- {{ . }}
32+
{{- end }}
33+
verbs:
34+
{{- if .verbs }}
35+
{{- range .verbs }}
36+
- {{ . }}
37+
{{- end }}
38+
{{- else }}
39+
{{- include "generic-operator.primaryVerbs" $ | nindent 2 }}
40+
{{- end }}
41+
- apiGroups:
42+
- {{ .apiGroup | quote }}
43+
resources:
44+
{{- range .resources }}
45+
- {{ . }}/status
46+
{{- end }}
47+
verbs:
48+
{{- if .statusVerbs }}
49+
{{- range .statusVerbs }}
50+
- {{ . }}
51+
{{- end }}
52+
{{- else }}
53+
{{- include "generic-operator.primaryStatusVerbs" $ | nindent 2 }}
54+
{{- end }}
55+
{{- end }}
56+
{{- /* Secondary resources - resources managed by the operator */}}
57+
{{- range .Values.secondaryResources }}
58+
- apiGroups:
59+
- {{ .apiGroup | quote }}
60+
resources:
61+
{{- range .resources }}
62+
- {{ . }}
63+
{{- end }}
64+
verbs:
65+
{{- if .verbs }}
66+
{{- range .verbs }}
67+
- {{ . }}
68+
{{- end }}
69+
{{- else }}
70+
{{- include "generic-operator.secondaryVerbs" $ | nindent 2 }}
71+
{{- end }}
72+
{{- end }}
73+
# Event permissions - for recording events
74+
- apiGroups:
75+
- ""
76+
resources:
77+
- events
78+
verbs:
79+
- create
80+
- patch
81+
{{- /* Leader election - Lease permissions */}}
82+
{{- if .Values.leaderElection.enabled }}
83+
# Lease permissions - for leader election
84+
- apiGroups:
85+
- coordination.k8s.io
86+
resources:
87+
- leases
88+
verbs:
89+
- get
90+
- list
91+
- watch
92+
- create
93+
- update
94+
- patch
95+
- delete
96+
{{- end }}
97+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Copyright Java Operator SDK Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
{{- if .Values.rbac.create }}
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
kind: ClusterRoleBinding
20+
metadata:
21+
name: {{ include "generic-operator.fullname" . }}
22+
labels:
23+
{{- include "generic-operator.labels" . | nindent 4 }}
24+
roleRef:
25+
apiGroup: rbac.authorization.k8s.io
26+
kind: ClusterRole
27+
name: {{ include "generic-operator.fullname" . }}
28+
subjects:
29+
- kind: ServiceAccount
30+
name: {{ include "generic-operator.serviceAccountName" . }}
31+
namespace: {{ .Release.Namespace }}
32+
{{- end }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright Java Operator SDK Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
apiVersion: v1
18+
kind: ConfigMap
19+
metadata:
20+
name: {{ include "generic-operator.fullname" . }}-config
21+
labels:
22+
{{- include "generic-operator.labels" . | nindent 4 }}
23+
data:
24+
config.yaml: |
25+
{{- index .Values.operatorConfig "config" | nindent 4 }}
26+
log4j2.xml: |
27+
{{- .Values.operatorConfig.log4j2 | nindent 4 }}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# Copyright Java Operator SDK Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
apiVersion: apps/v1
18+
kind: Deployment
19+
metadata:
20+
name: {{ include "generic-operator.fullname" . }}
21+
labels:
22+
{{- include "generic-operator.labels" . | nindent 4 }}
23+
spec:
24+
replicas: {{ .Values.replicaCount }}
25+
selector:
26+
matchLabels:
27+
{{- include "generic-operator.selectorLabels" . | nindent 6 }}
28+
template:
29+
metadata:
30+
annotations:
31+
checksum/config: {{ .Values.operatorConfig | toJson | sha256sum }}
32+
{{- with .Values.podAnnotations }}
33+
{{- toYaml . | nindent 8 }}
34+
{{- end }}
35+
labels:
36+
{{- include "generic-operator.selectorLabels" . | nindent 8 }}
37+
spec:
38+
{{- with .Values.podSecurityContext }}
39+
securityContext:
40+
{{- toYaml . | nindent 8 }}
41+
{{- end }}
42+
{{- with .Values.imagePullSecrets }}
43+
imagePullSecrets:
44+
{{- toYaml . | nindent 8 }}
45+
{{- end }}
46+
serviceAccountName: {{ include "generic-operator.serviceAccountName" . }}
47+
{{- with .Values.extraInitContainers }}
48+
initContainers:
49+
{{- toYaml . | nindent 8 }}
50+
{{- end }}
51+
containers:
52+
- name: operator
53+
securityContext:
54+
{{- toYaml .Values.securityContext | nindent 12 }}
55+
image: "{{ required "A valid .Values.image.repository is required" .Values.image.repository }}:{{ include "generic-operator.imageTag" . }}"
56+
imagePullPolicy: {{ .Values.image.pullPolicy }}
57+
env:
58+
- name: OPERATOR_NAMESPACE
59+
valueFrom:
60+
fieldRef:
61+
fieldPath: metadata.namespace
62+
{{- if .Values.operator.watchNamespace }}
63+
- name: WATCH_NAMESPACE
64+
value: {{ .Values.operator.watchNamespace | quote }}
65+
{{- end }}
66+
{{- with .Values.operator.env }}
67+
{{- toYaml . | nindent 8 }}
68+
{{- end }}
69+
resources:
70+
{{- toYaml .Values.resources | nindent 12 }}
71+
volumeMounts:
72+
- name: config
73+
mountPath: /config
74+
readOnly: true
75+
{{- with .Values.extraVolumeMounts }}
76+
{{- toYaml . | nindent 8 }}
77+
{{- end }}
78+
{{- with .Values.extraContainers }}
79+
{{- toYaml . | nindent 6 }}
80+
{{- end }}
81+
volumes:
82+
- name: config
83+
configMap:
84+
name: {{ include "generic-operator.fullname" . }}-config
85+
{{- with .Values.extraVolumes }}
86+
{{- toYaml . | nindent 6 }}
87+
{{- end }}

0 commit comments

Comments
 (0)