Skip to content

Commit

Permalink
feat: Add helm chart (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Anurag Rajawat <[email protected]>
  • Loading branch information
Anurag Rajawat authored Nov 27, 2024
1 parent b27c041 commit e6be548
Show file tree
Hide file tree
Showing 19 changed files with 656 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/release-helm-charts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Authors of SentryFlow

name: Release Helm charts

on:
workflow_dispatch:
inputs:
tag:
description: "Release tag which has to be updated"
type: "string"
required: true

jobs:
release_helm_charts:
if: github.repository == '5GSEC/sentryflow'
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Install Helm
uses: azure/setup-helm@v4

- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.ACTIONS_APP_ID }}
private-key: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }}
repositories: charts

- name: Publish Helm chart
uses: stefanprodan/helm-gh-pages@master
with:
# Access token which can push to a different repo in the same org
token: ${{ steps.generate-token.outputs.token }}
charts_dir: deployments/
# repo where charts would be published
owner: 5GSEC
repository: charts
branch: gh-pages
charts_url: https://5gsec.github.io/charts/
commit_username: "github-actions[bot]"
commit_email: "github-actions[bot]@users.noreply.github.com"
36 changes: 36 additions & 0 deletions .github/workflows/stable-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,39 @@ jobs:
WORKING_DIRECTORY: filter/envoy/envoy-wasm-filters
NAME: sentryflow-httpfilter
secrets: inherit

update-image-tags-in-helm-charts:
if: github.repository == '5GSEC/sentryflow'
needs: [ release-sentryflow-image ]
permissions:
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Get tag
id: tag
run: |
if [ ${{ github.ref }} == "refs/heads/main" ]; then
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
fi
- name: Update images tag
run: |
./hack/update-image-tag.sh ${{ steps.tag.outputs.tag }}
- name: Create PR to update images tag in Helm charts
uses: peter-evans/create-pull-request@v7
with:
branch: update-helm-${{ steps.tag.outputs.tag }}
commit-message: "[skip ci] Update Helm Chart To ${{ steps.tag.outputs.tag }}"
committer: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
title: "[skip ci] Update Helm Chart To ${{ steps.tag.outputs.tag }}"
base: main
signoff: true
delete-branch: true
23 changes: 23 additions & 0 deletions deployments/sentryflow/.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/
24 changes: 24 additions & 0 deletions deployments/sentryflow/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: sentryflow
description: A Helm chart for SentryFlow

# 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: "0.1.0"
39 changes: 39 additions & 0 deletions deployments/sentryflow/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Install SentryFlow

Install SentryFlow using the official 5GSEC Helm charts.

### Add SentryFlow repo

```shell
helm repo add 5gsec https://5gsec.github.io/charts
helm repo update 5gsec
```

### Update `values.yaml` file according to your requirements.

```shell
helm show values 5gsec/sentryflow > values.yaml
```

Configure SentryFlow receiver by following [this](../../docs/receivers.md).

### Deploy SentryFlow

```shell
helm install --values values.yaml sentryflow 5gsec/sentryflow-n sentryflow --create-namespace
```

Install SentryFlow using Helm charts locally (for testing)

```bash
cd deployments/sentryflow/
helm upgrade --install sentryflow . -n sentryflow --create-namespace
```

## Uninstall

To uninstall, just run:

```bash
helm uninstall sentryflow -n sentryflow
```
3 changes: 3 additions & 0 deletions deployments/sentryflow/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Thank you for installing SentryFlow.
Your release is named '{{ include "sentryflow.fullname" . }}' and deployed in '{{ .Release.Namespace }}' namespace.
For more info please visit: https://github.com/5GSEC/SentryFlow
62 changes: 62 additions & 0 deletions deployments/sentryflow/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "sentryflow.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 "sentryflow.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 "sentryflow.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "sentryflow.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "sentryflow.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
39 changes: 39 additions & 0 deletions deployments/sentryflow/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "sentryflow.fullname" . }}
labels:
{{- include "sentryflow.labels" . | nindent 4 }}
{{- with .Values.genericLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
rules:
- apiGroups:
- networking.istio.io
verbs:
- get
- create
- delete
resources:
- envoyfilters
- apiGroups:
- extensions.istio.io
verbs:
- get
- create
- delete
resources:
- wasmplugins

- apiGroups:
- ""
verbs:
- get
resources:
- configmaps
- apiGroups:
- apps
verbs:
- get
resources:
- deployments
17 changes: 17 additions & 0 deletions deployments/sentryflow/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "sentryflow.fullname" . }}
labels:
{{- include "sentryflow.labels" . | nindent 4 }}
{{- with .Values.genericLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "sentryflow.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ include "sentryflow.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
14 changes: 14 additions & 0 deletions deployments/sentryflow/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: sentryflow
labels:
{{- include "sentryflow.labels" . | nindent 4 }}
{{- with .Values.genericLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.config }}
data:
config.yaml: |2-
{{- toYaml . | nindent 4 }}
{{- end }}
56 changes: 56 additions & 0 deletions deployments/sentryflow/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sentryflow.fullname" . }}
labels:
{{- include "sentryflow.labels" . | nindent 4 }}
{{- with .Values.genericLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "sentryflow.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "sentryflow.labels" . | nindent 8 }}
{{- with .Values.genericLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "sentryflow.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.args }}
args:
{{- toYaml . | nindent 12 }}
{{- end}}
ports:
- name: exporter
containerPort: {{ index .Values.service.ports 0 "port" }}
- name: receiver
containerPort: {{ index .Values.service.ports 1 "port" }}
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
Loading

0 comments on commit e6be548

Please sign in to comment.