Skip to content

Instantly share code, notes, and snippets.

View mohllal's full-sized avatar
🎯
Focusing

Kareem Khaled mohllal

🎯
Focusing
View GitHub Profile
@mohllal
mohllal / MarroMailerSMTPTransport.py
Created May 16, 2024 17:16
A custom SMTP transport for the marrow/mailer python package
import sys
# Fix to marrow/mailer issue: https://github.com/marrow/mailer/issues/87#issuecomment-689586587
sys.modules["cgi.parse_qsl"] = None
from smtplib import SMTP, SMTP_SSL
from marrow.mailer import Mailer
from marrow.mailer.exc import TransportException
from marrow.mailer.transport.smtp import SMTPTransport
@mohllal
mohllal / AdmissionSecret.yaml
Created November 29, 2022 10:18
An example of Kubernetes Secret for the TLS certificate of the admission server
apiVersion: v1
kind: Secret
metadata:
name: kubernetes-sidecar-injector
type: Opaque
data:
tls-cert-file: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JS...
tls-private-key-file: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0t...
@mohllal
mohllal / AdmissionMutatingWebhookConfiguration.yaml
Last active November 29, 2022 10:13
An example of Kubernetes MutatingWebhookConfiguration for the admission controller webhook server
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: kubernetes-sidecar-injector
webhooks:
- name: kubernetes-sidecar-injector.default.svc
admissionReviewVersions:
- v1
sideEffects: "NoneOnDryRun"
reinvocationPolicy: "Never"
@mohllal
mohllal / AdmissionService.yaml
Last active November 29, 2022 09:59
An example of Kubernetes Service for the admission webhook server
apiVersion: v1
kind: Service
metadata:
name: kubernetes-sidecar-injector
labels:
app.kubernetes.io/instance: kubernetes-sidecar-injector
spec:
type: ClusterIP
ports:
- port: 443
@mohllal
mohllal / AdmissionDeployment.yaml
Last active November 29, 2022 10:02
An example of Kubernetes Deployment that runs the admission webhook server
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubernetes-sidecar-injector
labels:
app.kubernetes.io/instance: kubernetes-sidecar-injector
spec:
selector:
matchLabels:
app.kubernetes.io/instance: kubernetes-sidecar-injector
@mohllal
mohllal / _helpers.tpl
Last active November 29, 2022 09:18
An example of Helm helper file for generating an x509 certificate
{{- define "kubernetes-sidecar-injector.service.fullname" -}}
{{- default ( printf "%s.%s.svc" (include "kubernetes-sidecar-injector.serviceName" .) .Release.Namespace ) }}
{{- end }}
{{- define "kubernetes-sidecar-injector.gen-certs" -}}
{{- $expiration := (.Values.admission.ca.expiration | int) -}}
{{- if (or (empty .Values.admission.ca.cert) (empty .Values.admission.ca.key)) -}}
{{- $ca := genCA "kubernetes-sidecar-injector-ca" $expiration -}}
{{- template "kubernetes-sidecar-injector.gen-client-tls" (dict "RootScope" . "CA" $ca) -}}
{{- end -}}
@mohllal
mohllal / Mutate.ts
Last active November 28, 2022 23:56
An example of the injection mutation function
import * as jsonpatch from 'fast-json-patch';
const mutate = (admissionReviewRequest: V1AdmissionRequest<V1Pod>): V1AdmissionResponse => {
const admissionReviewResponse: V1AdmissionResponse = {
allowed: true,
uid: admissionReviewRequest.uid,
};
// get the pod object and clone it
const originalPod = admissionReviewRequest.object as V1Pod;
@mohllal
mohllal / AdmissionResponse.json
Created November 28, 2022 23:04
An example of an AdmissionReview response body containing the AdmissionResponse object
{
"apiVersion": "admission.k8s.io/v1",
"kind": "AdmissionReview",
"response": {
"uid": "075a1336-0165-41e0-b0ac-8705883f1c41",
"allowed": true,
"patch": "W3sib3AiOiJhZGQiLCJwYXRoIjoiL3NwZWMvY29udG...",
"patchType": "JSONPatch"
}
}
@mohllal
mohllal / AdmissionRequest.json
Last active November 28, 2022 23:07
An example of an AdmissionReview request body containing the AdmissionRequest object
{
"apiVersion": "admission.k8s.io/v1",
"kind": "AdmissionReview",
"request": {
"uid": "075a1336-0165-41e0-b0ac-8705883f1c41",
"dryRun": false,
"namespace": "default",
"...": "..."
"object": {
"apiVersion": "v1",