Skip to content

Commit

Permalink
Add integration testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Mar 6, 2024
1 parent 84a32de commit 674f6ad
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Expected to be run from the context of the K8sDeputy package root:
# ```
# docker build -f test/integration/Dockerfile .
# ```

ARG JULIA_VERSION=1.9.4
FROM julia:${JULIA_VERSION}-bookworm

# Install Julia package registries
RUN julia -e 'using Pkg; Pkg.Registry.add("General")'

ENV JULIA_PROJECT=/root/K8sDeputy
COPY Project.toml Manifest.toml ${JULIA_PROJECT}/
RUN julia -e 'using Pkg; Pkg.Registry.update(); Pkg.instantiate(); Pkg.build(); Pkg.precompile(strict=true, timing=true)'

COPY . ${JULIA_PROJECT}
RUN mv ${JULIA_PROJECT}/test/integration/entrypoint.jl ${JULIA_PROJECT} && \
rmdir ${JULIA_PROJECT}/test/integration
RUN julia -e 'using Pkg; Pkg.precompile(strict=true, timing=true)'

WORKDIR ${JULIA_PROJECT}
ENTRYPOINT ["julia", "entrypoint.jl"]
10 changes: 10 additions & 0 deletions test/integration/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Using a .dockerignore file relative to the Dockerfile and not the build context:
# https://docs.docker.com/build/building/context/#filename-and-location

**/*.md
.git
.github
.gitignore
docs
test/integration
!test/integration/entrypoint.jl
25 changes: 25 additions & 0 deletions test/integration/chart/k8s-deputy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
apiVersion: v2
name: k8s-deputy
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: "0.0.0"
51 changes: 51 additions & 0 deletions test/integration/chart/k8s-deputy/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "k8s-deputy.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 "k8s-deputy.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 "k8s-deputy.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "k8s-deputy.selectorLabels" -}}
app.kubernetes.io/name: {{ include "k8s-deputy.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
77 changes: 77 additions & 0 deletions test/integration/chart/k8s-deputy/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "k8s-deputy.fullname" . }}
labels:
{{- include "k8s-deputy.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "k8s-deputy.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "k8s-deputy.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
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 }}
# Wait after Julia process exits to allow `preStop` to complete
command: ["/bin/sh", "-c", "julia entrypoint.jl; sleep 1"]
env:
- name: JULIA_NUM_THREADS
value: "{ .Values.threads }}"
- name: DEPUTY_HEALTH_CHECK_PORT
value: {{ .Values.probe.port | quote }}
- name: DEPUTY_IPC_DIR
value: /mnt/deputy-ipc
ports:
- name: probe
containerPort: {{ .Values.probe.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /health/live
port: probe
timeoutSeconds: 5
lifecycle:
preStop:
exec:
command: ["julia", "-e", "using K8sDeputy; graceful_terminate()"]
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
terminationGracePeriodSeconds: 30
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
79 changes: 79 additions & 0 deletions test/integration/chart/k8s-deputy/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Default values for k8s-deputyprov.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
---
replicaCount: 1

image:
repository: k8s-deputy
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""

threads: "1,1"

nameOverride: ""
fullnameOverride: ""

podAnnotations: {}
podLabels: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- all
readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

probe:
port: 8081

livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http

# Additional volumes on the output Deployment definition.
volumes:
- name: deputy-ipc
emptyDir:
medium: Memory
# - name: foo
# secret:
# secretName: mysecret
# optional: false

# Additional volumeMounts on the output Deployment definition.
volumeMounts:
- name: deputy-ipc
mountPath: /mnt/deputy-ipc
# - name: foo
# mountPath: "/etc/foo"
# readOnly: true

nodeSelector: {}

tolerations: []

affinity: {}
9 changes: 9 additions & 0 deletions test/integration/entrypoint.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env -S julia --color=no --startup-file=no

using K8sDeputy

deputy = Deputy()
server = K8sDeputy.serve!(deputy, "0.0.0.0")
graceful_terminator(() -> shutdown(deputy))
readied(deputy)
wait(server)
20 changes: 20 additions & 0 deletions test/integration/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
apiVersion: skaffold/v4beta2
kind: Config

build:
artifacts:
- image: k8s-deputy
context: ../..
local:
useBuildkit: true
push: false

deploy:
helm:
releases:
- name: k8s-deputy
chartPath: chart/k8s-deputy
setValueTemplates:
image.repository: "{{.IMAGE_REPO_k8s_deputy}}"
image.tag: "{{.IMAGE_TAG_k8s_deputy}}@{{.IMAGE_DIGEST_k8s_deputy}}"

0 comments on commit 674f6ad

Please sign in to comment.