Skip to content

Commit

Permalink
local k8s helpers for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
udnay committed Feb 5, 2025
1 parent 28ba983 commit 7de191e
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PROTO_FILES := $(shell find internal/pb/ -type f -name '*.proto')
MIGRATE_DIR := ./migrations
SERVICE := $(PROJECT).server
BENCH_PROFILE ?= ""
KUBE_CONTEXT ?= orbstack

.PHONY: migrate migrate-create clean build lint release
.PHONY: test test-one test-fuzz test-js lint-js install-js build-js
Expand All @@ -33,7 +34,7 @@ BENCH_PROFILE ?= ""
.PHONY: cachedclient-probe cachedclient-populate cachedclient-stats
.PHONY: health upload-container-image upload-prerelease-container-image run-container gen-docs
.PHONY: load-test-new load-test-update load-test-update-large load-test-get load-test-get-compress

.PHONY: k8s k8s/start k8s/stop k8s/delete k8s/reset k8s/deploy
migrate:
migrate -database $(DB_URI)?sslmode=disable -path $(MIGRATE_DIR) up

Expand Down Expand Up @@ -283,3 +284,26 @@ lint-js: js/node_modules js/src/pb
install-js: js/node_modules

build-js: js/dist

k8s:
which orb >/dev/null 2>&1; if [ $$? -ne 0 ]; then echo "orb not found"; exit 1; fi
k8s/start: k8s
orb start k8s

k8s/stop: k8s
orb stop k8s

k8s/delete: k8s
orb delete k8s

k8s/reset: k8s/stop k8s/delete k8s/start

k8s/deploy: k8s k8s/start
kubectl --context=$(KUBE_CONTEXT) create namespace dateilager-local || true
kubectl --context=$(KUBE_CONTEXT) apply -f test/k8s-local/cached-csi.yaml -n dateilager-local
kubectl --context=$(KUBE_CONTEXT) apply -f test/k8s-local/cached-daemon.yaml -n dateilager-local

k8s/reset_namespace: k8s k8s/start
kubectl --context=$(KUBE_CONTEXT) delete ds dateilager-csi-cached -n dateilager-local --force --grace-period=0 || true
kubectl --context=$(KUBE_CONTEXT) delete pod busybox-csi -n dateilager-local --force --grace-period=0 || true
kubectl --context=$(KUBE_CONTEXT) delete namespace dateilager-local || true
24 changes: 24 additions & 0 deletions test/k8s-local/busy-box-debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox-csi
spec:
containers:
- name: busybox
image: busybox
command:
- "/bin/sh"
- "-c"
- "sleep infinity"
volumeMounts:
- name: gadget
mountPath: /gadget
subPath: gadget
volumes:
- name: gadget
csi:
driver: com.gadget.dateilager.cached
volumeAttributes:
placeCacheAtPath: "dl_cache"
mountCache: "true"
readOnly: false
11 changes: 11 additions & 0 deletions test/k8s-local/cached-csi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: storage.k8s.io/v1
kind: CSIDriver
metadata:
name: com.gadget.dateilager.cached
labels:
origin: krane
spec:
attachRequired: false
volumeLifecycleModes:
- Ephemeral
95 changes: 95 additions & 0 deletions test/k8s-local/cached-daemon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: dateilager-csi-cached
labels:
app: dateilager-csi-cached
spec:
selector:
matchLabels:
app: dateilager-csi-cached
template:
metadata:
name: datailager-csi-cached
labels:
app: dateilager-csi-cached
spec:
terminationGracePeriodSeconds: 60
containers:
- name: csi-cached
image: dl-local:dev
imagePullPolicy: IfNotPresent
securityContext:
privileged: true
runAsUser: 0
command:
[
"./cached",
"--log-level=info",
"--log-encoding=json",
"--csi-socket=unix:///csi/csi.sock",
"--upstream-host=host.internal",
"--upstream-port=5051",
"--tracing",
"--staging-path=/var/lib/kubelet/dateilager_cache",
]
env:
- name: DL_ENV
value: "dev"
- name: "LOG_LEVEL"
value: "debug"
- name: DL_PGX_TRACING
value: "1"
- name: DL_TOKEN
value: "v2.public.eyJzdWIiOiJzaGFyZWQtcmVhZGVyIn1CxWdB02s9el0Wt7qReARZ-7JtIb4Zj3D4Oiji1yXHqj0orkpbcVlswVUiekECJC16d1NrHwD2FWSwRORZn8gK"
- name: DL_SKIP_SSL_VERIFICATION
value: "1"
- name: BUMP_TO_ROLL
value: "2"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: plugin-dir
mountPath: /csi/
- mountPath: "/var/lib/kubelet"
name: host-kubelet-dir
mountPropagation: "Bidirectional"
- name: csi-driver-registrar
image: registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.10.1
args:
- "--csi-address=/csi/csi.sock"
- "--kubelet-registration-path=/var/lib/kubelet/plugins/com.gadget.dateilager.cached/csi.sock"
- "--health-port=9809"
volumeMounts:
- name: plugin-dir
mountPath: /csi
- name: registration-dir
mountPath: /registration
ports:
- containerPort: 9809
name: healthz
livenessProbe:
httpGet:
path: /healthz
port: healthz
initialDelaySeconds: 5
timeoutSeconds: 5
volumes:
# a working directory for the two containers to share when registering the CSI
- name: plugin-dir
hostPath:
path: /var/lib/kubelet/plugins/com.gadget.dateilager.cached
type: DirectoryOrCreate
# the directory for the driver-registrar sidecar container to register our driver with the kubelet
#
- name: registration-dir
hostPath:
path: /var/lib/kubelet/plugins_registry/
type: DirectoryOrCreate
# the host kubelet directory for the CSI driver to mount volumes in
- name: host-kubelet-dir
hostPath:
path: /var/lib/kubelet

0 comments on commit 7de191e

Please sign in to comment.