Skip to content

Commit

Permalink
Merge pull request #1 from osodevops/kafka-connect
Browse files Browse the repository at this point in the history
feat: Added kafka-connect helm chart to helm repository
  • Loading branch information
robcoward authored Nov 25, 2024
2 parents 53fd29f + 211fb43 commit 69c45e1
Show file tree
Hide file tree
Showing 12 changed files with 1,099 additions and 203 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Lint and Test Charts

on: pull_request

jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.14.4

- uses: actions/setup-python@v5
with:
python-version: "3.x"
check-latest: true

- name: Set up chart-testing
uses: helm/[email protected]

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }}

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/[email protected]

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }}
27 changes: 27 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release Charts

on:
push:
branches:
- main

jobs:
release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
875 changes: 674 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# helm-charts
Public Helm Charts from OSO DevOps
## Usage

[Helm](https://helm.sh) must be installed to use the charts. Please refer to
Helm's [documentation](https://helm.sh/docs) to get started.

Once Helm has been set up correctly, add the repo as follows:

helm repo add oso-devops https://osodevops.github.io/helm-charts

If you had already added this repo earlier, run `helm repo update` to retrieve
the latest versions of the packages. You can then run `helm search repo
oso-devops` to see the charts.

To install the <chart-name> chart:

helm install my-<chart-name> oso-devops/<chart-name>

To uninstall the chart:

helm delete my-<chart-name>
23 changes: 23 additions & 0 deletions charts/kafka-connect/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
27 changes: 27 additions & 0 deletions charts/kafka-connect/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v2
name: kafka-connect
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

maintainers:
- name: devops-consultants
77 changes: 77 additions & 0 deletions charts/kafka-connect/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "kafka-connect.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "kafka-connect.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 "kafka-connect.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

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

{{/*
Create the name of the config topic to use
*/}}
{{- define "kafka-connect.storageConfig" -}}
{{- $global := .global -}}
{{- $config := .config -}}
{{- $clustername := .clustername -}}
{{- $topic_prefix := (printf "%s-%s" $global.configTopicPrefix $clustername) -}}
{{- range $topic, $topic_config := $config.topics }}
{{ $topic }}.storage.replication.factor: {{ $topic_config.replicationFactor | default $global.replicationFactor }}
{{ $topic }}.storage.topic: {{ $topic_config.topic | default (printf "%s-%s" $topic_prefix $topic) }}
{{- end }}
{{- end }}

32 changes: 32 additions & 0 deletions charts/kafka-connect/templates/connect-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- $global := .Values.global }}
{{- range $cluster, $config := .Values.clusters }}
{{- $connect_name := (printf "%s-%s" (include "kafka-connect.name" $) $cluster) }}
{{- $jvmOptions := $config.jvmOptions | default $global.jvmOptions -}}
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnect
metadata:
name: {{ $connect_name }}
annotations:
strimzi.io/use-connector-resources: "true"
spec:
image: {{ $.Values.image }}
jvmOptions:
{{- range $opt, $value := $jvmOptions }}
{{ $opt | quote }}: {{ $value | quote }}
{{- end }}
version: {{ $config.version | default $global.version }}
replicas: {{ $config.replicas | default $global.replicas }}
bootstrapServers: {{ $.Values.kafka.bootstrapServers }}
template:
serviceAccount:
metadata:
name: {{ include "kafka-connect.serviceAccountName" $ }}
config:
group.id: {{ $config.groupId | default $connect_name }}
config.providers: {{ $config.providersClass | keys | join ", " }}
{{- range $provider, $class := $config.providersClass }}
config.providers.{{ $provider }}.class: {{ $class }}
{{- end }}
{{- include "kafka-connect.storageConfig" (dict "global" $global "config" $config "clustername" $connect_name) | indent 4}}
---
{{- end }}
28 changes: 28 additions & 0 deletions charts/kafka-connect/templates/connector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- $global := .Values.global }}
{{- range $cluster, $config := .Values.clusters }}
{{- $connect_name := (printf "%s-%s" (include "kafka-connect.name" $) $cluster) }}
{{- range $connector, $connector_config := $config.connectors -}}
{{- $topic := $connector_config.topic | default (printf "%s-%s" $connect_name $connector) -}}
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaConnector
metadata:
name: {{ $connect_name }}-{{ $connector }}
labels:
strimzi.io/cluster: {{ $connect_name }}
spec:
class: {{ $connector_config.class }}
config:
kafka.topic: {{ $topic }}
confluent.topic.sasl.mechanism: {{ $.Values.kafka.saslMechanism }}
confluent.topic.sasl.jaas.config: {{ $.Values.kafka.saslJaasConfig }}
confluent.topic.sasl.client.callback.handler.class: {{ $.Values.kafka.saslClientCallbackHandler }}
confluent.topic.security.protocol: {{ $.Values.kafka.securityProtocol }}
confluent.topic.bootstrap.servers: {{ $.Values.kafka.bootstrapServers }}
confluent.topic.replication.factor: 3
confluent.license: {{ $global.confluentLicense | quote }}
{{- range $key, $value := $connector_config.config }}
{{ $key }}: {{ $value }}
{{- end }}
---
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/kafka-connect/templates/external-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- range $secret, $secret_config := .Values.secrets }}
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: {{ $secret }}
spec:
refreshInterval: {{ $.Values.global.refreshInterval}}
secretStoreRef:
name: {{ $.Values.global.secretStore }}
kind: {{ $.Values.global.secretStoreKind }}
data:
{{- range $k8sKey, $awsKey := $secret_config.keys }}
- secretKey: {{ $k8sKey }}
remoteRef:
key: {{ $secret_config.awsSecret}}
property: {{ $awsKey }}
{{- end }}
---
{{- end }}
42 changes: 42 additions & 0 deletions charts/kafka-connect/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{- $global := .Values.global }}
{{- range $cluster, $config := .Values.clusters }}
{{- $sa_name := (printf "%s-%s-connect" (include "kafka-connect.name" $) $cluster) }}

{{- if $.Values.serviceAccount.create -}}
---
apiVersion: v1
kind: ServiceAccount
metadata:
{{- with $.Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "kafka-connect.labels" $ | nindent 4 }}
name: {{ $sa_name }}
automountServiceAccountToken: {{ $.Values.serviceAccount.automount }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: "{{ $sa_name }}-configuration-role"
rules:
- apiGroups: [""]
resources: ["secrets"]
resourceNames: [{{- range $secret, $secret_config := $.Values.secrets -}}"{{ $secret }}",{{- end -}}]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: "{{ $sa_name }}-configuration-role-binding"
subjects:
- kind: ServiceAccount
name: "{{ $sa_name }}"
namespace: {{ $.Release.Namespace }}
roleRef:
kind: Role
name: "{{ $sa_name }}-configuration-role"
apiGroup: rbac.authorization.k8s.io
{{- end }}
Loading

0 comments on commit 69c45e1

Please sign in to comment.