Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ jobs:

build:
uses: ./.github/workflows/build.yml

helm_unit_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Run Helm unit tests
run: ./helm/run-tests.sh
22 changes: 22 additions & 0 deletions helm/generic-helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright Java Operator SDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

apiVersion: v2
name: generic-operator-chart
description: A generic reusable Helm chart for Java operators built with Java Operator SDK (JOSDK)
type: application
version: 0.1.0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be same as JOSDK version?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good question, so I don't really want to advertise this helm chart, as something that follows josdk semver versioning. Rather it mean to be a starting point for users to basically copy paste and extend. But this is up to the debate. For now I would stick with this basic / simple approach and we can discuss on next community meeting if we should improve on that in a next iteration, and follow semver + add helm repository support from the webpage.

appVersion: "0.1.0"
100 changes: 100 additions & 0 deletions helm/generic-helm-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "generic-operator.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
*/}}
{{- define "generic-operator.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "generic-operator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "generic-operator.labels" -}}
helm.sh/chart: {{ include "generic-operator.chart" . }}
{{ include "generic-operator.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "generic-operator.selectorLabels" -}}
app.kubernetes.io/name: {{ include "generic-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "generic-operator.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "generic-operator.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Image tag - defaults to chart appVersion
*/}}
{{- define "generic-operator.imageTag" -}}
{{- .Values.image.tag | default .Chart.AppVersion }}
{{- end }}

{{/*
Default verbs for primary resources
*/}}
{{- define "generic-operator.primaryVerbs" -}}
- get
- list
- watch
- patch
- update
{{- end }}

{{/*
Default verbs for primary resource status
*/}}
{{- define "generic-operator.primaryStatusVerbs" -}}
- get
- patch
- update
{{- end }}

{{/*
Default verbs for secondary resources
*/}}
{{- define "generic-operator.secondaryVerbs" -}}
- get
- list
- watch
- create
- update
- patch
- delete
{{- end }}
97 changes: 97 additions & 0 deletions helm/generic-helm-chart/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#
# Copyright Java Operator SDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "generic-operator.fullname" . }}
labels:
{{- include "generic-operator.labels" . | nindent 4 }}
rules:
{{- /* Primary resources - the custom resources the operator reconciles */}}
{{- range .Values.primaryResources }}
- apiGroups:
- {{ .apiGroup | quote }}
resources:
{{- range .resources }}
- {{ . }}
{{- end }}
verbs:
{{- if .verbs }}
{{- range .verbs }}
- {{ . }}
{{- end }}
{{- else }}
{{- include "generic-operator.primaryVerbs" $ | nindent 2 }}
{{- end }}
- apiGroups:
- {{ .apiGroup | quote }}
resources:
{{- range .resources }}
- {{ . }}/status
{{- end }}
verbs:
{{- if .statusVerbs }}
{{- range .statusVerbs }}
- {{ . }}
{{- end }}
{{- else }}
{{- include "generic-operator.primaryStatusVerbs" $ | nindent 2 }}
{{- end }}
{{- end }}
{{- /* Secondary resources - resources managed by the operator */}}
{{- range .Values.secondaryResources }}
- apiGroups:
- {{ .apiGroup | quote }}
resources:
{{- range .resources }}
- {{ . }}
{{- end }}
verbs:
{{- if .verbs }}
{{- range .verbs }}
- {{ . }}
{{- end }}
{{- else }}
{{- include "generic-operator.secondaryVerbs" $ | nindent 2 }}
{{- end }}
{{- end }}
# Event permissions - for recording events
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
{{- /* Leader election - Lease permissions */}}
{{- if .Values.leaderElection.enabled }}
# Lease permissions - for leader election
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
{{- end }}
{{- end }}
32 changes: 32 additions & 0 deletions helm/generic-helm-chart/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright Java Operator SDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "generic-operator.fullname" . }}
labels:
{{- include "generic-operator.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "generic-operator.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ include "generic-operator.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end }}
27 changes: 27 additions & 0 deletions helm/generic-helm-chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright Java Operator SDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "generic-operator.fullname" . }}-config
labels:
{{- include "generic-operator.labels" . | nindent 4 }}
data:
config.yaml: |
{{- index .Values.operatorConfig "config" | nindent 4 }}
log4j2.xml: |
{{- .Values.operatorConfig.log4j2 | nindent 4 }}
87 changes: 87 additions & 0 deletions helm/generic-helm-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#
# Copyright Java Operator SDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "generic-operator.fullname" . }}
labels:
{{- include "generic-operator.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "generic-operator.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ .Values.operatorConfig | toJson | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "generic-operator.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "generic-operator.serviceAccountName" . }}
{{- with .Values.extraInitContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: operator
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ required "A valid .Values.image.repository is required" .Values.image.repository }}:{{ include "generic-operator.imageTag" . }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- if .Values.operator.watchNamespace }}
- name: WATCH_NAMESPACE
value: {{ .Values.operator.watchNamespace | quote }}
{{- end }}
{{- with .Values.operator.env }}
{{- toYaml . | nindent 8 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: config
mountPath: /config
readOnly: true
{{- with .Values.extraVolumeMounts }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.extraContainers }}
{{- toYaml . | nindent 6 }}
{{- end }}
volumes:
- name: config
configMap:
name: {{ include "generic-operator.fullname" . }}-config
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 6 }}
{{- end }}
Loading
Loading