mirror of
https://github.com/owncloud/ocis
synced 2026-04-25 17:25:21 +02:00
test: add setup and docs for running API tests in K8s (#12107)
* test: add locak k8s setup Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * chore: move k8s config files Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * fix: add host alias Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * fix: remove unsed dir Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * ci: use script to expose external servers to the cluster Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * ci: expose using existing script Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * docs: add docs Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * docs: refer k8s setup docs Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * ci: specify namespace Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * ci: create namespace Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * docs: fix docs errors Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * test: patch chart template only once Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * docs: add toc and setup cleanup Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * chore: remove deprecated --atomic helm option Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * test: add k8s namespace wrapper option Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * test: fix logs dir permissions Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * docs: update docs Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * test: fix host ip detection Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> * docs: add show-logs command and warning for external services Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com> --------- Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>
This commit is contained in:
36
.drone.star
36
.drone.star
@@ -3975,18 +3975,10 @@ def k3sCluster(name = OCIS_SERVER_NAME, ocm = False):
|
||||
if ocm:
|
||||
commands.extend([
|
||||
# wait for peer
|
||||
"echo 'Waiting for %s to be available...'" % peer_name,
|
||||
"for i in {1..60}; do if getent hosts %s > /dev/null 2>&1; then break; fi; echo 'Waiting for %s... attempt '$i; sleep 2; done" % (peer_name, peer_name),
|
||||
# get the IP of peer
|
||||
"PEER_IP=$(getent hosts %s | awk '{ print $1 }')" % peer_name,
|
||||
"echo \"%s IP: $PEER_IP\"" % peer_name,
|
||||
# create namespace for ocis
|
||||
"kubectl create namespace ocis --dry-run=client -o yaml | kubectl apply -f -",
|
||||
# create service in the 'ocis' namespace
|
||||
"cat <<EOF | kubectl apply -f -\napiVersion: v1\nkind: Service\nmetadata:\n name: %s\n namespace: ocis\nspec:\n type: ClusterIP\n clusterIP: None\n ports:\n - port: 443\n protocol: TCP\n---\napiVersion: v1\nkind: Endpoints\nmetadata:\n name: %s\n namespace: ocis\nsubsets:\n- addresses:\n - ip: $PEER_IP\n ports:\n - port: 443\n protocol: TCP\nEOF" % (peer_name, peer_name),
|
||||
# verify
|
||||
"kubectl get svc %s -n ocis" % peer_name,
|
||||
"kubectl get endpoints %s -n ocis" % peer_name,
|
||||
"until getent hosts %s >/dev/null 2>&1; do echo 'Waiting for %s...'; sleep 2; done" % (peer_name, peer_name),
|
||||
# create namespace
|
||||
"kubectl create namespace ocis || true",
|
||||
"bash %s/tests/config/k8s/expose-external-svc.sh -n ocis %s:443" % (dirs["base"], peer_name),
|
||||
])
|
||||
|
||||
commands.extend([
|
||||
@@ -4025,7 +4017,7 @@ def prepareChartsK8s(environment = []):
|
||||
"[ ! -d %s/ocis-charts ] && " % dirs["base"] +
|
||||
"git clone --single-branch -b main --depth 1 https://github.com/owncloud/ocis-charts.git",
|
||||
# prepare charts for the tests
|
||||
"bash %s/tests/config/drone/k8s/setup.sh %s/ocis-charts" % (dirs["base"], dirs["base"]),
|
||||
"bash %s/tests/config/k8s/setup.sh %s/ocis-charts" % (dirs["base"], dirs["base"]),
|
||||
]
|
||||
|
||||
return [{
|
||||
@@ -4070,10 +4062,6 @@ def deployOcisK8s(name = OCIS_SERVER_NAME):
|
||||
"cd %s/ocis-charts" % dirs["base"],
|
||||
# update external domain
|
||||
"sed -i 's|externalDomain:.*|externalDomain: %s|' ./charts/ocis/ci/deployment-values.yaml" % name,
|
||||
# [NOTE]
|
||||
# Remove schema validation to add extra configs in values.yaml.
|
||||
# Also this allows us to use fakeoffice as web-office server
|
||||
"rm ./charts/ocis/values.schema.json || true",
|
||||
# deploy ocis
|
||||
"make helm-install-atomic",
|
||||
],
|
||||
@@ -4134,15 +4122,10 @@ def exposeNodePortsK8s(services = [], name = OCIS_SERVER_NAME):
|
||||
}]
|
||||
|
||||
def exposeExternalServersK8s(servers = [], name = OCIS_SERVER_NAME):
|
||||
commands = []
|
||||
servers_arg = []
|
||||
for server in servers:
|
||||
server_name = server[0]
|
||||
server_port = str(server[1])
|
||||
commands.append("SERVER_IP=$(getent hosts %s | awk '{print $1}')" % server_name)
|
||||
commands.append('echo -e "apiVersion: v1\nkind: Endpoints\nmetadata:\n name: %s\n namespace: ocis\n' % server_name +
|
||||
'subsets:\n- addresses:\n - ip: $SERVER_IP\n ports:\n - port: %s" | kubectl apply -f -' % server_port)
|
||||
commands.append('echo -e "apiVersion: v1\nkind: Service\nmetadata:\n name: %s\n namespace: ocis\n' % server_name +
|
||||
'spec:\n ports:\n - port: %s\n targetPort: %s" | kubectl apply -f -' % (server_port, server_port))
|
||||
servers_arg.append("%s:%s" % (server[0], str(server[1])))
|
||||
servers_arg = ",".join(servers_arg)
|
||||
|
||||
return [{
|
||||
"name": "expose-external-servers",
|
||||
@@ -4150,5 +4133,6 @@ def exposeExternalServersK8s(servers = [], name = OCIS_SERVER_NAME):
|
||||
"commands": [
|
||||
"export KUBECONFIG=kubeconfig-$${DRONE_BUILD_NUMBER}-%s.yaml" % name,
|
||||
"until test -f $${KUBECONFIG}; do sleep 1s; done",
|
||||
] + commands,
|
||||
"bash %s/tests/config/k8s/expose-external-svc.sh -n ocis %s" % (dirs["base"], servers_arg),
|
||||
],
|
||||
}]
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -63,7 +63,4 @@ go.work.sum
|
||||
.env
|
||||
.envrc
|
||||
CLAUDE.md
|
||||
.claude/
|
||||
|
||||
# charts
|
||||
ocis-charts/
|
||||
.claude/
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "Acceptance Testing"
|
||||
date: 2018-05-02T00:00:00+00:00
|
||||
title: 'Acceptance Testing'
|
||||
date: 2026-03-18T00:00:00+00:00
|
||||
weight: 20
|
||||
geekdocRepo: https://github.com/owncloud/ocis
|
||||
geekdocEditPath: edit/master/docs/ocis/development
|
||||
@@ -591,160 +591,7 @@ The sample `fontsMap.json` file is located in `tests/config/drone/fontsMap.json`
|
||||
|
||||
## Running Test on Helm Setup
|
||||
|
||||
The following tools must be installed:
|
||||
|
||||
* Install [k3d](https://k3d.io/stable/#install-script)
|
||||
* Install [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
|
||||
* Install [helm](https://helm.sh/docs/intro/install/)
|
||||
|
||||
Also, clone the [ocis-charts](https://github.com/owncloud/ocis-charts/) repository.
|
||||
|
||||
1. Setup Basicauth\
|
||||
Enable basic authentication for the proxy in the `ocis-charts` repo:
|
||||
```bash
|
||||
cd ocis-charts
|
||||
|
||||
# Enable basic auth in proxy deployment
|
||||
sed -i '/- name: PROXY_HTTP_ADDR/i \
|
||||
- name: PROXY_ENABLE_BASIC_AUTH \
|
||||
value: "true"' ./charts/ocis/templates/proxy/deployment.yaml
|
||||
|
||||
# copy authbasic service
|
||||
cp -r <path-to-ocis-repo>/tests/config/drone/k8s/authbasic ./charts/ocis/templates/
|
||||
|
||||
# change admin password
|
||||
sed -i '/- name: IDM_ADMIN_PASSWORD/{n;N;N;N;d;}' ./charts/ocis/templates/idm/deployment.yaml
|
||||
sed -i '/- name: IDM_ADMIN_PASSWORD/a\\n value: "admin"' ./charts/ocis/templates/idm/deployment.yaml
|
||||
|
||||
# Update values.yaml
|
||||
cp <path-to-ocis-repo>/tests/config/drone/k8s/values.yaml ./charts/ocis/ci/deployment-values.yaml
|
||||
|
||||
# Update template values
|
||||
sed -i '/{{- $_ := set .scope "appNameAuthMachine" "authmachine" -}}/a \
|
||||
{{- $_ := set .scope "appNameAuthBasic" "authbasic" -}}' \
|
||||
./charts/ocis/templates/_common/_tplvalues.tpl
|
||||
```
|
||||
|
||||
2. Install Charts Using k3d
|
||||
|
||||
```bash
|
||||
k3d cluster create drone \
|
||||
--api-port ocis-server:33199 \
|
||||
-p '80:80@loadbalancer' \
|
||||
-p '443:443@loadbalancer' \
|
||||
--k3s-arg '--tls-san=k3d@server:*' \
|
||||
--k3s-arg '--disable=metrics-server@server:*'
|
||||
|
||||
k3d kubeconfig get drone > kubeconfig.yaml
|
||||
|
||||
chmod 0600 kubeconfig.yaml
|
||||
|
||||
kubectl create configmap coredns-custom \
|
||||
--namespace kube-system \
|
||||
--from-literal='rewritehost.override=rewrite name exact ocis-server host.k3d.internal'
|
||||
|
||||
kubectl -n kube-system rollout restart deployment coredns
|
||||
|
||||
make helm-install-atomic
|
||||
```
|
||||
|
||||
3. Run Test\
|
||||
To run test you should set `K8S` to true:
|
||||
```bash
|
||||
cd <path-to-ocis-repo>
|
||||
|
||||
# build and run ocis wrapper
|
||||
make -C ./tests/ociswrapper
|
||||
./tests/ociswrapper/bin/ociswrapper serve \
|
||||
--url https://ocis-server \
|
||||
--admin-username admin \
|
||||
--admin-password admin \
|
||||
--skip-ocis-run
|
||||
|
||||
K8S=true TEST_SERVER_URL="https://ocis-server" \
|
||||
make test-acceptance-api BEHAT_FEATURE=tests/acceptance/features/apiArchiver/downloadById.feature
|
||||
```
|
||||
|
||||
4. Run Test With ociswrapper
|
||||
```bash
|
||||
ociswrapper serve \
|
||||
--url https://ocis-server \
|
||||
--admin-username admin \
|
||||
--admin-password admin \
|
||||
--skip-ocis-run
|
||||
```
|
||||
|
||||
5. Run Antivirus Test\
|
||||
To run the clamav service, run these commands deploying the helm chart:
|
||||
```bash
|
||||
cp -r config/drone/k8s/clamav charts/ocis/templates/
|
||||
|
||||
sed -i 's/{{ *\.Values\.features\.virusscan\.infectedFileHandling *| *quote *}}/"delete"/' \
|
||||
ocis/templates/antivirus/deployment.yaml
|
||||
|
||||
sed -i '/name: ANTIVIRUS_SCANNER_TYPE/{n;s/value: *"icap"/value: "clamav"/}' \
|
||||
charts/ocis/templates/antivirus/deployment.yaml
|
||||
|
||||
sed -i '/- name: ANTIVIRUS_SCANNER_TYPE/i \
|
||||
- name: ANTIVIRUS_CLAMAV_SOCKET\n \
|
||||
value: "tcp://clamav:3310"' \
|
||||
charts/ocis/templates/antivirus/deployment.yaml
|
||||
```
|
||||
|
||||
5. Run Email Test\
|
||||
To run the email service, run these commands deploying the helm chart:
|
||||
```bash
|
||||
cp -r <path-to-ocis-repo>/tests/config/drone/k8s/mailpit charts/ocis/templates/
|
||||
```
|
||||
After ocis is deployed:
|
||||
```bash
|
||||
kubectl port-forward svc/mailpit $EMAIL_PORT:8025 -n ocis
|
||||
```
|
||||
|
||||
6. Run Tika Test\
|
||||
To run the tika service, run these commands deploying the helm chart:
|
||||
```bash
|
||||
cp -r <path-to-ocis-repo>/tests/config/drone/k8s/tika charts/ocis/templates/
|
||||
```
|
||||
|
||||
### Running Core API Test Suites from Pipeline "8"
|
||||
|
||||
For running specific core API suites (`coreApiWebdavMove1`, `coreApiWebdavPreviews`, `coreApiWebdavUpload`, `coreApiWebdavUploadTUS`) on k8s:
|
||||
|
||||
1. **Additional Configs** (after step 1 above):
|
||||
```bash
|
||||
# Create fonts configmaps
|
||||
echo '{"defaultFont": "/etc/ocis/fonts/NotoSans.ttf"}' > fontsMap.json
|
||||
kubectl create configmap -n ocis sharing-banned-passwords \
|
||||
--from-file=banned-password-list.txt=<path-to-ocis-repo>/tests/config/drone/banned-password-list.txt
|
||||
kubectl create configmap -n ocis ocis-fonts-map --from-file=./fontsMap.json
|
||||
|
||||
# Patch sharing for banned passwords
|
||||
sed -i 's|/etc/ocis/sharing-banned-passwords.txt|/etc/ocis/config/drone/banned-password-list.txt|' ./charts/ocis/templates/sharing/deployment.yaml
|
||||
sed -i 's|- name: configs|- name: banned-passwords|' ./charts/ocis/templates/sharing/deployment.yaml
|
||||
sed -i 's|mountPath: /etc/ocis$|mountPath: /etc/ocis/config/drone|' ./charts/ocis/templates/sharing/deployment.yaml
|
||||
sed -i 's|name: sharing-banned-passwords-{{ .appName }}|name: sharing-banned-passwords|' ./charts/ocis/templates/sharing/deployment.yaml
|
||||
|
||||
kubectl create configmap -n ocis sharing-banned-passwords \
|
||||
--from-file=banned-password-list.txt=<path-to-ocis-repo>/tests/config/drone/banned-password-list.txt
|
||||
```
|
||||
|
||||
2. **Install and Setup** (after step 2 above):
|
||||
```bash
|
||||
make helm-install-atomic
|
||||
```
|
||||
|
||||
3. **Run Tests**:
|
||||
```bash
|
||||
cd <path-to-ocis-repo>
|
||||
K8S=true \
|
||||
TEST_OCIS=true \
|
||||
TEST_WITH_GRAPH_API=true \
|
||||
TEST_SERVER_URL="https://ocis-server" \
|
||||
OCIS_WRAPPER_URL="http://localhost:5200" \
|
||||
make test-acceptance-api \
|
||||
BEHAT_FEATURE=tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature
|
||||
```
|
||||
Refer to the [Running API Tests in Kubernetes Cluster](../../../tests/config/k8s/README.md) documentation for running tests against a K8s setup.
|
||||
|
||||
## Generating Code Coverage Report by Running Acceptance Tests
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: clamav
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: clamav
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: clamav
|
||||
spec:
|
||||
containers:
|
||||
- name: clamav
|
||||
image: owncloudci/clamavd
|
||||
ports:
|
||||
- containerPort: 3310
|
||||
@@ -1,11 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: clamav
|
||||
spec:
|
||||
selector:
|
||||
app: clamav
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 3310
|
||||
targetPort: 3310
|
||||
@@ -1,24 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mailpit
|
||||
labels:
|
||||
app: mailpit
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mailpit
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mailpit
|
||||
spec:
|
||||
containers:
|
||||
- name: mailpit
|
||||
image: axllent/mailpit:latest
|
||||
ports:
|
||||
- containerPort: 1025
|
||||
name: smtp
|
||||
- containerPort: 8025
|
||||
name: web
|
||||
@@ -1,17 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mailpit
|
||||
spec:
|
||||
selector:
|
||||
app: mailpit
|
||||
ports:
|
||||
- name: smtp
|
||||
port: 1025
|
||||
targetPort: smtp
|
||||
protocol: TCP
|
||||
appProtocol: tcp
|
||||
- name: web
|
||||
port: 8025
|
||||
targetPort: web
|
||||
protocol: TCP
|
||||
@@ -1,72 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
CHART_REPO="$1"
|
||||
if [[ -z "$CHART_REPO" ]]; then
|
||||
echo "[ERR] Chart directory argument missing. Usage: $0 <chart-repo-directory>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d "$CHART_REPO" ]]; then
|
||||
echo "[ERR] Path not found: $CHART_REPO"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
ROOT="$(cd $SCRIPT_DIR/../../../.. && pwd)"
|
||||
|
||||
CFG_DIR="$ROOT/tests/config/drone/k8s"
|
||||
CHT_DIR="$CHART_REPO/charts/ocis"
|
||||
TPL_DIR="$CHT_DIR/templates"
|
||||
|
||||
# patch ocis service templates
|
||||
for service in "$TPL_DIR"/*/; do
|
||||
if [[ -f "$service/deployment.yaml" ]]; then
|
||||
if grep -qE 'ocis.caEnv' "$service/deployment.yaml"; then
|
||||
sed -i '/.*ocis.caEnv.*/a\{{- include "ocis.extraEnvs" . | nindent 12 }}' "$service/deployment.yaml"
|
||||
sed -i '/.*ocis.caPath.*/a\{{- include "ocis.extraVolMounts" . | nindent 12 }}' "$service/deployment.yaml"
|
||||
sed -i '/.*ocis.caVolume.*/a\{{- include "ocis.extraVolumes" . | nindent 8 }}' "$service/deployment.yaml"
|
||||
else
|
||||
sed -i '/env:/a\{{- include "ocis.extraEnvs" . | nindent 12 }}' "$service/deployment.yaml"
|
||||
sed -i '/volumeMounts:/a\{{- include "ocis.extraVolMounts" . | nindent 12 }}' "$service/deployment.yaml"
|
||||
sed -i '/volumes:/a\{{- include "ocis.extraVolumes" . | nindent 8 }}' "$service/deployment.yaml"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# copy custom template resources
|
||||
cp -r $CFG_DIR/templates/* $TPL_DIR/
|
||||
|
||||
# add authbasic service
|
||||
sed -i "/{{- define \"ocis.basicServiceTemplates\" -}}/a\ {{- \$_ := set .scope \"appNameAuthBasic\" \"authbasic\" -}}" $TPL_DIR/_common/_tplvalues.tpl
|
||||
|
||||
if [[ "$ENABLE_ANTIVIRUS" == "true" ]]; then
|
||||
sed -i '/virusscan:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_EMAIL" == "true" ]]; then
|
||||
sed -i '/emailNotifications:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_TIKA" == "true" ]]; then
|
||||
sed -i 's|type: basic|type: tika|' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_WOPI" == "true" ]]; then
|
||||
sed -i '/appsIntegration:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
# patch collaboration service
|
||||
# - allow dynamic wopi src
|
||||
sed -i -E "s|value: http://.*:9300|value: {{ \$officeSuite.wopiSrc }}|" $TPL_DIR/collaboration/deployment.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_OCM" == "true" ]]; then
|
||||
sed -i '/ocm:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_AUTH_APP" == "true" ]]; then
|
||||
sed -i '/authapp:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
# move custom values file
|
||||
cp $CFG_DIR/values.yaml "$CHT_DIR/ci/deployment-values.yaml"
|
||||
@@ -1,19 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: tika
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: tika
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: tika
|
||||
spec:
|
||||
containers:
|
||||
- name: tika
|
||||
image: apache/tika:3.2.2.0-full
|
||||
ports:
|
||||
- containerPort: 9998
|
||||
@@ -1,12 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: tika
|
||||
spec:
|
||||
selector:
|
||||
app: tika
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9998
|
||||
targetPort: 9998
|
||||
type: ClusterIP
|
||||
2
tests/config/k8s/.gitignore
vendored
Normal file
2
tests/config/k8s/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
logs/
|
||||
ocis-charts/
|
||||
45
tests/config/k8s/Makefile
Normal file
45
tests/config/k8s/Makefile
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
LOGS_DIR := $(abspath ./logs)
|
||||
CHART_REPO := $(abspath ./ocis-charts)
|
||||
HOST_IP := $(shell ip route get 1 | awk '{print $$7}')
|
||||
|
||||
OCM ?= false
|
||||
DOMAIN := ocis-server
|
||||
ifeq ($(OCM), true)
|
||||
DOMAIN := federation-ocis-server
|
||||
endif
|
||||
|
||||
.PHONY: create-cluster
|
||||
create-cluster:
|
||||
@echo $(LOGS_DIR)
|
||||
@mkdir -p $(LOGS_DIR)
|
||||
@chmod 777 $(LOGS_DIR)
|
||||
k3d cluster create local-ocis \
|
||||
-p '80:80@loadbalancer' -p '443:443@loadbalancer' -p '9100-9399:30100-30399@loadbalancer' \
|
||||
--k3s-arg '--tls-san=k3d@server:*' --k3s-arg '--disable=metrics-server@server:*' \
|
||||
--host-alias $(HOST_IP):ocis-server --host-alias $(HOST_IP):federation-ocis-server \
|
||||
-v $(LOGS_DIR):/logs
|
||||
|
||||
.PHONY: prepare-charts
|
||||
prepare-charts:
|
||||
@test -d "$(CHART_REPO)" || git clone --single-branch -b main --depth 1 https://github.com/owncloud/ocis-charts.git $(CHART_REPO)
|
||||
bash setup.sh $(CHART_REPO)
|
||||
kubectl create namespace $(DOMAIN) || true
|
||||
kubectl create configmap -n $(DOMAIN) ocis-fonts-ttf --from-file=../drone/NotoSans.ttf || true
|
||||
|
||||
.PHONY: deploy-ocis
|
||||
deploy-ocis:
|
||||
@sed -i 's|externalDomain:.*|externalDomain: $(DOMAIN)|' $(CHART_REPO)/charts/ocis/ci/deployment-values.yaml
|
||||
helm install -n $(DOMAIN) --create-namespace \
|
||||
--values $(CHART_REPO)/charts/ocis/ci/deployment-values.yaml \
|
||||
--wait --timeout 5m0s ocis $(CHART_REPO)/charts/ocis/
|
||||
|
||||
.PHONY: show-logs
|
||||
show-logs:
|
||||
@tail -f $(LOGS_DIR)/*.log
|
||||
|
||||
.PHONY: cleanup
|
||||
cleanup:
|
||||
k3d cluster delete local-ocis
|
||||
rm -rf $(LOGS_DIR)
|
||||
rm -rf $(CHART_REPO)
|
||||
201
tests/config/k8s/README.md
Normal file
201
tests/config/k8s/README.md
Normal file
@@ -0,0 +1,201 @@
|
||||
# Running API Tests in Kubernetes Cluster
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [K8s Setup](#k8s-setup)
|
||||
- [Running API Tests](#running-api-tests)
|
||||
- [Run General API tests](#run-general-api-tests)
|
||||
- [Run Notification API tests](#run-notification-api-tests)
|
||||
- [Run Antivirus API tests](#run-antivirus-api-tests)
|
||||
- [Run Full Text Search API tests](#run-full-text-search-api-tests)
|
||||
- [Cleanup the Setup](#cleanup-the-setup)
|
||||
|
||||
## K8s Setup
|
||||
|
||||
### Pre-requisites
|
||||
|
||||
1. Install the following tools:
|
||||
- [k3d](https://k3d.io/stable/)
|
||||
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/)
|
||||
- [helm@v3](https://github.com/helm/helm/releases/tag/v3.20.1) (⚠️ MUST use v3)
|
||||
|
||||
2. Add these hosts to your `/etc/hosts` file:
|
||||
|
||||
```bash
|
||||
echo "127.0.0.1 ocis-server federation-ocis-server \
|
||||
clamav collabora onlyoffice fakeoffice tika \
|
||||
email" | sudo tee -a /etc/hosts
|
||||
```
|
||||
|
||||
### Deploy oCIS in K8s
|
||||
|
||||
1. Change directory to `<ocis-root>/tests/config/k8s`:
|
||||
|
||||
```bash
|
||||
cd <ocis-root>/tests/config/k8s
|
||||
```
|
||||
|
||||
2. Create K8s Cluster
|
||||
|
||||
```bash
|
||||
make create-cluster
|
||||
```
|
||||
|
||||
3. Prepare Charts
|
||||
|
||||
```bash
|
||||
make prepare-charts
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
> To run the test suites that require extra services,
|
||||
> use the following appropriate environment variables:
|
||||
>
|
||||
> - `ENABLE_ANTIVIRUS=true`: Antivirus test suites
|
||||
> - `ENABLE_EMAIL=true`: Notification test suites
|
||||
> - `ENABLE_TIKA=true`: Content search test suites
|
||||
> - `ENABLE_WOPI=true`: WOPI test suites
|
||||
> - `ENABLE_OCM=true`: OCM test suites
|
||||
> - `ENABLE_AUTH_APP=true`: auth-app test suites
|
||||
>
|
||||
> ⚠️ When using the above environment variables,
|
||||
> make sure you run the necessary external services and expose them to the cluster.
|
||||
> Check the respective test running sections for more details.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
ENABLE_EMAIL=true make prepare-charts
|
||||
```
|
||||
|
||||
4. Deploy oCIS
|
||||
|
||||
```bash
|
||||
make deploy-ocis
|
||||
```
|
||||
|
||||
5. Check the ocis logs
|
||||
|
||||
```bash
|
||||
make show-logs
|
||||
```
|
||||
|
||||
## Running API Tests
|
||||
|
||||
Build and run the ociswrapper to be able to run the API tests tagged with `@env-config`.
|
||||
|
||||
1. Change directory to the ocis root:
|
||||
|
||||
```bash
|
||||
cd <ocis-root>
|
||||
```
|
||||
|
||||
2. Build the ociswrapper:
|
||||
|
||||
```bash
|
||||
make -C tests/ociswrapper build
|
||||
```
|
||||
|
||||
3. Run the ociswrapper:
|
||||
|
||||
```bash
|
||||
tests/ociswrapper/bin/ociswrapper serve \
|
||||
--url https://ocis-server \
|
||||
--admin-username admin \
|
||||
--admin-password admin \
|
||||
--skip-ocis-run \
|
||||
-n ocis-server
|
||||
```
|
||||
|
||||
### Run General API tests
|
||||
|
||||
```bash
|
||||
TEST_SERVER_URL=https://ocis-server \
|
||||
K8S=true \
|
||||
BEHAT_FEATURE=<test-suites-path>/apiDownloads/download.feature \
|
||||
make test-acceptance-api
|
||||
```
|
||||
|
||||
### Run Notification API tests
|
||||
|
||||
1. Check if setup [step 3](#deploy-ocis-in-k8s) is done correctly. (`ENABLE_EMAIL=true`)
|
||||
2. Start the email server
|
||||
|
||||
```bash
|
||||
docker run -d -p 1025:1025 -p 8025:8025 axllent/mailpit:v1.22.3
|
||||
```
|
||||
|
||||
3. Expose the email server to the cluster
|
||||
|
||||
```bash
|
||||
bash tests/config/k8s/expose-external-svc.sh email:1025
|
||||
```
|
||||
|
||||
4. Run the tests
|
||||
|
||||
```bash
|
||||
TEST_SERVER_URL=https://ocis-server \
|
||||
EMAIL_HOST=email \
|
||||
EMAIL_PORT=8025 \
|
||||
K8S=true \
|
||||
BEHAT_FEATURE=<test-suites-path>/apiNotification/notification.feature \
|
||||
make test-acceptance-api
|
||||
```
|
||||
|
||||
### Run Antivirus API tests
|
||||
|
||||
1. Check if setup [step 3](#deploy-ocis-in-k8s) is done correctly. (`ENABLE_ANTIVIRUS=true`)
|
||||
2. Start the antivirus server
|
||||
|
||||
```bash
|
||||
docker run -d -p 3310:3310 owncloudci/clamavd
|
||||
```
|
||||
|
||||
3. Expose the antivirus server to the cluster
|
||||
|
||||
```bash
|
||||
bash tests/config/k8s/expose-external-svc.sh clamav:3310
|
||||
```
|
||||
|
||||
4. Run the tests
|
||||
|
||||
```bash
|
||||
TEST_SERVER_URL=https://ocis-server \
|
||||
K8S=true \
|
||||
BEHAT_FEATURE=<test-suites-path>/apiAntivirus/antivirus.feature \
|
||||
make test-acceptance-api
|
||||
```
|
||||
|
||||
### Run Full Text Search API tests
|
||||
|
||||
1. Check if setup [step 3](#deploy-ocis-in-k8s) is done correctly. (`ENABLE_TIKA=true`)
|
||||
2. Start the tika server
|
||||
|
||||
```bash
|
||||
docker run -d -p 9998:9998 apache/tika:3.2.2.0-full
|
||||
```
|
||||
|
||||
3. Expose the tika server to the cluster
|
||||
|
||||
```bash
|
||||
bash tests/config/k8s/expose-external-svc.sh tika:9998
|
||||
```
|
||||
|
||||
4. Run the tests
|
||||
|
||||
```bash
|
||||
TEST_SERVER_URL=https://ocis-server \
|
||||
K8S=true \
|
||||
BEHAT_FEATURE=<test-suites-path>/apiSearchContent/contentSearch.feature \
|
||||
make test-acceptance-api
|
||||
```
|
||||
|
||||
## Cleanup the Setup
|
||||
|
||||
To delete the cluster and all the setup resources, run the following command:
|
||||
|
||||
```bash
|
||||
make -C <ocis-root>/tests/config/k8s cleanup
|
||||
```
|
||||
|
||||
This will delete the K8s cluster, ocis-charts, and ocis logs directory.
|
||||
81
tests/config/k8s/expose-external-svc.sh
Normal file
81
tests/config/k8s/expose-external-svc.sh
Normal file
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
HOST_IP=$(ip route get 1 | awk '{print $7}')
|
||||
|
||||
NAMESPACE="ocis-server"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-n|--namespace)
|
||||
NAMESPACE="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
services="$1"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$services" ]; then
|
||||
echo "[ERR] No services provided."
|
||||
echo "Usage: $0 [-n <namespace>] <svc1:port1,svc2:port2,...>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function expose_svc() {
|
||||
local k8s_endpoint k8s_service svc port server_ip
|
||||
svc=$1
|
||||
port=$2
|
||||
server_ip=$3
|
||||
|
||||
k8s_endpoint=$(cat <<EOF
|
||||
apiVersion: v1
|
||||
kind: Endpoints
|
||||
metadata:
|
||||
name: $svc
|
||||
namespace: $NAMESPACE
|
||||
subsets:
|
||||
- addresses:
|
||||
- ip: $server_ip
|
||||
ports:
|
||||
- port: $port
|
||||
EOF
|
||||
)
|
||||
echo -e "$k8s_endpoint" | kubectl apply -f -
|
||||
|
||||
k8s_service=$(cat <<EOF
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: $svc
|
||||
namespace: $NAMESPACE
|
||||
spec:
|
||||
ports:
|
||||
- port: $port
|
||||
targetPort: $port
|
||||
EOF
|
||||
)
|
||||
echo -e "$k8s_service" | kubectl apply -f -
|
||||
}
|
||||
|
||||
IFS=',' read -ra ADDR <<< "$services"
|
||||
for service in "${ADDR[@]}"; do
|
||||
IFS=':' read -ra SVC <<< "$service"
|
||||
if [ ${#SVC[@]} -ne 2 ]; then
|
||||
echo "[ERR] Invalid service format (<svc>:<port>): $service"
|
||||
exit 1
|
||||
fi
|
||||
SERVER_IP=$(getent hosts "${SVC[0]}" | awk '{print $1}')
|
||||
if [ -z "$SERVER_IP" ]; then
|
||||
echo "[ERR] Could not resolve IP for service ${SVC[0]}"
|
||||
exit 1
|
||||
fi
|
||||
# for localhost services, use the host IP
|
||||
if [[ "$SERVER_IP" == "127.0.0.1" ]]; then
|
||||
SERVER_IP="$HOST_IP"
|
||||
fi
|
||||
expose_svc "${SVC[0]}" "${SVC[1]}" "$SERVER_IP"
|
||||
done
|
||||
83
tests/config/k8s/setup.sh
Normal file
83
tests/config/k8s/setup.sh
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
CHART_REPO="$1"
|
||||
if [[ -z "$CHART_REPO" ]]; then
|
||||
echo "[ERR] Chart directory argument missing. Usage: $0 <chart-repo-directory>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d "$CHART_REPO" ]]; then
|
||||
echo "[ERR] Path not found: $CHART_REPO"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
ROOT="$(cd $SCRIPT_DIR/../../.. && pwd)"
|
||||
|
||||
CFG_DIR="$ROOT/tests/config/k8s"
|
||||
CHT_DIR="$CHART_REPO/charts/ocis"
|
||||
TPL_DIR="$CHT_DIR/templates"
|
||||
|
||||
function patch_templates(){
|
||||
# patch ocis service templates
|
||||
for service in "$TPL_DIR"/*/; do
|
||||
if [[ -f "$service/deployment.yaml" ]]; then
|
||||
if grep -qE 'ocis.caEnv' "$service/deployment.yaml"; then
|
||||
sed -i '/.*ocis.caEnv.*/a\{{- include "ocis.extraEnvs" . | nindent 12 }}' "$service/deployment.yaml"
|
||||
sed -i '/.*ocis.caPath.*/a\{{- include "ocis.extraVolMounts" . | nindent 12 }}' "$service/deployment.yaml"
|
||||
sed -i '/.*ocis.caVolume.*/a\{{- include "ocis.extraVolumes" . | nindent 8 }}' "$service/deployment.yaml"
|
||||
else
|
||||
sed -i '/env:/a\{{- include "ocis.extraEnvs" . | nindent 12 }}' "$service/deployment.yaml"
|
||||
sed -i '/volumeMounts:/a\{{- include "ocis.extraVolMounts" . | nindent 12 }}' "$service/deployment.yaml"
|
||||
sed -i '/volumes:/a\{{- include "ocis.extraVolumes" . | nindent 8 }}' "$service/deployment.yaml"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# copy custom template resources
|
||||
cp -r $CFG_DIR/templates/* $TPL_DIR/
|
||||
|
||||
# add authbasic service
|
||||
sed -i "/{{- define \"ocis.basicServiceTemplates\" -}}/a\ {{- \$_ := set .scope \"appNameAuthBasic\" \"authbasic\" -}}" $TPL_DIR/_common/_tplvalues.tpl
|
||||
|
||||
# [NOTE]
|
||||
# Remove schema validation to add extra configs in values.yaml.
|
||||
# Also this allows us to use fakeoffice as web-office server
|
||||
rm "$CHT_DIR/values.schema.json"
|
||||
}
|
||||
|
||||
if [[ -f "$CHT_DIR/values.schema.json" ]]; then
|
||||
patch_templates
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_ANTIVIRUS" == "true" ]]; then
|
||||
sed -i '/virusscan:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_EMAIL" == "true" ]]; then
|
||||
sed -i '/emailNotifications:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_TIKA" == "true" ]]; then
|
||||
sed -i 's|type: basic|type: tika|' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_WOPI" == "true" ]]; then
|
||||
sed -i '/appsIntegration:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
# patch collaboration service
|
||||
# - allow dynamic wopi src
|
||||
sed -i -E "s|value: http://.*:9300|value: {{ \$officeSuite.wopiSrc }}|" $TPL_DIR/collaboration/deployment.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_OCM" == "true" ]]; then
|
||||
sed -i '/ocm:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
if [[ "$ENABLE_AUTH_APP" == "true" ]]; then
|
||||
sed -i '/authapp:/{n;s|false|true|}' $CFG_DIR/values.yaml
|
||||
fi
|
||||
|
||||
# copy custom values file
|
||||
cp $CFG_DIR/values.yaml "$CHT_DIR/ci/deployment-values.yaml"
|
||||
@@ -1,5 +1,4 @@
|
||||
---
|
||||
namespaceOverride: ocis
|
||||
image:
|
||||
repository: owncloud/ocis-rolling
|
||||
tag: master
|
||||
@@ -35,6 +35,7 @@ func serveCmd() *cobra.Command {
|
||||
ocisConfig.Set("retry", cmd.Flag("retry").Value.String())
|
||||
ocisConfig.Set("adminUsername", cmd.Flag("admin-username").Value.String())
|
||||
ocisConfig.Set("adminPassword", cmd.Flag("admin-password").Value.String())
|
||||
ocisConfig.Set("namespace", cmd.Flag("namespace").Value.String())
|
||||
|
||||
if cmd.Flag("skip-ocis-run").Value.String() == "false" {
|
||||
go ocis.Start(nil)
|
||||
@@ -52,6 +53,7 @@ func serveCmd() *cobra.Command {
|
||||
serveCmd.Flags().StringP("admin-username", "", "", "admin username for oCIS server")
|
||||
serveCmd.Flags().StringP("admin-password", "", "", "admin password for oCIS server")
|
||||
serveCmd.Flags().Bool("skip-ocis-run", false, "Skip running oCIS server")
|
||||
serveCmd.Flags().StringP("namespace", "n", ocisConfig.Get("namespace"), "K8s namespace of oCIS server")
|
||||
|
||||
return serveCmd
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ var config = map[string]string{
|
||||
"retry": "5",
|
||||
"adminUsername": "",
|
||||
"adminPassword": "",
|
||||
"namespace": "ocis",
|
||||
}
|
||||
|
||||
var services = map[string]int{
|
||||
|
||||
Reference in New Issue
Block a user