Skip to content

Commit

Permalink
Added Sentry webhook (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushall authored Dec 9, 2024
1 parent 3210ecb commit 5a8ac11
Show file tree
Hide file tree
Showing 17 changed files with 649 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/webhook-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Nopo11y Operator Build

on:
push:
branches:
- main
paths:
- 'tools/sentry-webhook/**'
- '!tools/sentry-webhook/*.md'

env:
IMAGE_REPO: ghcr.io/znsio/nopo11y/sentry-webhook

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker Image
run: |
cd ./tools/sentry-webhook/
docker build . -t $IMAGE_REPO:${{ github.sha }} -t $IMAGE_REPO:latest
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: '${{ env.IMAGE_REPO }}:${{ github.sha }}'
format: 'table'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Docker Image
run: |
docker push $IMAGE_REPO:${{ github.sha }}
docker push $IMAGE_REPO:latest
23 changes: 23 additions & 0 deletions charts/sentry-webhook/.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 charts/sentry-webhook/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: sentry
description: A Helm chart for deploying sentry-webhook

# 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: 1.0.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.0.0"
62 changes: 62 additions & 0 deletions charts/sentry-webhook/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "sentry-webhook.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 "sentry-webhook.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 "sentry-webhook.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "sentry-webhook.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "sentry-webhook.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
25 changes: 25 additions & 0 deletions charts/sentry-webhook/templates/mutatingWebhookConfiguration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook
webhooks:
- name: sentry-webhook.znsio.nopo11y.com
failurePolicy: Ignore
rules:
- apiGroups:
- apps
apiVersions:
- "v1"
resources:
- deployments
operations:
- CREATE
- UPDATE
clientConfig:
service:
namespace: {{ .Release.Namespace }}
name: {{ include "sentry-webhook.fullname" . }}-webhook
path: /mutate
timeoutSeconds: {{ .Values.timeoutSeconds }}
admissionReviewVersions: ["v1"]
sideEffects: None
24 changes: 24 additions & 0 deletions charts/sentry-webhook/templates/webhook_cluster_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- create
- apiGroups:
- admissionregistration.k8s.io
resources:
- validatingwebhookconfigurations
- mutatingwebhookconfigurations
verbs:
- get
- update
15 changes: 15 additions & 0 deletions charts/sentry-webhook/templates/webhook_cluster_role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "sentry-webhook.fullname" . }}-webhook
subjects:
- kind: ServiceAccount
name: {{ include "sentry-webhook.fullname" . }}-webhook
namespace: {{ .Release.Namespace }}
41 changes: 41 additions & 0 deletions charts/sentry-webhook/templates/webhook_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook
namespace: {{ .Release.Namespace }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ include "sentry-webhook.fullname" . }}-webhook
template:
metadata:
labels:
app: {{ include "sentry-webhook.fullname" . }}-webhook
spec:
{{- with .Values.global.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: sentry-webhook
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
{{- with .Values.env }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- containerPort: 9443
name: https
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: tls-secret
mountPath: /certs
readOnly: true
volumes:
- name: tls-secret
secret:
defaultMode: 420
secretName: {{ include "sentry-webhook.fullname" . }}-webhook-certs
33 changes: 33 additions & 0 deletions charts/sentry-webhook/templates/webhook_patch_job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook-patch
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook-patch
spec:
{{- with .Values.global.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: patch
image: "{{ .Values.certgen.image.repository }}:{{ .Values.certgen.image.tag }}"
imagePullPolicy: "{{ .Values.certgen.image.pullPolicy }}"
args:
- patch
- --webhook-name={{ include "sentry-webhook.fullname" . }}-webhook
- --namespace={{ .Release.Namespace }}
- --secret-name={{ include "sentry-webhook.fullname" . }}-webhook-certs
- --patch-validating=false
{{- if .Values.certgen.resources }}
resources:
{{- toYaml .Values.certgen.resources | nindent 12 }}
{{- end }}
restartPolicy: OnFailure
serviceAccountName: {{ include "sentry-webhook.fullname" . }}-webhook
32 changes: 32 additions & 0 deletions charts/sentry-webhook/templates/webhook_secret_create_job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook-create
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook-create
spec:
{{- with .Values.global.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: webhook-create
image: "{{ .Values.certgen.image.repository }}:{{ .Values.certgen.image.tag }}"
imagePullPolicy: "{{ .Values.certgen.image.pullPolicy }}"
args:
- create
- --host="{{ include "sentry-webhook.fullname" . }}-webhook,{{ include "sentry-webhook.fullname" . }}-webhook.{{ .Release.Namespace }}.svc,{{ include "sentry-webhook.fullname" . }}-webhook.{{ .Release.Namespace }}.svc.cluster.local"
- --namespace={{ .Release.Namespace }}
- --secret-name={{ include "sentry-webhook.fullname" . }}-webhook-certs
{{- if .Values.certgen.resources }}
resources:
{{- toYaml .Values.certgen.resources | nindent 12 }}
{{- end }}
restartPolicy: OnFailure
serviceAccountName: {{ include "sentry-webhook.fullname" . }}-webhook
13 changes: 13 additions & 0 deletions charts/sentry-webhook/templates/webhook_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook
namespace: {{ .Release.Namespace }}
spec:
selector:
app: {{ include "sentry-webhook.fullname" . }}-webhook
ports:
- name: https
port: 443
protocol: TCP
targetPort: 9443
8 changes: 8 additions & 0 deletions charts/sentry-webhook/templates/webhook_service_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "sentry-webhook.fullname" . }}-webhook
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
Loading

0 comments on commit 5a8ac11

Please sign in to comment.